001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2021, 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-2021, 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 java.util.Objects; 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 private Comparable rowKey; 063 064 /** 065 * The column key. 066 */ 067 private Comparable columnKey; 068 069 /** 070 * Creates a new entity instance for an item in the specified dataset. 071 * 072 * @param area the 'hotspot' area ({@code null} not permitted). 073 * @param toolTipText the tool tip text. 074 * @param urlText the URL text. 075 * @param dataset the dataset ({@code null} not permitted). 076 * @param rowKey the row key ({@code null} not permitted). 077 * @param columnKey the column key ({@code null} not permitted). 078 */ 079 public CategoryItemEntity(Shape area, String toolTipText, String urlText, 080 CategoryDataset dataset, Comparable rowKey, Comparable columnKey) { 081 super(area, toolTipText, urlText); 082 Args.nullNotPermitted(dataset, "dataset"); 083 this.dataset = dataset; 084 this.rowKey = rowKey; 085 this.columnKey = columnKey; 086 } 087 088 /** 089 * Returns the dataset this entity refers to. This can be used to 090 * differentiate between items in a chart that displays more than one 091 * dataset. 092 * 093 * @return The dataset (never {@code null}). 094 * 095 * @see #setDataset(CategoryDataset) 096 */ 097 public CategoryDataset getDataset() { 098 return this.dataset; 099 } 100 101 /** 102 * Sets the dataset this entity refers to. 103 * 104 * @param dataset the dataset ({@code null} not permitted). 105 * 106 * @see #getDataset() 107 */ 108 public void setDataset(CategoryDataset dataset) { 109 Args.nullNotPermitted(dataset, "dataset"); 110 this.dataset = dataset; 111 } 112 113 /** 114 * Returns the row key. 115 * 116 * @return The row key (never {@code null}). 117 * 118 * @see #setRowKey(Comparable) 119 */ 120 public Comparable getRowKey() { 121 return this.rowKey; 122 } 123 124 /** 125 * Sets the row key. 126 * 127 * @param rowKey the row key ({@code null} not permitted). 128 * 129 * @see #getRowKey() 130 */ 131 public void setRowKey(Comparable rowKey) { 132 this.rowKey = rowKey; 133 } 134 135 /** 136 * Returns the column key. 137 * 138 * @return The column key (never {@code null}). 139 * 140 * @see #setColumnKey(Comparable) 141 */ 142 public Comparable getColumnKey() { 143 return this.columnKey; 144 } 145 146 /** 147 * Sets the column key. 148 * 149 * @param columnKey the column key ({@code null} not permitted). 150 * 151 * @see #getColumnKey() 152 */ 153 public void setColumnKey(Comparable columnKey) { 154 this.columnKey = columnKey; 155 } 156 157 /** 158 * Returns a string representing this object (useful for debugging 159 * purposes). 160 * 161 * @return A string (never {@code null}). 162 */ 163 @Override 164 public String toString() { 165 return "CategoryItemEntity: rowKey=" + this.rowKey 166 + ", columnKey=" + this.columnKey + ", dataset=" + this.dataset; 167 } 168 169 /** 170 * Tests the entity for equality with an arbitrary object. 171 * 172 * @param obj the object ({@code null} permitted). 173 * 174 * @return A boolean. 175 */ 176 @Override 177 public boolean equals(Object obj) { 178 if (obj == this) { 179 return true; 180 } 181 if (!(obj instanceof CategoryItemEntity)) { 182 return false; 183 } 184 CategoryItemEntity that = (CategoryItemEntity) obj; 185 if (!this.rowKey.equals(that.rowKey)) { 186 return false; 187 } 188 if (!this.columnKey.equals(that.columnKey)) { 189 return false; 190 } 191 if (!Objects.equals(this.dataset, that.dataset)) { 192 return false; 193 } 194 195 return super.equals(obj); 196 } 197 198}