|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.DateConstraint
public class DateConstraint
Stores information which defines date constraints,
and offers the accepts
method to test a given Date.
Supports these types of constraints:
dateMin
and dateMax
)dayOfWeekMin
and dayOfWeekMax
)timeOfDayMin
and timeOfDayMax
)accepts
.
Examples of how to construct DateConstraint instances:
new DateConstraint(null, null, -1, -1, -1, -1)
new DateConstraint(null, null, Calendar.MONDAY
, Calendar.FRIDAY
, 9*TimeLength.hour
+ 30*TimeLength.minute
, 16*TimeLength.hour
)
This class is multithread safe: it is immutable. In particular, it is always properly constructed, all of its fields are final, and none of their state can be changed after construction. See p. 53 of Java Concurrency In Practice for more discussion.
Nested Class Summary | |
---|---|
static class |
DateConstraint.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private Date2 |
dateMax
Specifies the maximum Date value. |
private Date2 |
dateMin
Specifies the minimum Date value. |
private int |
dayOfWeekMax
Specifies the maximum day of week value. |
private int |
dayOfWeekMin
Specifies the minimum day of week value. |
private long |
timeOfDayMax
Specifies the maximum time of day value (where the time is measured in milliseconds). |
private long |
timeOfDayMin
Specifies the minimum time of day value (where the time is measured in milliseconds). |
Constructor Summary | |
---|---|
DateConstraint(Date dateMin,
Date dateMax,
int dayOfWeekMin,
int dayOfWeekMax,
long timeOfDayMin,
long timeOfDayMax)
Constructor. |
Method Summary | |
---|---|
boolean |
accepts(Date date)
Returns true if date passes all of the constraints specified by this instance, false otherwise. |
private boolean |
equalDates(Date date1,
Date date2)
|
boolean |
equals(Object obj)
Immediately returns true if this == obj ,
or false if obj == null or ! |
Date2 |
getDateMax()
Returns the dateMax field. |
Date2 |
getDateMin()
Returns the dateMin field. |
int |
getDayOfWeekMax()
Returns the dayOfWeekMax field. |
int |
getDayOfWeekMin()
Returns the dayOfWeekMin field. |
long |
getTimeOfDayMax()
Returns the timeOfDayMax field. |
long |
getTimeOfDayMin()
Returns the timeOfDayMin field. |
int |
hashCode()
Returns a value based on all of the fields. |
String |
toString()
Returns . |
String |
toString(String separator)
Returns a String representation of this instance. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final Date2 dateMin
Contract: may be null.
Otherwise, must occur on or before dateMax
if dateMax is also non-null.
private final Date2 dateMax
Contract: may be null.
Otherwise, must occur on or after dateMin
if dateMin is also non-null.
private final int dayOfWeekMin
Contract: may be -1.
Otherwise, must (i) be in the range [Calendar.SUNDAY
, Calendar.SATURDAY
] = [1, 7]
and (ii) must be <= dayOfWeekMax
if dayOfWeekMax is also != -1.
private final int dayOfWeekMax
Contract: may be -1.
Otherwise, must (i) be in the range [Calendar.SUNDAY
, Calendar.SATURDAY
] = [1, 7]
and (ii) must be >= dayOfWeekMin
if dayOfWeekMin is also != -1.
private final long timeOfDayMin
Contract: may be -1.
Otherwise, must (i) be in the range [0, TimeLength.dayMax
]
and (ii) must be <= timeOfDayMax
if timeOfDayMax is also != -1.
private final long timeOfDayMax
Contract: may be -1.
Otherwise, must (i) be in the range [0, TimeLength.dayMax
]
and (ii) must be >= timeOfDayMin
if timeOfDayMin is also != -1.
Constructor Detail |
---|
public DateConstraint(Date dateMin, Date dateMax, int dayOfWeekMin, int dayOfWeekMax, long timeOfDayMin, long timeOfDayMax) throws IllegalArgumentException
IllegalArgumentException
- if any of the params violate the corresponding field's contractMethod Detail |
---|
public Date2 getDateMin()
dateMin
field.
public Date2 getDateMax()
dateMax
field.
public int getDayOfWeekMin()
dayOfWeekMin
field.
public int getDayOfWeekMax()
dayOfWeekMax
field.
public long getTimeOfDayMin()
timeOfDayMin
field.
public long getTimeOfDayMax()
timeOfDayMax
field.
public boolean accepts(Date date) throws IllegalArgumentException
The tests are:
Note that the logic above means that all of the bounds (both min and max) act as inclusive bounds (i.e. let f be some field of date; then f is accepted if min <= f <= max, so that the acceptance range is the closed interval [min, max]).
IllegalArgumentException
- if date == nullpublic boolean equals(Object obj)
this == obj
,
or false if obj == null
or !this.getClass().equals( obj.getClass() )
.
Otherwise, determines equality based on whether or not obj (which now must be a DateConstraint instance)
has every field equals to that of this instance.
The class equals criteria mentioned above is required because there exist subclasses of this class which contain new "aspects" (state that affects equality), so these subclasses must override this method. For more discussion, see the essay stored in the file equalsImplementation.txt
equals
in class Object
private boolean equalDates(Date date1, Date date2)
public final int hashCode()
hashCode
in class Object
public String toString()
toString
(", ")
.
toString
in class Object
public String toString(String separator) throws IllegalArgumentException
IllegalArgumentException
- if separator == null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |