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