001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2020, by Object Refinery Limited and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * -----------------------
028 * CategoryItemEntity.java
029 * -----------------------
030 * (C) Copyright 2002-2020, by Object Refinery Limited and Contributors.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   Richard Atkinson;
034 *                   Christian W. Zuckschwerdt;
035 *
036 */
037
038package org.jfree.chart.entity;
039
040import java.awt.Shape;
041import java.io.Serializable;
042import org.jfree.chart.util.ObjectUtils;
043import org.jfree.chart.util.Args;
044
045import org.jfree.data.category.CategoryDataset;
046
047/**
048 * A chart entity that represents one item within a category plot.
049 */
050public class CategoryItemEntity extends ChartEntity
051        implements Cloneable, Serializable {
052
053    /** For serialization. */
054    private static final long serialVersionUID = -8657249457902337349L;
055
056    /** The dataset. */
057    private CategoryDataset dataset;
058
059    /**
060     * The row key.
061     *
062     * @since 1.0.6
063     */
064    private Comparable rowKey;
065
066    /**
067     * The column key.
068     *
069     * @since 1.0.6
070     */
071    private Comparable columnKey;
072
073    /**
074     * Creates a new entity instance for an item in the specified dataset.
075     *
076     * @param area  the 'hotspot' area ({@code null} not permitted).
077     * @param toolTipText  the tool tip text.
078     * @param urlText  the URL text.
079     * @param dataset  the dataset ({@code null} not permitted).
080     * @param rowKey  the row key ({@code null} not permitted).
081     * @param columnKey  the column key ({@code null} not permitted).
082     *
083     * @since 1.0.6
084     */
085    public CategoryItemEntity(Shape area, String toolTipText, String urlText,
086            CategoryDataset dataset, Comparable rowKey, Comparable columnKey) {
087        super(area, toolTipText, urlText);
088        Args.nullNotPermitted(dataset, "dataset");
089        this.dataset = dataset;
090        this.rowKey = rowKey;
091        this.columnKey = columnKey;
092    }
093
094    /**
095     * Returns the dataset this entity refers to.  This can be used to
096     * differentiate between items in a chart that displays more than one
097     * dataset.
098     *
099     * @return The dataset (never {@code null}).
100     *
101     * @see #setDataset(CategoryDataset)
102     */
103    public CategoryDataset getDataset() {
104        return this.dataset;
105    }
106
107    /**
108     * Sets the dataset this entity refers to.
109     *
110     * @param dataset  the dataset ({@code null} not permitted).
111     *
112     * @see #getDataset()
113     */
114    public void setDataset(CategoryDataset dataset) {
115        Args.nullNotPermitted(dataset, "dataset");
116        this.dataset = dataset;
117    }
118
119    /**
120     * Returns the row key.
121     *
122     * @return The row key (never {@code null}).
123     *
124     * @since 1.0.6
125     *
126     * @see #setRowKey(Comparable)
127     */
128    public Comparable getRowKey() {
129        return this.rowKey;
130    }
131
132    /**
133     * Sets the row key.
134     *
135     * @param rowKey  the row key ({@code null} not permitted).
136     *
137     * @since 1.0.6
138     *
139     * @see #getRowKey()
140     */
141    public void setRowKey(Comparable rowKey) {
142        this.rowKey = rowKey;
143    }
144
145    /**
146     * Returns the column key.
147     *
148     * @return The column key (never {@code null}).
149     *
150     * @since 1.0.6
151     *
152     * @see #setColumnKey(Comparable)
153     */
154    public Comparable getColumnKey() {
155        return this.columnKey;
156    }
157
158    /**
159     * Sets the column key.
160     *
161     * @param columnKey  the column key ({@code null} not permitted).
162     *
163     * @since 1.0.6
164     *
165     * @see #getColumnKey()
166     */
167    public void setColumnKey(Comparable columnKey) {
168        this.columnKey = columnKey;
169    }
170
171    /**
172     * Returns a string representing this object (useful for debugging
173     * purposes).
174     *
175     * @return A string (never {@code null}).
176     */
177    @Override
178    public String toString() {
179        return "CategoryItemEntity: rowKey=" + this.rowKey
180               + ", columnKey=" + this.columnKey + ", dataset=" + this.dataset;
181    }
182
183    /**
184     * Tests the entity for equality with an arbitrary object.
185     *
186     * @param obj  the object ({@code null} permitted).
187     *
188     * @return A boolean.
189     */
190    @Override
191    public boolean equals(Object obj) {
192        if (obj == this) {
193            return true;
194        }
195        if (!(obj instanceof CategoryItemEntity)) {
196            return false;
197        }
198        CategoryItemEntity that = (CategoryItemEntity) obj;
199        if (!this.rowKey.equals(that.rowKey)) {
200            return false;
201        }
202        if (!this.columnKey.equals(that.columnKey)) {
203            return false;
204        }
205        if (!ObjectUtils.equal(this.dataset, that.dataset)) {
206            return false;
207        }
208
209        return super.equals(obj);
210    }
211
212}