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