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 * Timeline.java
029 * -------------
030 * (C) Copyright 2000-2022, by David Gilbert and Contributors.
031 *
032 * Original Author:  Bill Kelemen;
033 * Contributor(s):   David Gilbert;
034 *
035 * Changes
036 * -------
037 * 23-May-2003 : Version 1 (BK);
038 * 09-Sep-2003 : Changed some method and parameter names (DG);
039 * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
040 *
041 */
042
043package org.jfree.chart.axis;
044
045import java.util.Date;
046
047/**
048 * An interface that defines the contract for a Timeline.
049 * <P>
050 * A Timeline will present a series of values to be used for an axis. Each
051 * Timeline must provide transformation methods between domain values and
052 * timeline values. In theory many transformations are possible.
053 * <P>
054 * A timeline can be used as parameter to a
055 * {@link org.jfree.chart.axis.DateAxis} to define the values that this axis
056 * supports.
057 * <P>
058 * Because Timelines were created mainly for Date related axis, values are
059 * represented as longs instead of doubles. In this case, the domain value is
060 * just the number of milliseconds since January 1, 1970, 00:00:00 GMT as
061 * defined by the getTime() method of {@link java.util.Date}.
062 *
063 * @see org.jfree.chart.axis.DateAxis
064 */
065public interface Timeline {
066
067    /**
068     * Translates a millisecond (as defined by java.util.Date) into an index
069     * along this timeline.
070     *
071     * @param millisecond  the millisecond.
072     *
073     * @return A timeline value.
074     */
075    long toTimelineValue(long millisecond);
076
077    /**
078     * Translates a date into a value on this timeline.
079     *
080     * @param date  the date.
081     *
082     * @return A timeline value
083     */
084    long toTimelineValue(Date date);
085
086    /**
087     * Translates a value relative to this timeline into a domain value. The
088     * domain value obtained by this method is not always the same domain value
089     * that could have been supplied to
090     * translateDomainValueToTimelineValue(domainValue).
091     * This is because the original transformation may not be complete
092     * reversable.
093     *
094     * @param timelineValue  a timeline value.
095     *
096     * @return A domain value.
097     */
098    long toMillisecond(long timelineValue);
099
100    /**
101     * Returns {@code true} if a value is contained in the timeline values.
102     *
103     * @param millisecond  the millisecond.
104     *
105     * @return {@code true} if value is contained in the timeline and
106     *         {@code false} otherwise.
107     */
108    boolean containsDomainValue(long millisecond);
109
110    /**
111     * Returns {@code true} if a date is contained in the timeline values.
112     *
113     * @param date  the date to verify.
114     *
115     * @return {@code true} if value is contained in the timeline and
116     *         {@code false}  otherwise.
117     */
118    boolean containsDomainValue(Date date);
119
120    /**
121     * Returns {@code true} if a range of values are contained in the
122     * timeline.
123     *
124     * @param fromMillisecond  the start of the range to verify.
125     * @param toMillisecond  the end of the range to verify.
126     *
127     * @return {@code true} if the range is contained in the timeline or
128     *         {@code false} otherwise
129     */
130    boolean containsDomainRange(long fromMillisecond, long toMillisecond);
131
132    /**
133     * Returns {@code true} if a range of dates are contained in the
134     * timeline.
135     *
136     * @param fromDate  the start of the range to verify.
137     * @param toDate  the end of the range to verify.
138     *
139     * @return {@code true} if the range is contained in the timeline or
140     *         {@code false} otherwise
141     */
142    boolean containsDomainRange(Date fromDate, Date toDate);
143
144}