    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.io.Serializable;
    036
    037import org.jfree.chart3d.internal.Args;
    038import org.jfree.chart3d.internal.ObjectUtils;
    039
    040/**
    041 * An object that references one data item in a {@link KeyedValues3D} data
    042 * structure.  Instances of this class are immutable (subject to the caller
    043 * using series, row and column keys that are immutable).
    044 *
    045 * @since 1.3
    046 */
    047public class KeyedValues3DItemKey<S extends Comparable<S>,
    048        R extends Comparable<R>, C extends Comparable<C>>
    049        implements ItemKey, Comparable<KeyedValues3DItemKey<S, R, C>>,
    050        Serializable {
    051
    052    /** The series key. */
    053    S seriesKey;
    054
    055    /** The row key. */
    056    R rowKey;
    057
    058    /** The column key. */
    059    C columnKey;
    060
    061    /**
    062     * Creates a new instance.
    063     *
    064     * @param seriesKey  the series key ({@code null} not permitted).
    065     * @param rowKey  the row key ({@code null} not permitted).
    066     * @param columnKey  the column key ({@code null} not permitted).
    067     */
    068    public KeyedValues3DItemKey(S seriesKey, R rowKey, C columnKey) {
    069        Args.nullNotPermitted(seriesKey, "seriesKey");
    070        Args.nullNotPermitted(rowKey, "rowKey");
    071        Args.nullNotPermitted(columnKey, "columnKey");
    072        this.seriesKey = seriesKey;
    073        this.rowKey = rowKey;
    074        this.columnKey = columnKey;
    075    }
    076
    077    /**
    078     * Returns the series key.
    079     *
    080     * @return The series key (never {@code null}).
    081     */
    082    public S getSeriesKey() {
    083        return this.seriesKey;
    084    }
    085
    086    /**
    087     * Returns the row key.
    088     *
    089     * @return The row key (never {@code null}).
    090     */
    091    public R getRowKey() {
    092        return this.rowKey;
    093    }
    094
    095    /**
    096     * Returns the column key.
    097     *
    098     * @return The column key (never {@code null}).
    099     */
    100    public C getColumnKey() {
    101        return this.columnKey;
    102    }
    103
    104    @Override
    105    public int compareTo(KeyedValues3DItemKey<S, R, C> key) {
    106        int result = this.seriesKey.compareTo(key.getSeriesKey());
    107        if (result == 0) {
    108            result = this.rowKey.compareTo(key.rowKey);
    109            if (result == 0) {
    110                result = this.columnKey.compareTo(key.columnKey);
    111            }
    112        }
    113        return result;
    114    }
    115
    116    /**
    117     * Tests this key for equality with an arbitrary object.
    118     *
    119     * @param obj  the object ({@code null} permitted).
    120     *
    121     * @return A boolean.
    122     */
    123    @Override
    124    public boolean equals(Object obj) {
    125        if (obj == this) {
    126            return true;
    127        }
    128        if (!(obj instanceof KeyedValues3DItemKey)) {
    129            return false;
    130        }
    131        KeyedValues3DItemKey that = (KeyedValues3DItemKey) obj;
    132        if (!this.seriesKey.equals(that.seriesKey)) {
    133            return false;
    134        }
    135        if (!this.rowKey.equals(that.rowKey)) {
    136            return false;
    137        }
    138        if (!this.columnKey.equals(that.columnKey)) {
    139            return false;
    140        }
    141        return true;
    142    }
    143
    144    @Override
    145    public int hashCode() {
    146        int hash = 3;
    147        hash = 17 * hash + ObjectUtils.hashCode(this.seriesKey);
    148        hash = 17 * hash + ObjectUtils.hashCode(this.rowKey);
    149        hash = 17 * hash + ObjectUtils.hashCode(this.columnKey);
    150        return hash;
    151    }
    152
    153    @Override
    154    public String toJSONString() {
    155        return "{\"seriesKey\": \"" + this.seriesKey.toString() + "\", "
    156                + "\"rowKey\": \"" + this.rowKey.toString() + "\", "
    157                + "\"columnKey\": \"" + this.columnKey.toString() + "\"}";
    158    }
    159
    160    @Override
    161    public String toString() {
    162        return "Values3DItemKey[series=" + seriesKey.toString()
    163                + ",row=" + rowKey.toString()
    164                + ",column=" + columnKey.toString() + "]";
    165    }
    166
    167}