001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2022, by David Gilbert 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 * CategoryLabelEntity.java 029 * ------------------------ 030 * (C) Copyright 2006-2022, by David Gilbert and Contributors. 031 * 032 * Original Author: David Gilbert; 033 * Contributor(s): -; 034 * 035 */ 036 037package org.jfree.chart.entity; 038 039import java.awt.Shape; 040import java.util.Objects; 041 042import org.jfree.chart.internal.HashUtils; 043import org.jfree.chart.axis.CategoryAxis; 044 045/** 046 * An entity to represent the labels on a {@link CategoryAxis}. 047 * 048 * @param <C> the type for the category keys. 049 */ 050public class CategoryLabelEntity<C extends Comparable<C>> extends TickLabelEntity { 051 052 /** The category key. */ 053 private final C key; 054 055 /** 056 * Creates a new entity. 057 * 058 * @param key the category key. 059 * @param area the hotspot. 060 * @param toolTipText the tool tip text. 061 * @param urlText the URL text. 062 */ 063 public CategoryLabelEntity(C key, Shape area, String toolTipText, 064 String urlText) { 065 super(area, toolTipText, urlText); 066 this.key = key; 067 } 068 069 /** 070 * Returns the category key. 071 * 072 * @return The category key. 073 */ 074 public C getKey() { 075 return this.key; 076 } 077 078 /** 079 * Tests this instance for equality with an arbitrary object. 080 * 081 * @param obj the object ({@code null} permitted). 082 * 083 * @return A boolean. 084 */ 085 @Override 086 public boolean equals(Object obj) { 087 if (obj == this) { 088 return true; 089 } 090 if (!(obj instanceof CategoryLabelEntity)) { 091 return false; 092 } 093 CategoryLabelEntity<C> that = (CategoryLabelEntity) obj; 094 if (!Objects.equals(this.key, that.key)) { 095 return false; 096 } 097 return super.equals(obj); 098 } 099 100 /** 101 * Returns a hash code for this instance. 102 * 103 * @return A hash code. 104 */ 105 @Override 106 public int hashCode() { 107 int result = super.hashCode(); 108 result = HashUtils.hashCode(result, this.key); 109 return result; 110 } 111 112 /** 113 * Returns a string representation of this entity. This is primarily 114 * useful for debugging. 115 * 116 * @return A string representation of this entity. 117 */ 118 @Override 119 public String toString() { 120 StringBuilder sb = new StringBuilder("CategoryLabelEntity: "); 121 sb.append("category="); 122 sb.append(this.key); 123 sb.append(", tooltip=").append(getToolTipText()); 124 sb.append(", url=").append(getURLText()); 125 return sb.toString(); 126 } 127}