sos.dated.util
Class AbstractDatedList

java.lang.Object
  |
  +--sos.dated.util.AbstractDatedObject
        |
        +--sos.dated.util.AbstractDatedCollection
              |
              +--sos.dated.util.AbstractDatedList
All Implemented Interfaces:
DatedCollection, DatedList, DatedObject
Direct Known Subclasses:
sos.dated.util.AbstractListByDate, AbstractSequentialDatedList, ArrayListByElement

public abstract class AbstractDatedList
extends AbstractDatedCollection
implements DatedList

A partial implementation of a dated list. The purpose of this class is to make it easier to create a concrete DatedList and to share implementation common across concrete classes. It provides an implementation of iterator. To create an unmodifiable dated list, the programmer can subclass this class and implement the dateIterator, get, and size methods. To create a modifiable version, the programmer must also override the set, add, and remove methods.

Since:
1.0
See Also:
AbstractDatedCollection, DatedList, ArrayListByDate, ArrayListByElement

Field Summary
 
Fields inherited from interface sos.dated.util.DatedObject
MAX_DATE, MIN_DATE
 
Constructor Summary
protected AbstractDatedList()
          No-argument constructor available only to subclasses.
 
Method Summary
 void add(int index, java.lang.Object value, java.util.Date from, java.util.Date to)
          Inserts an element into the list for a specified date range (optional operation).
 Dates add(java.lang.Object value, java.util.Date from, java.util.Date to)
          This implementation invokes add(int,Object,Date,Date) for each static window within the specified range, passing it the size of this list at the start of the window as given by size.
 Dates addAll(int index, DatedCollection datedCollection)
          Inserts an entire dated collection into this dated list at the specified index (optional operation).
protected  void checkForComodification(int expectedModCount, java.util.Date date)
          Throws a ConcurrentModificationException if the expected modification count does not equal the actual modification count for the specified date.
 void clear(java.util.Date from, java.util.Date to)
          Removes all elements from this dated collection for the specified dates (optional operation).
protected  java.lang.Object clone()
          Creates and returns a copy of this object.
 boolean equals(java.util.Date date, DatedObject obj, java.util.Date objDate)
          Indicates if this dated object at date is equal to obj at objDate.
abstract  java.lang.Object get(int index, java.util.Date date)
          Retrieves the element at the specified position on the specified date.
 int hashCode(java.util.Date date)
          This implementation merely iterates through the elements of this dated list at the specified date, computing the hash code value as required.
 int indexOf(java.lang.Object value, java.util.Date date)
          Returns the position of the first occurrence of the specified element in this list at the specified date.
 Iterator iterator(java.util.Date date)
          Returns an iterator over the elements of this dated collection at the specified date.
 int lastIndexOf(java.lang.Object value, java.util.Date date)
          Returns the position of the last occurrence of the specified element in this list at the specified date.
 ListIterator listIterator(java.util.Date date)
          Returns a list iterator over the elements of this dated list at the specified date.
 ListIterator listIterator(int index, java.util.Date date)
          Returns a list iterator over the elements of this dated list at the specified date, starting at the specified index.
protected  int modCount(java.util.Date date)
          Returns the modification count at the specified date.
 DatedValue remove(int index, java.util.Date from, java.util.Date to)
          Removes from this list the element at the specified position for the specified date range (optional operation).
protected  void removeRange(int fromIndex, int toIndex, java.util.Date from, java.util.Date to)
          Removes all elements between fromIndex, inclusive, and toIndex, exclusive, for the specified date range.
 DatedValue set(int index, java.lang.Object value, java.util.Date from, java.util.Date to)
          Replaces the element at the specified position with the specified element for the specified date range.
abstract  int size(java.util.Date date)
          Returns the number of elements in this collection at the specified date.
 DatedList subList(int fromIndex, int toIndex)
          Returns a view of this dated list restricted to the range fromIndex, inclusive, to toIndex, exclusive.
protected  void upModCount(java.util.Date from, java.util.Date to)
           
 
Methods inherited from class sos.dated.util.AbstractDatedCollection
addAll, contains, containsAll, containsThroughout, dateIterator, excludesThroughout, hasSizeThroughout, isEmpty, isEmptyThroughout, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class sos.dated.util.AbstractDatedObject
dateIterator, equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface sos.dated.util.DatedCollection
addAll, contains, containsAll, containsThroughout, excludesThroughout, hasSizeThroughout, isEmpty, isEmptyThroughout, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface sos.dated.util.DatedObject
dateIterator, dateIterator, equals, hashCode, toString
 

Constructor Detail

AbstractDatedList

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

Method Detail

