001/* =========================================================== 002 * Orson Charts : a 3D chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C)opyright 2013-2016, by Object Refinery Limited. All rights reserved. 006 * 007 * http://www.object-refinery.com/orsoncharts/index.html 008 * 009 * This program is free software: you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as published by 011 * the Free Software Foundation, either version 3 of the License, or 012 * (at your option) any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 021 * 022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 023 * Other names may be trademarks of their respective owners.] 024 * 025 * If you do not wish to be bound by the terms of the GPL, an alternative 026 * commercial license can be purchased. For details, please see visit the 027 * Orson Charts home page: 028 * 029 * http://www.object-refinery.com/orsoncharts/index.html 030 * 031 */ 032 033package com.orsoncharts.data; 034 035import java.util.ArrayList; 036import java.util.Collection; 037import java.util.List; 038import com.orsoncharts.util.ArgChecks; 039 040/** 041 * Utility methods related to the {@link KeyedValues3DItemKey} class. 042 * 043 * @since 1.3 044 */ 045public class KeyedValues3DItemKeys { 046 047 private KeyedValues3DItemKeys() { 048 // no need to instantiate this 049 } 050 051 /** 052 * Returns a collection containing all the item keys for the specified 053 * series. 054 * 055 * @param data the data ({@code null} not permitted). 056 * @param seriesKey the series key ({@code null} not permitted). 057 * 058 * @param <S> the series key type 059 * @param <R> the row key type 060 * @param <C> the column key type 061 * @param <T> the value type 062 * 063 * @return A collection of item keys (never {@code null}). 064 */ 065 public static <S extends Comparable<S>, R extends Comparable<R>, 066 C extends Comparable<C>, T> 067 Collection<KeyedValues3DItemKey> itemKeysForSeries( 068 KeyedValues3D<S, R, C, T> data, S seriesKey) { 069 ArgChecks.nullNotPermitted(data, "data"); 070 ArgChecks.nullNotPermitted(seriesKey, "seriesKey"); 071 Collection<KeyedValues3DItemKey> result 072 = new ArrayList<KeyedValues3DItemKey>(); 073 if (!data.getSeriesKeys().contains(seriesKey)) { 074 return result; 075 } 076 for (R rowKey: data.getRowKeys()) { 077 for (C columnKey: data.getColumnKeys()) { 078 KeyedValues3DItemKey<S, R, C> key 079 = new KeyedValues3DItemKey<S, R, C>(seriesKey, rowKey, 080 columnKey); 081 result.add(key); 082 } 083 } 084 return result; 085 } 086 087 /** 088 * Returns a collection containing all the item keys for the specified 089 * row. 090 * 091 * @param <S> the series key type 092 * @param <R> the row key type 093 * @param <C> the column key type 094 * @param <T> the value type 095 * 096 * @param data the data ({@code null} not permitted). 097 * @param rowKey the row key ({@code null} not permitted). 098 * 099 * @return A collection of item keys (never {@code null}). 100 */ 101 public static <S extends Comparable<S>, R extends Comparable<R>, 102 C extends Comparable<C>, T> Collection<KeyedValues3DItemKey> 103 itemKeysForRow(KeyedValues3D<S, R, C, T> data, R rowKey) { 104 ArgChecks.nullNotPermitted(data, "data"); 105 ArgChecks.nullNotPermitted(rowKey, "rowKey"); 106 Collection<KeyedValues3DItemKey> result 107 = new ArrayList<KeyedValues3DItemKey>(); 108 if (!data.getRowKeys().contains(rowKey)) { 109 return result; 110 } 111 for (S seriesKey: data.getSeriesKeys()) { 112 for (C columnKey: data.getColumnKeys()) { 113 KeyedValues3DItemKey<S, R, C> key 114 = new KeyedValues3DItemKey<S, R, C>(seriesKey, 115 rowKey, columnKey); 116 result.add(key); 117 } 118 } 119 return result; 120 } 121 122 /** 123 * Returns a collection containing all the item keys for the specified 124 * column. 125 * 126 * @param <S> the series key type 127 * @param <R> the row key type 128 * @param <C> the column key type. 129 * @param <T> the value type. 130 * 131 * @param data the data ({@code null} not permitted). 132 * @param columnKey the column key ({@code null} not permitted). 133 * 134 * @return A collection of item keys (never {@code null}). 135 */ 136 public static <S extends Comparable<S>, R extends Comparable<R>, 137 C extends Comparable<C>, T> 138 Collection<KeyedValues3DItemKey> itemKeysForColumn( 139 KeyedValues3D<S, R, C, T> data, C columnKey) { 140 ArgChecks.nullNotPermitted(data, "data"); 141 ArgChecks.nullNotPermitted(columnKey, "columnKey"); 142 Collection<KeyedValues3DItemKey> result 143 = new ArrayList<KeyedValues3DItemKey>(); 144 if (!data.getColumnKeys().contains(columnKey)) { 145 return result; 146 } 147 for (S seriesKey: data.getSeriesKeys()) { 148 for (R rowKey: data.getRowKeys()) { 149 KeyedValues3DItemKey<S, R, C> key 150 = new KeyedValues3DItemKey<S, R, C>(seriesKey, 151 rowKey, columnKey); 152 result.add(key); 153 } 154 } 155 return result; 156 } 157 158}