Side of Software
Dated Collections Library 2.0

sos.dated.util
Class AbstractDatedObject<D>

java.lang.Object
  extended by sos.dated.util.AbstractDatedObject<D>
Type Parameters:
D - the type of dates used by this dated object
All Implemented Interfaces:
DatedObject<D>
Direct Known Subclasses:
AbstractDatedCollection, AbstractDatedMap, AbstractDatedValue

public abstract class AbstractDatedObject<D>
extends java.lang.Object
implements DatedObject<D>

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

Constructor Summary
protected AbstractDatedObject()
          No-argument constructor available only to subclasses.
 
Method Summary
 DateIterator<D> dateIterator()
          Returns an iterator of the date ranges of when this dated object has changed.
abstract  DateIterator<D> dateIterator(D at)
          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(D at, DatedObject<D> obj, D objAt)
          Indicates if this dated object at at is equal to obj at objAt.
 boolean equals(java.lang.Object obj)
          Indicates if this dated object equals the specified object.
 int hashCode()
          Returns the hash code value of this dated object.
 int hashCode(D at)
          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(D at)
          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<D> dateIterator()
Returns an iterator of the date ranges of when this dated object has changed. This method is equivalent to dateIterator( null ). This implementation simply invokes dateIterator(D), passing null.

Specified by:
dateIterator in interface DatedObject<D>
Returns:
a date iterator positioned before the first date range
See Also:
DatedObject.dateIterator(Object)

dateIterator

public abstract DateIterator<D> dateIterator(D at)
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 null as the argument will return an iterator positioned at the beginning of the sequence.

Specified by:
dateIterator in interface DatedObject<D>
Parameters:
at - 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 equals the specified object. Two DatedObjects are equal if they have the same dates and if they are equal at each of these dates, as seen by equals(D,DatedObject,D). 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<D>
Overrides:
equals in class java.lang.Object
Parameters:
obj - object to compare this dated object to
Returns:
true if this dated object equals the specified object
See Also:
DatedObject.equals(Object,DatedObject,Object)

equals

public boolean equals(D at,
                      DatedObject<D> obj,
                      D objAt)
Indicates if this dated object at at is equal to obj at objAt. 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<D>
Parameters:
at - date at which this object should be tested
obj - the other dated object to be compared to
objAt - the date of the other dated object
Returns:
true if this dated object at at equals another dated object at objAt
Throws:
java.lang.NullPointerException - if any argument is 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<D>
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value of this dated object

hashCode

public int hashCode(D at)
Returns a hash code value of this dated object at the specified date. For two dated objects o1 and o2 and two dates d1 and d2, if o1.equals( d1, o2, d2 ) returns true, then o1.hashCode( d1 ) must equal o2.hashCode( d2 ). This implementation returns the identity hash code value of this dated object.

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

toString

public java.lang.String toString()
Returns a string representation of this dated object. The string representation begins with the open angled bracket "<". Then, for each date of this dated object, "d:x, " appears, where d is a change date and x is the result of calling toString( d ). After the last date change, no comma appears, and the string representation is closed with 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(D at)
Description copied from interface: DatedObject
Returns a string representation of this dated object at the specified date.

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

Side of Software
Dated Collections Library 2.0

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