sos.dated.util
Class AbstractDatedObject

java.lang.Object
  |
  +--sos.dated.util.AbstractDatedObject
All Implemented Interfaces:
DatedObject
Direct Known Subclasses:
AbstractDatedCollection, AbstractDatedMap, AbstractDatedValue

public abstract class AbstractDatedObject
extends java.lang.Object
implements DatedObject

A partial implementation of a dated object. This class makes it easier to define a class that implements the DatedObject interface. This abstract class provides generic implementations of equals, hashCode, toString, and dateIterator(). Subclasses must define dateIterator(Date) and toString(Date).

Since:
1.0
See Also:
DatedObject

Field Summary
 
Fields inherited from interface sos.dated.util.DatedObject
MAX_DATE, MIN_DATE
 
Constructor Summary
protected AbstractDatedObject()
          No-argument constructor available only to subclasses.
 
Method Summary
 DateIterator dateIterator()
          Returns an iterator of the date ranges of when this dated object has changed.
abstract  DateIterator dateIterator(java.util.Date date)
          Returns an iterator of the date ranges of when this dated object has changed, starting at the range that contains the specified date.
 boolean equals(java.util.Date date, DatedObject obj, java.util.Date objDate)
          Indicates if another dated object is equal to this dated object at specified dates.
 boolean equals(java.lang.Object obj)
          Indicates if this dated object is equivalent to the specified object.
 int hashCode()
          Returns the hash code value of this dated object.
 int hashCode(java.util.Date date)
          Returns a hash code value of this dated object at the specified date.
 java.lang.String toString()
          Returns a string representation of this dated object.
abstract  java.lang.String toString(java.util.Date date)
          Returns a string representation of this dated object at the specified date.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDatedObject

protected AbstractDatedObject()
No-argument constructor available only to subclasses.

Method Detail

dateIterator

public DateIterator dateIterator()
Returns an iterator of the date ranges of when this dated object has changed. This method is equivalent to dateIterator( MIN_DATE ).

This implementation simply invokes dateIterator(Date), passing MIN_DATE.

Specified by:
dateIterator in interface DatedObject
Returns:
a date iterator positioned before the first date range
See Also:
dateIterator(Date)

dateIterator

public abstract DateIterator dateIterator(java.util.Date date)
Description copied from interface: DatedObject
Returns an iterator of the date ranges of when this dated object has changed, starting at the range that contains the specified date. Throughout a range returned by the iterator, the state of the dated object must be the same. Also, the states of the dated object must be different in two consecutive ranges returned by the iterator. There are no gaps in the ranges returned by the iterator. That is, if a previous date range exists, then a call to nextFrom returns the same date as previousTo. Passing MAX_DATE as the argument will return an iterator positioned at the end of the sequence.

Specified by:
dateIterator in interface DatedObject
Parameters:
date - date to position the iteration
Returns:
an iterator of the dates of when this dated object has changed, positioned immediately before the date range that contains the specified date

equals

public boolean equals(java.lang.Object obj)
Indicates if this dated object is equivalent to the specified object.

If the parameter is not a DatedObject, this implementation returns false. Otherwise, it returns true if the dates of these objects are equivalent and if these objects are equivalent at the dates.

Specified by:
equals in interface DatedObject
Overrides:
equals in class java.lang.Object
Parameters:
obj - object to check for equality to this dated object
Returns:
true if this dated object is deemed equivalent to the specified object
See Also:
equals(Date,DatedObject,Date)

equals

public boolean equals(java.util.Date date,
                      DatedObject obj,
                      java.util.Date objDate)
Indicates if another dated object is equal to this dated object at specified dates.

This implementation uses object identity to determine equality. In other words, it returns true if

   this == obj && date.equals( objDate )
Subclasses should override this method to impose a weaker equality condition.

Specified by:
equals in interface DatedObject
Parameters:
date - date at which this object should be tested
obj - the other dated object to be compared to
objDate - the date of the other dated object
Returns:
true if thid dated object at date date equals another dated object at date objDate
Throws:
java.lang.NullPointerException - if any of the parameters equal null

hashCode

public int hashCode()
Returns the hash code value of this dated object.

This implementation sums the bitwise exclusive or of the date and the object's hash code value at the date, for each date the object changes. Specifically (in pseudocode):

 hashCode = 0;
 for each date d that a change in the object occurs
    hashCode += d.hashCode() ^ hashCode( d )
 

Specified by:
hashCode in interface DatedObject
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value of this dated object
See Also:
hashCode(Date)

hashCode

public int hashCode(java.util.Date date)
Returns a hash code value of this dated object at the specified date.

This implementation returns the identity hash code value of this dated object.

Specified by:
hashCode in interface DatedObject
Parameters:
date - date to which the value should correspond
Returns:
the hash code value of this dated object at the specified date
Throws:
java.lang.NullPointerException - if date is null

toString

public java.lang.String toString()
Returns a string representation of this dated object.

This implemention forms a string as follows. Start with an open angled bracket "<". For each date of this dated object, append "d:x, " where d is a change date and x is the result of calling toString( d ). After the last date change, do not append the comma, but add a closing angle bracket ">".

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this dated object

toString

public abstract java.lang.String toString(java.util.Date date)
Description copied from interface: DatedObject
Returns a string representation of this dated object at the specified date.

Specified by:
toString in interface DatedObject
Parameters:
date - to which the string should correspond
Returns:
a string representation of this dated object


Copyright 2003 Side of Software (SOS). All rights reserved.