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