KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > DateRange


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------
23  * DateRange.java
24  * --------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Bill Kelemen;
29  *
30  * $Id: DateRange.java,v 1.6 2003/09/24 12:06:27 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 22-Apr-2002 : Version 1 based on code by Bill Kelemen (DG);
35  * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
36  * 23-Sep-2003 : Minor Javadoc update (DG);
37  *
38  */

39
40 package org.jfree.data;
41
42 import java.text.DateFormat JavaDoc;
43 import java.util.Date JavaDoc;
44
45 /**
46  * A range specified in terms of two <code>java.util.Date</code> objects.
47  * <p>
48  * Instances of this class are immutable.
49  *
50  * @author David Gilbert
51  * @author Bill Kelemen
52  */

53 public class DateRange extends Range {
54
55     /** The lower bound for the range. */
56     private Date JavaDoc lowerDate;
57
58     /** The upper bound for the range. */
59     private Date JavaDoc upperDate;
60
61     /**
62      * Default constructor.
63      */

64     public DateRange() {
65
66         this(new Date JavaDoc(0), new Date JavaDoc(1));
67
68     }
69
70     /**
71      * Constructs a new range.
72      *
73      * @param lower the lower bound.
74      * @param upper the upper bound.
75      */

76     public DateRange(Date JavaDoc lower, Date JavaDoc upper) {
77
78         super(lower.getTime(), upper.getTime());
79         this.lowerDate = lower;
80         this.upperDate = upper;
81
82     }
83
84     /**
85      * Constructs a new range.
86      *
87      * @param lower the lower (oldest) date.
88      * @param upper the upper (most recent) date.
89      */

90     public DateRange(double lower, double upper) {
91
92         super(lower, upper);
93         this.lowerDate = new Date JavaDoc((long) lower);
94         this.upperDate = new Date JavaDoc((long) upper);
95
96
97     }
98
99     /**
100      * Constructs a new range based on another range.
101      * <P>
102      * The other range may not be a {@link DateRange}. If it is not, the upper
103      * and lower bounds are evaluated as milliseconds since midnight
104      * GMT, 1-Jan-1970.
105      *
106      * @param other the other range.
107      */

108     public DateRange(Range other) {
109
110         this(other.getLowerBound(), other.getUpperBound());
111
112     }
113
114     /**
115      * Returns the lower bound for the range.
116      *
117      * @return the lower bound for the range.
118      */

119     public Date JavaDoc getLowerDate() {
120         return this.lowerDate;
121     }
122
123     /**
124      * Returns the upper bound for the range.
125      *
126      * @return the upper bound for the range.
127      */

128     public Date JavaDoc getUpperDate() {
129         return this.upperDate;
130     }
131     
132     /**
133      * Returns a string representing the date range (useful for debugging).
134      *
135      * @return A string representing the date range.
136      */

137     public String JavaDoc toString() {
138         DateFormat JavaDoc df = DateFormat.getDateTimeInstance();
139         return "[" + df.format(this.lowerDate) + " --> " + df.format(this.upperDate) + "]";
140     }
141
142 }
143
Popular Tags