add

public Dates add(java.lang.Object value,
                 java.util.Date from,
                 java.util.Date to)
This implementation invokes add(int,Object,Date,Date) for each static window within the specified range, passing it the size of this list at the start of the window as given by size.

Specified by:
add in interface DatedCollection
Overrides:
add in class AbstractDatedCollection
Parameters:
value - element to add
from - starting date at which the element should be added
to - ending date at which the element should be added
Returns:
a series of date ranges indicating when the addition changed this collection
Throws:
java.lang.NullPointerException - if from or to is null
java.lang.IllegalArgumentException

add

public void add(int index,
                java.lang.Object value,
                java.util.Date from,
                java.util.Date to)
Inserts an element into the list for a specified date range (optional operation). This implementation throws an UnsupportedOperationException.

Specified by:
add in interface DatedList
Parameters:
index - position to insert the element
value - element to insert
from - starting date at which the element should be inserted
to - ending date at which the element should be inserted
Throws:
java.lang.UnsupportedOperationException - always

addAll

public Dates addAll(int index,
                    DatedCollection datedCollection)
Inserts an entire dated collection into this dated list at the specified index (optional operation).

Specified by:
addAll in interface DatedList
Parameters:
index - index at which to insert the dated collection
datedCollection - collection to insert into this dated list
Returns:
a series of date ranges for which this list changed
Throws:
java.lang.IndexOutOfBoundsException - if index < 0 || index > size( d ) where d is a date when elements exist in datedCollection
java.lang.NullPointerException - datedCollection is null

checkForComodification

protected void checkForComodification(int expectedModCount,
                                      java.util.Date date)
Throws a ConcurrentModificationException if the expected modification count does not equal the actual modification count for the specified date.

Parameters:
expectedModCount - the caller's expected modification count
date - the date in question
Throws:
java.util.ConcurrentModificationException - if the expected modification count does not equal the actual modification count for the specified date

clear

public void clear(java.util.Date from,
                  java.util.Date to)
Removes all elements from this dated collection for the specified dates (optional operation).

This implementation invokes removeRange for each static window within the specified date range, passing in the size of the list at the start of the window, as gotten from a call to size.

Specified by:
clear in interface DatedCollection
Overrides:
clear in class AbstractDatedCollection
Parameters:
from - date to start clearing the collection, inclusive
to - date to finish clearing the collection, exclusive
Throws:
java.lang.NullPointerException - if from or to is null
java.lang.IllegalArgumentException - if from does not precede to

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Creates and returns a copy of this object. Subclasses that wish to be cloneable should override this method but first call their parent's clone method.

Overrides:
clone in class java.lang.Object
Returns:
a copy of this dated list
Throws:
java.lang.CloneNotSupportedException - if this object's class does not support the Cloneable interface.

equals

public boolean equals(java.util.Date date,
                      DatedObject obj,
                      java.util.Date objDate)
Description copied from interface: DatedObject
Indicates if this dated object at date is equal to obj at objDate.

Specified by:
equals in interface DatedList
Overrides:
equals in class AbstractDatedObject
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 date equals another dated object at objDate
Throws:
java.lang.NullPointerException - if any of the parameters equal null

get

public abstract java.lang.Object get(int index,
                                     java.util.Date date)
Description copied from interface: DatedList
Retrieves the element at the specified position on the specified date.

Specified by:
get in interface DatedList
Parameters:
index - position to retrieve an element
date - date at which this list is to be queried
Returns:
the element at the specified position on the specified date

hashCode

public int hashCode(java.util.Date date)
This implementation merely iterates through the elements of this dated list at the specified date, computing the hash code value as required.

Specified by:
hashCode in interface DatedList
Overrides:
hashCode in class AbstractDatedObject
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

indexOf

public int indexOf(java.lang.Object value,
                   java.util.Date date)
Returns the position of the first occurrence of the specified element in this list at the specified date. After getting a list iterator at the specified date, this implementation traverses the list, stopping at the first occurrence of the specified value.

Specified by:
indexOf in interface DatedList
Parameters:
value - element whose presence is to be tested
date -
Returns:
the position of the first occurrence of the specified element in this list at the specified date.
Throws:
java.lang.NullPointerException - if date is null

iterator

public Iterator iterator(java.util.Date date)
Returns an iterator over the elements of this dated collection at the specified date. The returned iterator will always throw an UnsupportedOperationException in its remove method because a date range is required to remove an element from this dated collection.

This implementation returns listIterator( date ).

