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 * DateTick.java
029 * -------------
030 * (C) Copyright 2003-2022, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   Peter Kolb (patch 1934255);
034 *                   Andrew Mickish (patch 1870189);
035 *
036 */
037
038package org.jfree.chart.axis;
039
040import java.util.Date;
041import java.util.Objects;
042
043import org.jfree.chart.text.TextAnchor;
044
045import org.jfree.chart.internal.Args;
046
047/**
048 * A tick used by the {@link DateAxis} class.
049 */
050public class DateTick extends ValueTick {
051
052    /** The date. */
053    private Date date;
054
055    /**
056     * Creates a new date tick.
057     *
058     * @param date  the date.
059     * @param label  the label.
060     * @param textAnchor  the part of the label that is aligned to the anchor
061     *                    point.
062     * @param rotationAnchor  defines the rotation point relative to the text.
063     * @param angle  the rotation angle (in radians).
064     */
065    public DateTick(Date date, String label,
066                    TextAnchor textAnchor, TextAnchor rotationAnchor,
067                    double angle) {
068        this(TickType.MAJOR, date, label, textAnchor, rotationAnchor, angle);
069    }
070
071    /**
072     * Creates a new date tick.
073     *
074     * @param tickType the tick type ({@code null} not permitted).
075     * @param date  the date.
076     * @param label  the label.
077     * @param textAnchor  the part of the label that is aligned to the anchor
078     *                    point.
079     * @param rotationAnchor  defines the rotation point relative to the text.
080     * @param angle  the rotation angle (in radians).
081     */
082    public DateTick(TickType tickType, Date date, String label,
083                    TextAnchor textAnchor, TextAnchor rotationAnchor,
084                    double angle) {
085        super(tickType, date.getTime(), label, textAnchor, rotationAnchor,
086                angle);
087        Args.nullNotPermitted(tickType, "tickType");
088        this.date = date;
089    }
090
091    /**
092     * Returns the date.
093     *
094     * @return The date.
095     */
096    public Date getDate() {
097        return this.date;
098    }
099
100    /**
101     * Tests this tick for equality with an arbitrary object.
102     *
103     * @param obj  the object to test ({@code null} permitted).
104     *
105     * @return A boolean.
106     */
107    @Override
108    public boolean equals(Object obj) {
109        if (obj == this) {
110            return true;
111        }
112        if (!(obj instanceof DateTick)) {
113            return false;
114        }
115        DateTick that = (DateTick) obj;
116        if (!Objects.equals(this.date, that.date)) {
117            return false;
118        }
119        return super.equals(obj);
120    }
121
122    /**
123     * Returns a hash code for this object.
124     *
125     * @return A hash code.
126     */
127    @Override
128    public int hashCode() {
129        return this.date.hashCode();
130    }
131
132}