info.aduna.gee.publication.util
Class DateSpec

java.lang.Object
  extended by info.aduna.gee.publication.util.DateSpec

public class DateSpec
extends Object

A DateSpec specifies which dates are valid and which are not. It can used e.g. in a DateTemplate for specifying the dates for which the template should be used.

The DateSpec has four fields: legal years, legal months, legal dates and legal weekdays, separated by a colon. Each field can be specified to be valid for any value ('*') or as a range (e.g.: "1, 3, 5-9, 12-15, 30"). If a range is specified, its values should be legal values for the specific field. These legal values are:

 year: -100,000 - 100,000
 month: 1 - 12
 date: 1 - 31
 weekday: 0 - 7 (0 and 7 = Sunday, 1 = monday, etc.)
 

A date specification should fit the following grammar:

 dateSpec := Years:Months:Dates:Weekdays
 Years    := Range
 Months   := Range
 Dates    := Range
 Weekdays := Range
 Range    := SubRange [,SubRange]*
          |  '*'
 SubRange := N
          |  N-N
 

Where N is a legal value the part it is in (Years, Months, etc.).


Field Summary
protected  Vector _dates
          The valid date ranges.
protected  Vector _months
          The valid month ranges.
protected  Vector _weekdays
          The valid weekday ranges.
protected  Vector _years
          The valid year ranges.
 
Constructor Summary
DateSpec(String spec)
          Creates a new date specification.
 
Method Summary
protected  void _setRange(String range, Vector subranges)
          Set a range to a new value.
protected  boolean _valueInRange(int value, Vector ranges)
          Check if a value is in a certain range.
 boolean includes(WDate date)
          Check if the date specification includes a certain date.
 void setSpec(String spec)
          Set the date specification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_years

protected Vector _years
The valid year ranges.


_months

protected Vector _months
The valid month ranges.


_dates

protected Vector _dates
The valid date ranges.


_weekdays

protected Vector _weekdays
The valid weekday ranges.

Constructor Detail

DateSpec

public DateSpec(String spec)
Creates a new date specification.

Parameters:
spec - the date specification to use.
Throws:
IllegalArgumentException - if "spec" is not a legal date specification.
Method Detail

setSpec

public void setSpec(String spec)
Set the date specification.

Parameters:
spec - the date specification to set.
Throws:
IllegalArgumentException - if "spec" is not a legal date specification.

_setRange

protected void _setRange(String range,
                         Vector subranges)
Set a range to a new value. This method should only be called with parts of specifications that were found legal by isLegalSpec().

Parameters:
range - the new value (e.g.: "3, 4-5, 9").
subranges - the vector in which to store the new subranges.

includes

public boolean includes(WDate date)
Check if the date specification includes a certain date.

Parameters:
date - the date to check.
Returns:
true if the date is included, false otherwise.

_valueInRange

protected boolean _valueInRange(int value,
                                Vector ranges)
Check if a value is in a certain range.

Parameters:
value - the value to check.
range - a vector containing ranges.
Returns:
true if the value is in the range, false otherwise.


Copyright © 1997-2008 Aduna. All Rights Reserved.