Side of Software
Dated Collections Library 2.0

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

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

public abstract class AbstractDatedValue<E,D>
extends AbstractDatedObject<D>
implements DatedValue<E,D>

A partial implementation of a dated value. This abstract class makes it easier to implement the DatedValue interface. To implement an unmodifiable dated value, programmers should subclass this class and define get and dateIterator(D). To make it modifiable, programmers must also define set.

Since:
1.0
See Also:
ValueByDate, DatedValue

Constructor Summary
protected AbstractDatedValue()
          No-argument constructor available only to subclasses.
 
Method Summary
 boolean equals(D at, DatedObject<D> obj, D objAt)
          Indicates if this dated object at at is equal to obj at objAt.
 int hashCode(D at)
          Returns a hash code value of this dated object at the specified date.
 boolean is(java.lang.Object value, D at)
          Returns true if this dated value has the specified value at the specified date.
 boolean isNotThroughout(java.lang.Object value, D from, D to)
          Returns true if this dated value does not have the specified value at any date within the specified date range.
 boolean isThroughout(java.lang.Object value, D from, D to)
          Returns true if this dated value has the specified value throughout the specified date range.
 DatedValue<E,D> set(E value, D from, D to)
          Sets the value for a specified date range (optional operation).
 java.lang.String toString(D at)
          Returns a string representation of this dated object at the specified date.
 
Methods inherited from class sos.dated.util.AbstractDatedObject
dateIterator, 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.DatedValue
get
 
Methods inherited from interface sos.dated.util.DatedObject
dateIterator, dateIterator, equals, hashCode
 

Constructor Detail

AbstractDatedValue

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

Method Detail

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>
Specified by:
equals in interface DatedValue<E,D>
Overrides:
equals in class AbstractDatedObject<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(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.

This implementation invokes get to retrieve the value at the specified date If the value is null, it returns 0; otherwise, it returns the value's hash code.

Specified by:
hashCode in interface DatedObject<D>
Specified by:
hashCode in interface DatedValue<E,D>
Overrides:
hashCode in class AbstractDatedObject<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

is

public boolean is(java.lang.Object value,
                  D at)
Returns true if this dated value has the specified value at the specified date. If value is null and this dated value has not been set at the specified date, this method returns true. This implementation invokes get to retrieve the value at the specified date and tests for equality to the parameter (using equals if non-null).

Specified by:
is in interface DatedValue<E,D>
Parameters:
value - value whose presence is to be tested
at - date at which this dated value is to be queried
Returns:
true if this dated value has a specified value at a specified date
Throws:
java.lang.NullPointerException - if at is null

isNotThroughout

public boolean isNotThroughout(java.lang.Object value,
                               D from,
                               D to)
Returns true if this dated value does not have the specified value at any date within the specified date range.

This implementation iterates through the dates of this dated value, invoking is at the start of each range.

Specified by:
isNotThroughout in interface DatedValue<E,D>
Parameters:
value - value whose presence is to be tested
from - starting date (inclusive) at which containment should be tested
to - ending date (exclusive) at which containment should be tested
Returns:
true if this dated value does not have the specified value at any date within the specified date range
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if from or to is null

isThroughout

public boolean isThroughout(java.lang.Object value,
                            D from,
                            D to)
Returns true if this dated value has the specified value throughout the specified date range. This implementation iterates through the dates of this dated value, invoking is at the start of each range.

Specified by:
isThroughout in interface DatedValue<E,D>
Parameters:
value - value whose presence is to be tested
from - starting date (inclusive) at which containment should be tested
to - ending date (exclusive) at which containment should be tested
Returns:
true if this dated value has a specified value throughout the specified date range
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if from or to is null

set

public DatedValue<E,D> set(E value,
                           D from,
                           D to)
Sets the value for a specified date range (optional operation).

The returned value holds the old values before the call to set and is applicable only for the specified date range. It may be read-only, and it is not tied to this dated value.

This implementation throws an UnsupportedOperationException.

Specified by:
set in interface DatedValue<E,D>
Parameters:
value - value to be set
from - starting date (inclusive) at which the value should hold
to - ending date (exclusive) at which the value should hold
Returns:
Returns a DatedValue indicating the values held in the date range of interest before the call to set.
Throws:
java.lang.UnsupportedOperationException - always

toString

public java.lang.String toString(D at)
Returns a string representation of this dated object at the specified date. This implementation invokes get to retrieve the value at the specified date and then invokes String.valueOf to convert the value to a string.

Specified by:
toString in interface DatedObject<D>
Specified by:
toString in class AbstractDatedObject<D>
Parameters:
at - date to which the string should correspond
Returns:
a string representation of this dated object
Throws:
java.lang.NullPointerException - if at is null

Side of Software
Dated Collections Library 2.0

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