|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.meta.model.AbstractSequence<E> dk.rode.thesis.observer.SequenceObserversSequence<Date,Sequence.State> dk.rode.thesis.observer.DateSequence
@Participant(value={"ConcreteSubject","ConcreteObserver"}) public class DateSequence
An observable date sequence is a sequence that will
advance an initial date by one day each time next()
is
invoked and then notify relevant observers
of its state changes.
The returned dates only contain hours, day, month, and year.
Modifying returned dates will not affect a date sequence.
A date sequence may be bounded
, but is
consistent
and unique
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary | |
---|---|
private long |
date
The current date in milliseconds. |
private Date |
end
The end date of this sequence, if any. |
private Date |
start
The start date of this sequence. |
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
state |
Constructor Summary | |
---|---|
DateSequence()
No-arg constructor. |
|
DateSequence(Date start)
Constructor. |
|
DateSequence(Date start,
Date end)
Constructor. |
|
DateSequence(Date start,
int days)
Constructor. |
|
DateSequence(DateSequence sequence)
Copy constructor. |
Method Summary | |
---|---|
boolean |
bounded()
Returns true if this sequence is bounded, i.e. |
boolean |
consistent()
Returns true. |
DateSequence |
copy()
Returns a deep copy of this object. |
Date |
current()
Returns the current element from this sequence. |
protected Date |
doNext()
Hook for sub-classes to perform the actual next()
operation without notifying observers. |
Sequence.State |
getAspect()
Hook for sub-classes to deliver the changed aspect value to notify observers about immediately after SequenceObserversSequence.doNext() has been
invoked, if any. |
private static Date |
getDate(Date date)
Returns a date corresponding to date , but
where minutes, seconds, and milliseconds
have been cleared. |
private static Date |
getDate(Date date,
int days)
Returns a date corresponding to date plus
the number of days supplied as days , but
where minutes, seconds, and milliseconds
have been cleared. |
void |
reset()
Resets this sequence to start over if it is consistent. |
boolean |
unique()
Returns true. |
Methods inherited from class dk.rode.thesis.observer.SequenceObserversSequence |
---|
addObserver, addObserver, getAspects, getObservers, getObservers, next, removeObserver, removeObserver, sequenceEvent |
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
getStringablePolicy, state, toString, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
state |
Methods inherited from interface dk.rode.thesis.strategy.Stringable |
---|
getStringablePolicy, toString |
Field Detail |
---|
private long date
Hours, minutes, seconds, and milliseconds are ignored, i.e. always zero.
Never null.
private final Date end
private final Date start
Constructor Detail |
---|
public DateSequence()
The start date is set to "now", and no end date is used.
public DateSequence(Date start)
This date sequence will not have an end date.
start
- The date to start this sequence from; cannot be null.
Only hours, days, months, and years are used.
NullPointerException
- If start
is null.public DateSequence(Date start, Date end)
If end
is null, this date sequence is unbounded.
start
- The date to start this sequence from; cannot be null.
Only hours, days, months, and years are used.end
- The end date of this sequence; can be null. Only hours,
days, months, and years are used.
NullPointerException
- If start
is null.
IllegalArgumentException
- If end
is before
start
.public DateSequence(Date start, int days)
This date sequence will have an end date days
from start
. If days
is smaller than one, one
day will be used.
start
- The date to start this sequence from; cannot be null.
Only hours, days, months, and years are used.days
- The number of days in this sequence.
NullPointerException
- If start
is null.public DateSequence(DateSequence sequence)
sequence
- The date sequence to copy; cannot be null.
NullPointerException
- If sequence
is null.Method Detail |
---|
public boolean bounded()
Sequence
The same type of sequence may represent both bounded and
unbounded sequences and the behaviour is determined and fixed
at construction time.
Bounded sequences will restart if they deliver
consistent
values.
Sequence.unique()
public boolean consistent()
public DateSequence copy()
Copyable
public Date current()
Sequence
This method can be invoked even if Sequence.next()
has not been invoked yet, thus delivering the initial
value of this sequence.
protected Date doNext()
SequenceObserversSequence
next()
operation without notifying observers.
doNext
in class SequenceObserversSequence<Date,Sequence.State>
public Sequence.State getAspect()
SequenceObserversSequence
SequenceObserversSequence.doNext()
has been
invoked, if any. If this method returns null, no notification is performed as the aspect has not changed.
getAspect
in class SequenceObserversSequence<Date,Sequence.State>
private static final Date getDate(Date date)
date
, but
where minutes, seconds, and milliseconds
have been cleared.
date
- The date; cannot be null.
Date
instance;
never null.private static final Date getDate(Date date, int days)
date
plus
the number of days supplied as days
, but
where minutes, seconds, and milliseconds
have been cleared.
date
- The date; cannot be null.days
- Days to add to the date; cannot be negative.
Date
instance;
never null.
IllegalArgumentException
- If days
is negative.public void reset()
Sequence
If this sequence is consistent
, the
sequence will restart.
reset
in interface Sequence<Date>
reset
in class AbstractSequence<Date>
public boolean unique()
Sequence.consistent()
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |