001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, 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 * CategoryTick.java
029 * -----------------
030 * (C) Copyright 2003-present, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   Tracy Hiltbrand (equals/hashCode comply with EqualsVerifier);
034 *
035 */
036
037package org.jfree.chart.axis;
038
039import java.util.Objects;
040import org.jfree.chart.text.TextBlock;
041import org.jfree.chart.text.TextBlockAnchor;
042import org.jfree.chart.ui.TextAnchor;
043
044/**
045 * A tick for a {@link CategoryAxis}.
046 */
047public class CategoryTick extends Tick {
048
049    /** The category. */
050    private final Comparable category;
051
052    /** The label. */
053    private final TextBlock label;
054
055    /** The label anchor. */
056    private final TextBlockAnchor labelAnchor;
057
058    /**
059     * Creates a new tick.
060     *
061     * @param category  the category.
062     * @param label  the label.
063     * @param labelAnchor  the label anchor.
064     * @param rotationAnchor  the rotation anchor.
065     * @param angle  the rotation angle (in radians).
066     */
067    public CategoryTick(Comparable category,
068                        TextBlock label,
069                        TextBlockAnchor labelAnchor,
070                        TextAnchor rotationAnchor,
071                        double angle) {
072
073        super("", TextAnchor.CENTER, rotationAnchor, angle);
074        this.category = category;
075        this.label = label;
076        this.labelAnchor = labelAnchor;
077
078    }
079
080    /**
081     * Returns the category.
082     *
083     * @return The category.
084     */
085    public Comparable getCategory() {
086        return this.category;
087    }
088
089    /**
090     * Returns the label.
091     *
092     * @return The label.
093     */
094    public TextBlock getLabel() {
095        return this.label;
096    }
097
098    /**
099     * Returns the label anchor.
100     *
101     * @return The label anchor.
102     */
103    public TextBlockAnchor getLabelAnchor() {
104        return this.labelAnchor;
105    }
106
107    /**
108     * Tests this category tick for equality with an arbitrary object.
109     *
110     * @param obj  the object ({@code null} permitted).
111     *
112     * @return A boolean.
113     */
114    @Override
115    public boolean equals(Object obj) {
116        if (this == obj) {
117            return true;
118        }
119        if (!(obj instanceof CategoryTick)) {
120            return false;
121        }
122        CategoryTick that = (CategoryTick) obj;
123        if (!Objects.equals(this.category, that.category)) {
124            return false;
125        }
126        if (!Objects.equals(this.label, that.label)) {
127            return false;
128        }
129        if (!Objects.equals(this.labelAnchor, that.labelAnchor)) {
130            return false;
131        }
132        if (!that.canEqual(this)) {
133            return false;
134        }
135        return super.equals(obj);
136    }
137
138    /**
139     * Ensures symmetry between super/subclass implementations of equals. For
140     * more detail, see http://jqno.nl/equalsverifier/manual/inheritance.
141     *
142     * @param other Object
143     * 
144     * @return true ONLY if the parameter is THIS class type
145     */
146    @Override
147    public boolean canEqual(Object other) {
148        // fix the "equals not symmetric" problem
149        return (other instanceof CategoryTick);
150    }
151
152    /**
153     * Returns a hash code for this object.
154     *
155     * @return A hash code.
156     */
157    @Override
158    public int hashCode() {
159        int hash = super.hashCode(); // equals calls superclass, hashCode must also
160        hash = 89 * hash + Objects.hashCode(this.category);
161        hash = 89 * hash + Objects.hashCode(this.label);
162        hash = 89 * hash + Objects.hashCode(this.labelAnchor);
163        return hash;
164    }
165}