Side of Software
Dated Collections Library 2.0

sos.dated.util
Class AbstractDatedSet<E,D>

java.lang.Object
  extended by sos.dated.util.AbstractDatedObject<D>
      extended by sos.dated.util.AbstractDatedCollection<E,D>
          extended by sos.dated.util.AbstractDatedSet<E,D>
Type Parameters:
E - the type of elements maintained by this dated set
D - the type of dates used by this dated set
All Implemented Interfaces:
DatedCollection<E,D>, DatedObject<D>, DatedSet<E,D>
Direct Known Subclasses:
HashSetByDate, HashSetByElement, LinkedHashSetByDate, TreeSetByDate, TreeSetByElement

public abstract class AbstractDatedSet<E,D>
extends AbstractDatedCollection<E,D>
implements DatedSet<E,D>

A partial implementation of a dated set. This class provides an implementation of equals(D,DatedObject,D) and hashCode(D) that satisfies the contracts specified in DatedSet.

Since:
1.0
See Also:
DatedSet, HashSetByDate, HashSetByElement, TreeSetByDate, TreeSetByElement

Constructor Summary
protected AbstractDatedSet()
          No-argument constructor available to subclasses only.
 
Method Summary
 boolean equals(D date, DatedObject<D> obj, D objDate)
          Indicates if this dated object at at is equal to obj at objAt.
 int hashCode(D date)
          Returns a hash code value of this dated object at the specified date.
 
Methods inherited from class sos.dated.util.AbstractDatedCollection
add, addAll, clear, contains, containsAll, containsThroughout, dateIterator, excludesThroughout, hasSizeThroughout, isEmpty, isEmptyThroughout, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
 
Methods inherited from class sos.dated.util.AbstractDatedObject
dateIterator, equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface sos.dated.util.DatedCollection
add, addAll, clear, contains, containsAll, containsThroughout, excludesThroughout, hasSizeThroughout, isEmpty, isEmptyThroughout, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface sos.dated.util.DatedObject
dateIterator, dateIterator, equals, hashCode, toString
 

Constructor Detail

AbstractDatedSet

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

Method Detail

equals

public boolean equals(D date,
                      DatedObject<D> obj,
                      D objDate)
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.

Two sets are equivalent at the specified dates if their sizes are equal and one set contains all elements of the other set. Once this implementation has checked reference equality and verified that the argument is of type DatedSet, it checks if the sizes of this set and the set passed in are equal. If not, it iterates through the elements of obj at objDate, checking if this set contains the elements at date.

Specified by:
equals in interface DatedObject<D>
Specified by:
equals in interface DatedSet<E,D>
Overrides:
equals in class AbstractDatedObject<D>
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 this dated object at at equals another dated object at objAt
Throws:
java.lang.NullPointerException - if any argument is null

hashCode

public int hashCode(D date)
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.

The hash code of a DatedSet at a date is calculated the same way as in hashCode of java.util.Set. This implementation iterates through the elements of this dated set at the specified date and sums the hash code values of the elements.

Specified by:
hashCode in interface DatedObject<D>
Specified by:
hashCode in interface DatedSet<E,D>
Overrides:
hashCode in class AbstractDatedObject<D>
Parameters:
date - 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 if at is null

Side of Software
Dated Collections Library 2.0

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