com.jrefinery.data
Class Quarter

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

public class Quarter
extends TimePeriod

Defines a quarter (in a given year).

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

The range supported is Q1 1900 to Q4 9999.


Field Summary
static int[] FIRST_MONTH_IN_QUARTER
          The first month in each quarter.
static int FIRST_QUARTER
          Constant for quarter 1.
static int[] LAST_MONTH_IN_QUARTER
          The last month in each quarter.
static int LAST_QUARTER
          Constant for quarter 4.
protected  int quarter
          The quarter (1-4).
protected  Year year
          The year in which the quarter falls.
 
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
Quarter()
          Constructs a new Quarter, based on the current system date/time.
Quarter(java.util.Date time)
          Constructs a new Quarter, based on a date/time and the default time zone.
Quarter(java.util.Date time, java.util.TimeZone zone)
          Constructs a Quarter, based on a date/time and time zone.
Quarter(int quarter, int year)
          Constructs a new quarter.
Quarter(int quarter, Year year)
          Constructs a new quarter.
 
Method Summary
 int compareTo(java.lang.Object o1)
          Returns an integer indicating the order of this Quarter object relative to the specified object: negative == before, zero == same, positive == after.
 boolean equals(java.lang.Object obj)
          Tests the equality of this Quarter object to an arbitrary object.
 long getEnd(java.util.Calendar calendar)
          Returns the last millisecond of the Quarter, evaluated using the supplied calendar (which determines the time zone).
 int getQuarter()
          Returns the quarter.
 long getStart(java.util.Calendar calendar)
          Returns the first millisecond in the Quarter, evaluated using the supplied calendar (which determines the time zone).
 Year getYear()
          Returns the year.
static void main(java.lang.String[] args)
           
 TimePeriod next()
          Returns the quarter following this one.
static Quarter parseQuarter(java.lang.String s)
          Parses the string argument as a quarter.
 TimePeriod previous()
          Returns the quarter preceding this one.
 java.lang.String toString()
          Returns a string representing the quarter (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

FIRST_QUARTER

public static final int FIRST_QUARTER
Constant for quarter 1.

See Also:
Constant Field Values

LAST_QUARTER

public static final int LAST_QUARTER
Constant for quarter 4.

See Also:
Constant Field Values

FIRST_MONTH_IN_QUARTER

public static final int[] FIRST_MONTH_IN_QUARTER
The first month in each quarter.


LAST_MONTH_IN_QUARTER

public static final int[] LAST_MONTH_IN_QUARTER
The last month in each quarter.


year

protected Year year
The year in which the quarter falls.


quarter

protected int quarter
The quarter (1-4).

Constructor Detail

Quarter

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


Quarter

public Quarter(int quarter,
               int year)
Constructs a new quarter.

Parameters:
year - The year (1900 to 9999).
quarter - The quarter (1 to 4).

Quarter

public Quarter(int quarter,
               Year year)
Constructs a new quarter.

Parameters:
quarter - The quarter (1 to 4).
year - The year (1900 to 9999).

Quarter

public Quarter(java.util.Date time)
Constructs a new Quarter, based on a date/time and the default time zone.

Parameters:
time - The date/time.

Quarter

public Quarter(java.util.Date time,
               java.util.TimeZone zone)
Constructs a Quarter, based on a date/time and time zone.

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

getQuarter

public int getQuarter()
Returns the quarter.

Returns:
The quarter.

getYear

public Year getYear()
Returns the year.

Returns:
The year.

equals

public boolean equals(java.lang.Object obj)
Tests the equality of this Quarter object to an arbitrary object. Returns true if the target is a Quarter instance representing the same quarter 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 Quarter object relative to the specified object: negative == before, zero == same, positive == after.


previous

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

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

next

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

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

toString

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

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

getStart

public long getStart(java.util.Calendar calendar)
Returns the first millisecond in the Quarter, 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 time period.

getEnd

public long getEnd(java.util.Calendar calendar)
Returns the last millisecond of the Quarter, 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 time period.

parseQuarter

public static Quarter parseQuarter(java.lang.String s)
                            throws TimePeriodFormatException
Parses the string argument as a quarter.

This method should accept the following formats: "YYYY-QN" and "QN-YYYY", where the "-" can be a space, a forward-slash (/), comma or a dash (-).

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

main

public static void main(java.lang.String[] args)


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.