    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     * @return A collection of item keys (never {@code null}).
    059     */
    060    public static Collection<KeyedValues3DItemKey> itemKeysForSeries(
    061            KeyedValues3D data, Comparable<?> seriesKey) {
    062        ArgChecks.nullNotPermitted(data, "data");
    063        ArgChecks.nullNotPermitted(seriesKey, "seriesKey");
    064        Collection<KeyedValues3DItemKey> result
    065                = new ArrayList<KeyedValues3DItemKey>();
    066        if (!data.getSeriesKeys().contains(seriesKey)) {
    067            return result;
    068        }
    069        for (Comparable<?> rowKey: (List<Comparable<?>>) data.getRowKeys()) {
    070            for (Comparable columnKey:
    071                    (List<Comparable<?>>) data.getColumnKeys()) {
    072                KeyedValues3DItemKey key = new KeyedValues3DItemKey(seriesKey,
    073                        rowKey, columnKey);
    074                result.add(key);
    075            }
    076        }
    077        return result;
    078    }
    079
    080    /**
    081     * Returns a collection containing all the item keys for the specified
    082     * row.
    083     *
    084     * @param data  the data ({@code null} not permitted).
    085     * @param rowKey  the row key ({@code null} not permitted).
    086     *
    087     * @return A collection of item keys (never {@code null}).
    088     */
    089    public static Collection<KeyedValues3DItemKey> itemKeysForRow(
    090            KeyedValues3D data, Comparable<?> rowKey) {
    091        ArgChecks.nullNotPermitted(data, "data");
    092        ArgChecks.nullNotPermitted(rowKey, "rowKey");
    093        Collection<KeyedValues3DItemKey> result
    094                = new ArrayList<KeyedValues3DItemKey>();
    095        if (!data.getRowKeys().contains(rowKey)) {
    096            return result;
    097        }
    098        for (Comparable<?> seriesKey:
    099                (List<Comparable<?>>) data.getSeriesKeys()) {
    100            for (Comparable columnKey: (List<Comparable<?>>)
    101                    data.getColumnKeys()) {
    102                KeyedValues3DItemKey key = new KeyedValues3DItemKey(seriesKey,
    103                        rowKey, columnKey);
    104                result.add(key);
    105            }
    106        }
    107        return result;
    108    }
    109
    110    /**
    111     * Returns a collection containing all the item keys for the specified
    112     * column.
    113     *
    114     * @param data  the data ({@code null} not permitted).
    115     * @param columnKey  the column key ({@code null} not permitted).
    116     *
    117     * @return A collection of item keys (never {@code null}).
    118     */
    119    public static Collection<KeyedValues3DItemKey> itemKeysForColumn(
    120            KeyedValues3D data, Comparable<?> columnKey) {
    121        ArgChecks.nullNotPermitted(data, "data");
    122        ArgChecks.nullNotPermitted(columnKey, "columnKey");
    123        Collection<KeyedValues3DItemKey> result
    124                = new ArrayList<KeyedValues3DItemKey>();
    125        if (!data.getColumnKeys().contains(columnKey)) {
    126            return result;
    127        }
    128        for (Comparable<?> seriesKey:
    129                (List<Comparable<?>>) data.getSeriesKeys()) {
    130            for (Comparable rowKey: (List<Comparable<?>>) data.getRowKeys()) {
    131                KeyedValues3DItemKey key = new KeyedValues3DItemKey(seriesKey,
    132                        rowKey, columnKey);
    133                result.add(key);
    134            }
    135        }
    136        return result;
    137    }
    138
    139}