com.jrefinery.date
Class RelativeDayOfWeekRule

java.lang.Object
  extended by com.jrefinery.date.AnnualDateRule
      extended by com.jrefinery.date.RelativeDayOfWeekRule
All Implemented Interfaces:
java.lang.Cloneable

public class RelativeDayOfWeekRule
extends AnnualDateRule
implements java.lang.Cloneable

An annual date rule that returns a date for each year based on (a) a reference rule; (b) a day of the week; and (c) a selection parameter (SerialDate.PRECEDING, SerialDate.NEAREST, SerialDate.FOLLOWING).

For example, Good Friday can be specified as 'the Friday PRECEDING Easter Sunday'.


Field Summary
protected  int dayOfWeek
          The day of the week (SerialDate.MONDAY, SerialDate.TUESDAY, and so on).
protected  int relative
          Specifies which day of the week (PRECEDING, NEAREST or FOLLOWING).
protected  AnnualDateRule subrule
          A reference to the annual date rule on which this rule is based.
 
Constructor Summary
RelativeDayOfWeekRule()
          Default constructor - builds a rule for the Monday following 1 January.
RelativeDayOfWeekRule(AnnualDateRule subrule, int dayOfWeek, int relative)
          Standard constructor - builds rule based on the supplied sub-rule.
 
Method Summary
 java.lang.Object clone()
          Creates a clone of this rule.
 SerialDate getDate(int year)
          Returns the date generated by this rule, for the specified year.
 int getDayOfWeek()
          Returns the day-of-the-week for this rule.
 int getRelative()
          Returns the 'relative' attribute, that determines *which* day-of-the-week we are interested in.
 AnnualDateRule getSubrule()
          Returns the sub-rule (also called the reference rule).
 void setDayOfWeek(int dayOfWeek)
          Sets the day-of-the-week for this rule.
 void setRelative(int relative)
          Sets the 'relative' attribute.
 void setSubrule(AnnualDateRule subrule)
          Sets the sub-rule;
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subrule

protected AnnualDateRule subrule
A reference to the annual date rule on which this rule is based.


dayOfWeek

protected int dayOfWeek
The day of the week (SerialDate.MONDAY, SerialDate.TUESDAY, and so on).


relative

protected int relative
Specifies which day of the week (PRECEDING, NEAREST or FOLLOWING).

Constructor Detail

RelativeDayOfWeekRule

public RelativeDayOfWeekRule()
Default constructor - builds a rule for the Monday following 1 January.


RelativeDayOfWeekRule

public RelativeDayOfWeekRule(AnnualDateRule subrule,
                             int dayOfWeek,
                             int relative)
Standard constructor - builds rule based on the supplied sub-rule.

Parameters:
subrule - The rule that determines the reference date;
dayOfWeek - The day-of-the-week relative to the reference date;
relative - Indicates *which* day-of-the-week (preceding, nearest or following);
Method Detail

getSubrule

public AnnualDateRule getSubrule()
Returns the sub-rule (also called the reference rule).

Returns:
The annual date rule that determines the reference date for this rule;

setSubrule

public void setSubrule(AnnualDateRule subrule)
Sets the sub-rule;

Parameters:
subrule - The annual date rule that determines the reference date for this rule;

getDayOfWeek

public int getDayOfWeek()
Returns the day-of-the-week for this rule.

Returns:
The day-of-the-week for this rule;

setDayOfWeek

public void setDayOfWeek(int dayOfWeek)
Sets the day-of-the-week for this rule.

Parameters:
dayOfWeek - The day-of-the-week (SerialDate.MONDAY, SerialDate.TUESDAY, and so on);

getRelative

public int getRelative()
Returns the 'relative' attribute, that determines *which* day-of-the-week we are interested in.

Returns:
The 'relative' attribute (SerialDate.PRECEDING, SerialDate.NEAREST or SerialDate.FOLLOWING).

setRelative

public void setRelative(int relative)
Sets the 'relative' attribute.

Parameters:
relative - Determines *which* day-of-the-week is selected by this rule (SerialDate.PRECEDING, SerialDate.NEAREST, SerialDate.FOLLOWING);

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a clone of this rule.

Overrides:
clone in class AnnualDateRule
Returns:
A clone of the rule.
Throws:
java.lang.CloneNotSupportedException

getDate

public SerialDate getDate(int year)
Returns the date generated by this rule, for the specified year.

Specified by:
getDate in class AnnualDateRule
Parameters:
The - year (1900 <= year <= 9999).
Returns:
The date generated by the rule for the given year (null possible).


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.