com.jrefinery.data
Class Year

java.lang.Object
  extended by com.jrefinery.data.TimePeriod
      extended by com.jrefinery.data.Year
All Implemented Interfaces:
MonthConstants, java.lang.Comparable

public class Year
extends TimePeriod

Represents a year in the range 1900 to 9999.

This class is immutable, which is a requirement for all TimePeriod subclasses.


Field Summary
protected  int year
          The year.
 
Fields inherited from class com.jrefinery.data.TimePeriod
DEFAULT_TIME_ZONE, WORKING_CALENDAR
 
Fields inherited from interface com.jrefinery.date.MonthConstants
APRIL, AUGUST, DECEMBER, FEBRUARY, JANUARY, JULY, JUNE, MARCH, MAY, NOVEMBER, OCTOBER, SEPTEMBER
 
Constructor Summary
Year()
          Constructs a new Year, based on the current system date/time.
Year(java.util.Date time)
          Constructs a new Year, based on a particular instant in time, using the default time zone.
Year(java.util.Date time, java.util.TimeZone zone)
          Constructs a year, based on a particular instant in time and a time zone.
Year(int year)
          Constructs a time period representing a single year.
 
Method Summary
 int compareTo(java.lang.Object o1)
          Returns an integer indicating the order of this Year object relative to the specified object: negative == before, zero == same, positive == after.
 boolean equals(java.lang.Object object)
          Tests the equality of this Year object to an arbitrary object.
 long getEnd(java.util.Calendar calendar)
          Returns the last millisecond of the year, evaluated using the supplied calendar (which determines the time zone).
 long getStart(java.util.Calendar calendar)
          Returns the first millisecond of the year, evaluated using the supplied calendar (which determines the time zone).
 int getYear()
          Returns the year.
 TimePeriod next()
          Returns the year following this one.
static Year parseYear(java.lang.String s)
          Parses the string argument as a year.
 TimePeriod previous()
          Returns the year preceding this one.
 java.lang.String toString()
          Returns a string representing the year (e.g.
 
Methods inherited from class com.jrefinery.data.TimePeriod
getEnd, getEnd, getMiddle, getMiddle, getMiddle, getStart, getStart
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

year

protected int year
The year.

Constructor Detail

Year

public Year()
Constructs a new Year, based on the current system date/time.


Year

public Year(int year)
Constructs a time period representing a single year.

Parameters:
The - year.

Year

public Year(java.util.Date time)
Constructs a new Year, based on a particular instant in time, using the default time zone.

Parameters:
time - The time.

Year

public Year(java.util.Date time,
            java.util.TimeZone zone)
Constructs a year, based on a particular instant in time and a time zone.

Parameters:
time - The time.
zone - The time zone.
Method Detail

getYear

public int getYear()
Returns the year.

Returns:
The year.

previous

public TimePeriod previous()
Returns the year preceding this one.

Specified by:
previous in class TimePeriod
Returns:
The year preceding this one (or null if the current year is 1900).

next

public TimePeriod next()
Returns the year following this one.

Specified by:
next in class TimePeriod
Returns:
The year following this one (or null if the current year is 9999).

equals

public boolean equals(java.lang.Object object)
Tests the equality of this Year object to an arbitrary object. Returns true if the target is a Year instance representing the same year as this object. In all other cases, returns false.

Overrides:
equals in class java.lang.Object
Parameters:
object - The object.

compareTo

public int compareTo(java.lang.Object o1)
Returns an integer indicating the order of this Year object relative to the specified object: negative == before, zero == same, positive == after.


toString

public java.lang.String toString()
Returns a string representing the year (e.g. "2002").

Overrides:
toString in class java.lang.Object
Returns:
A string representing the year.

parseYear

public static Year parseYear(java.lang.String s)
                      throws TimePeriodFormatException
Parses the string argument as a year.

The string format is YYYY.

Parameters:
s - A string representing the year.
Throws:
TimePeriodFormatException

getStart

public long getStart(java.util.Calendar calendar)
Returns the first millisecond of the year, evaluated using the supplied calendar (which determines the time zone).

Specified by:
getStart in class TimePeriod
Parameters:
calendar - The calendar.
Returns:
The first millisecond of the year.

getEnd

public long getEnd(java.util.Calendar calendar)
Returns the last millisecond of the year, evaluated using the supplied calendar (which determines the time zone).

Specified by:
getEnd in class TimePeriod
Parameters:
calendar - The calendar.
Returns:
The last millisecond of the year.


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.