|
jfreechart example source code file (Day.java)
The jfreechart Day.java source code
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2009, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* --------
* Day.java
* --------
* (C) Copyright 2001-2009, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* Changes
* -------
* 11-Oct-2001 : Version 1 (DG);
* 15-Nov-2001 : Updated Javadoc comments (DG);
* 04-Dec-2001 : Added static method to parse a string into a Day object (DG);
* 19-Dec-2001 : Added new constructor as suggested by Paul English (DG);
* 29-Jan-2002 : Changed getDay() method to getSerialDate() (DG);
* 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to
* evaluate with reference to a particular time zone (DG);
* 19-Mar-2002 : Changed the API for the TimePeriod classes (DG);
* 29-May-2002 : Fixed bug in equals method (DG);
* 24-Jun-2002 : Removed unnecessary imports (DG);
* 10-Sep-2002 : Added getSerialIndex() method (DG);
* 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 10-Jan-2003 : Changed base class and method names (DG);
* 13-Mar-2003 : Moved to com.jrefinery.data.time package, and implemented
* Serializable (DG);
* 21-Oct-2003 : Added hashCode() method (DG);
* 30-Sep-2004 : Replaced getTime().getTime() with getTimeInMillis() (DG);
* 04-Nov-2004 : Reverted change of 30-Sep-2004, because it won't work for
* JDK 1.3 (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 05-Oct-2006 : Updated API docs (DG);
* 06-Oct-2006 : Refactored to cache first and last millisecond values (DG);
* 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG);
* 02-Mar-2009 : Added new constructor with Locale (DG);
*
*/
package org.jfree.data.time;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import org.jfree.date.SerialDate;
/**
* Represents a single day in the range 1-Jan-1900 to 31-Dec-9999. This class
* is immutable, which is a requirement for all {@link RegularTimePeriod}
* subclasses.
*/
public class Day extends RegularTimePeriod implements Serializable {
/** For serialization. */
private static final long serialVersionUID = -7082667380758962755L;
/** A standard date formatter. */
protected static final DateFormat DATE_FORMAT
= new SimpleDateFormat("yyyy-MM-dd");
/** A date formatter for the default locale. */
protected static final DateFormat
DATE_FORMAT_SHORT = DateFormat.getDateInstance(DateFormat.SHORT);
/** A date formatter for the default locale. */
protected static final DateFormat
DATE_FORMAT_MEDIUM = DateFormat.getDateInstance(DateFormat.MEDIUM);
/** A date formatter for the default locale. */
protected static final DateFormat
DATE_FORMAT_LONG = DateFormat.getDateInstance(DateFormat.LONG);
/** The day (uses SerialDate for convenience). */
private SerialDate serialDate;
/** The first millisecond. */
private long firstMillisecond;
/** The last millisecond. */
private long lastMillisecond;
/**
* Creates a new instance, derived from the system date/time (and assuming
* the default timezone).
*/
public Day() {
this(new Date());
}
/**
* Constructs a new one day time period.
*
* @param day the day-of-the-month.
* @param month the month (1 to 12).
* @param year the year (1900 <= year <= 9999).
*/
public Day(int day, int month, int year) {
this.serialDate = SerialDate.createInstance(day, month, year);
peg(Calendar.getInstance());
}
/**
* Constructs a new one day time period.
*
* @param serialDate the day (<code>null not permitted).
*/
public Day(SerialDate serialDate) {
if (serialDate == null) {
throw new IllegalArgumentException("Null 'serialDate' argument.");
}
this.serialDate = serialDate;
peg(Calendar.getInstance());
}
/**
* Constructs a new instance, based on a particular date/time and the
* default time zone.
*
* @param time the time (<code>null not permitted).
*
* @see #Day(Date, TimeZone)
*/
public Day(Date time) {
// defer argument checking...
this(time, TimeZone.getDefault(), Locale.getDefault());
}
/**
* Constructs a new instance, based on a particular date/time and time zone.
*
* @param time the date/time.
* @param zone the time zone.
*
* @deprecated As of 1.0.13, use the constructor that specifies the locale
* also.
*/
public Day(Date time, TimeZone zone) {
this(time, zone, Locale.getDefault());
}
/**
* Constructs a new instance, based on a particular date/time and time zone.
*
* @param time the date/time (<code>null not permitted).
* @param zone the time zone (<code>null not permitted).
* @param locale the locale (<code>null not permitted).
*/
public Day(Date time, TimeZone zone, Locale locale) {
if (time == null) {
throw new IllegalArgumentException("Null 'time' argument.");
}
if (zone == null) {
throw new IllegalArgumentException("Null 'zone' argument.");
}
if (locale == null) {
throw new IllegalArgumentException("Null 'locale' argument.");
}
Calendar calendar = Calendar.getInstance(zone, locale);
calendar.setTime(time);
int d = calendar.get(Calendar.DAY_OF_MONTH);
int m = calendar.get(Calendar.MONTH) + 1;
int y = calendar.get(Calendar.YEAR);
this.serialDate = SerialDate.createInstance(d, m, y);
peg(calendar);
}
/**
* Returns the day as a {@link SerialDate}. Note: the reference that is
* returned should be an instance of an immutable {@link SerialDate}
* (otherwise the caller could use the reference to alter the state of
* this <code>Day instance, and
Other jfreechart examples (source code examples)Here is a short list of links related to this jfreechart Day.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.