Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * -------------- 28: * DateRange.java 29: * -------------- 30: * (C) Copyright 2002-2005, by Object Refinery Limited and Contributors. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): Bill Kelemen; 34: * 35: * $Id: DateRange.java,v 1.5.2.1 2005/10/25 21:35:24 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 22-Apr-2002 : Version 1 based on code by Bill Kelemen (DG); 40: * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); 41: * 23-Sep-2003 : Minor Javadoc update (DG); 42: * 43: */ 44: 45: package org.jfree.data.time; 46: 47: import java.io.Serializable; 48: import java.text.DateFormat; 49: import java.util.Date; 50: 51: import org.jfree.data.Range; 52: 53: /** 54: * A range specified in terms of two <code>java.util.Date</code> objects. 55: * Instances of this class are immutable. 56: */ 57: public class DateRange extends Range implements Serializable { 58: 59: /** For serialization. */ 60: private static final long serialVersionUID = -4705682568375418157L; 61: 62: /** The lower bound for the range. */ 63: private Date lowerDate; 64: 65: /** The upper bound for the range. */ 66: private Date upperDate; 67: 68: /** 69: * Default constructor. 70: */ 71: public DateRange() { 72: this(new Date(0), new Date(1)); 73: } 74: 75: /** 76: * Constructs a new range. 77: * 78: * @param lower the lower bound (<code>null</code> not permitted). 79: * @param upper the upper bound (<code>null</code> not permitted). 80: */ 81: public DateRange(Date lower, Date upper) { 82: 83: super(lower.getTime(), upper.getTime()); 84: this.lowerDate = lower; 85: this.upperDate = upper; 86: 87: } 88: 89: /** 90: * Constructs a new range using two values that will be interpreted as 91: * "milliseconds since midnight GMT, 1-Jan-1970". 92: * 93: * @param lower the lower (oldest) date. 94: * @param upper the upper (most recent) date. 95: */ 96: public DateRange(double lower, double upper) { 97: super(lower, upper); 98: this.lowerDate = new Date((long) lower); 99: this.upperDate = new Date((long) upper); 100: } 101: 102: /** 103: * Constructs a new range that is based on another {@link Range}. The 104: * other range does not have to be a {@link DateRange}. If it is not, the 105: * upper and lower bounds are evaluated as milliseconds since midnight 106: * GMT, 1-Jan-1970. 107: * 108: * @param other the other range (<code>null</code> not permitted). 109: */ 110: public DateRange(Range other) { 111: this(other.getLowerBound(), other.getUpperBound()); 112: } 113: 114: /** 115: * Returns the lower (earlier) date for the range. 116: * 117: * @return The lower date for the range. 118: */ 119: public Date getLowerDate() { 120: return this.lowerDate; 121: } 122: 123: /** 124: * Returns the upper (later) date for the range. 125: * 126: * @return The upper date for the range. 127: */ 128: public Date 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 toString() { 138: DateFormat df = DateFormat.getDateTimeInstance(); 139: return "[" + df.format(this.lowerDate) + " --> " 140: + df.format(this.upperDate) + "]"; 141: } 142: 143: }