Specified by:
iterator in interface DatedCollection
Specified by:
iterator in class AbstractDatedCollection
Parameters:
date - date at which to iterate through the elements
Returns:
an iterator over the elements of this dated collection at the specified date.
Throws:
java.lang.NullPointerException

lastIndexOf

public int lastIndexOf(java.lang.Object value,
                       java.util.Date date)
Returns the position of the last occurrence of the specified element in this list at the specified date. After getting a list iterator at the specified date and positioned after the last element, this implementation traverses the list in reverse, stopping at the first occurrence of the specified value.

Specified by:
lastIndexOf in interface DatedList
Parameters:
value - element whose presence is to be tested
date -
Returns:
the position of the first occurrence of the specified element in this list at the specified date.
Throws:
java.lang.NullPointerException - if date is null

listIterator

public ListIterator listIterator(java.util.Date date)
Returns a list iterator over the elements of this dated list at the specified date. This implementation returns listIterator( 0, date ).

Specified by:
listIterator in interface DatedList
Parameters:
date - date at which to iterate over the elements of this dated list
Returns:
a list iterator at the specified date
Throws:
java.lang.NullPointerException - if date is null

listIterator

public ListIterator listIterator(int index,
                                 java.util.Date date)
Returns a list iterator over the elements of this dated list at the specified date, starting at the specified index. This implementation creates a fully functional list iterator, positioned at the element given by index and date. The list iterator's update operations call this dated list's add(int,Object,Date,Date), remove(int,Date,Date), and set(int,Object,Date,Date).

Specified by:
listIterator in interface DatedList
Parameters:
index - position at which to start the iteration
date - date at which to iterate over the elements of this dated list
Returns:
a list iterator at the specified date with the specified index as its starting position
Throws:
java.lang.NullPointerException - if date is null

modCount

protected int modCount(java.util.Date date)
Returns the modification count at the specified date. The return value should be used to detect concurrent modifications and other programming errors. The value is only meaningful if assertions are turned on. If assertions are enabled for this class, the returned value is the number of times upModCount has been called with a date range that includes date. If assertions are not enabled, the returned value is always zero.

Parameters:
date - date to request the modification count
Returns:
the modification count at the specified date

remove

public DatedValue remove(int index,
                         java.util.Date from,
                         java.util.Date to)
Removes from this list the element at the specified position for the specified date range (optional operation). This implementation throws an UnsupportedOperationException.

Specified by:
remove in interface DatedList
Parameters:
index - position at which to start the iteration
from - starting date at which the element should be removed
to - ending date at which the element should be removed
Returns:
the element at the specified index from this list for the specified date range.
Throws:
java.lang.UnsupportedOperationException - always

removeRange

protected void removeRange(int fromIndex,
                           int toIndex,
                           java.util.Date from,
                           java.util.Date to)
Removes all elements between fromIndex, inclusive, and toIndex, exclusive, for the specified date range. The dated list is constant in the date range. This implementaion gets a list iterator at from, starting at fromIndex. It then iterates through the elements up to toIndex, invoking remove(from,to). Subclasses may override this method to make it more efficient for the particular implementation.

Parameters:
fromIndex - start index of elements to remove
toIndex - end index of elements to remove
from - start date (inclusive) for which the elements should be removed
to - end date (exclusive) for which the elements should be removed

set

public DatedValue set(int index,
                      java.lang.Object value,
                      java.util.Date from,
                      java.util.Date to)
Replaces the element at the specified position with the specified element for the specified date range. This implementation throws an UnsupportedOperationException.

Specified by:
set in interface DatedList
Parameters:
index - position to place the element
value - element to place in this list
from - starting date at which the position should be set
to - ending date at which the position should be set
Throws:
java.lang.UnsupportedOperationException - always

size

public abstract int size(java.util.Date date)
Description copied from interface: DatedCollection
Returns the number of elements in this collection at the specified date.

Specified by:
size in interface DatedCollection
Overrides:
size in class AbstractDatedCollection
Parameters:
date - date at which this collection is to be queried
Returns:
the number of elements on the specified date

subList

public DatedList subList(int fromIndex,
                         int toIndex)
Returns a view of this dated list restricted to the range fromIndex, inclusive, to toIndex, exclusive. Changes made to the returned sub list are reflected in the master list, and vice versa. This implementation returns a fully operational sublist. The sublist implements RandomAccess if this dated list implements RandomAccess.

Specified by:
subList in interface DatedList
Parameters:
fromIndex - starting position of the returned view (inclusive)
toIndex - ending position of the returned view (exclusive)
Returns:
a fully modifiable view of this dated list restricted to the specified range
Throws:
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException

upModCount

protected void upModCount(java.util.Date from,
                          java.util.Date to)


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