001/* ===========================================================
002 * Orson Charts : a 3D chart library for the Java(tm) platform
003 * ===========================================================
004 * 
005 * (C)opyright 2013-2022, by David Gilbert.  All rights reserved.
006 * 
007 * https://github.com/jfree/orson-charts
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 org.jfree.chart3d.data;
034
035import java.util.ArrayList;
036import java.util.Collection;
037import org.jfree.chart3d.internal.Args;
038
039/**
040 * Utility methods related to the {@link KeyedValues3DItemKey} class.
041 * 
042 * @since 1.3
043 */
044public class KeyedValues3DItemKeys {
045    
046    private KeyedValues3DItemKeys() {
047        // no need to instantiate this
048    }
049 
050    /**
051     * Returns a collection containing all the item keys for the specified
052     * series.
053     * 
054     * @param data  the data ({@code null} not permitted).
055     * @param seriesKey  the series key ({@code null} not permitted).
056     * 
057     * @param <S> the series key type
058     * @param <R> the row key type
059     * @param <C> the column key type
060     * @param <T> the value type
061     * 
062     * @return A collection of item keys (never {@code null}).
063     */
064    public static <S extends Comparable<S>, R extends Comparable<R>, 
065             C extends Comparable<C>, T> 
066             Collection<KeyedValues3DItemKey> itemKeysForSeries(
067             KeyedValues3D<S, R, C, T> data, S seriesKey) {
068        Args.nullNotPermitted(data, "data");
069        Args.nullNotPermitted(seriesKey, "seriesKey");
070        Collection<KeyedValues3DItemKey> result = new ArrayList<>();
071        if (!data.getSeriesKeys().contains(seriesKey)) {
072            return result;
073        }
074        for (R rowKey: data.getRowKeys()) {
075            for (C columnKey: data.getColumnKeys()) {
076                KeyedValues3DItemKey<S, R, C> key = new KeyedValues3DItemKey<>(
077                        seriesKey, rowKey, columnKey);
078                result.add(key);
079            }
080        }
081        return result;
082    }
083    
084    /**
085     * Returns a collection containing all the item keys for the specified
086     * row.
087     * 
088     * @param <S> the series key type
089     * @param <R> the row key type
090     * @param <C> the column key type
091     * @param <T> the value type
092     * 
093     * @param data  the data ({@code null} not permitted).
094     * @param rowKey  the row key ({@code null} not permitted).
095     * 
096     * @return A collection of item keys (never {@code null}).
097     */
098    public static <S extends Comparable<S>, R extends Comparable<R>, 
099            C extends Comparable<C>, T> Collection<KeyedValues3DItemKey> 
100            itemKeysForRow(KeyedValues3D<S, R, C, T> data, R rowKey) {
101        Args.nullNotPermitted(data, "data");
102        Args.nullNotPermitted(rowKey, "rowKey");
103        Collection<KeyedValues3DItemKey> result = new ArrayList<>();
104        if (!data.getRowKeys().contains(rowKey)) {
105            return result;
106        }
107        for (S seriesKey: data.getSeriesKeys()) {
108            for (C columnKey: data.getColumnKeys()) {
109                KeyedValues3DItemKey<S, R, C> key 
110                        = new KeyedValues3DItemKey<>(seriesKey, 
111                        rowKey, columnKey);
112                result.add(key);
113            }
114        }
115        return result;
116    }
117    
118    /**
119     * Returns a collection containing all the item keys for the specified
120     * column.
121     * 
122     * @param <S> the series key type
123     * @param <R> the row key type
124     * @param <C> the column key type.
125     * @param <T> the value type.
126     * 
127     * @param data  the data ({@code null} not permitted).
128     * @param columnKey  the column key ({@code null} not permitted).
129     * 
130     * @return A collection of item keys (never {@code null}).
131     */
132    public static <S extends Comparable<S>, R extends Comparable<R>, 
133            C extends Comparable<C>, T> 
134            Collection<KeyedValues3DItemKey> itemKeysForColumn(
135            KeyedValues3D<S, R, C, T> data, C columnKey) {
136        Args.nullNotPermitted(data, "data");
137        Args.nullNotPermitted(columnKey, "columnKey");
138        Collection<KeyedValues3DItemKey> result = new ArrayList<>();
139        if (!data.getColumnKeys().contains(columnKey)) {
140            return result;
141        }
142        for (S seriesKey: data.getSeriesKeys()) {
143            for (R rowKey: data.getRowKeys()) {
144                KeyedValues3DItemKey<S, R, C> key = new KeyedValues3DItemKey<>(
145                        seriesKey, rowKey, columnKey);
146                result.add(key);
147            }
148        }
149        return result;
150    }
151    
152}