Side of Software
Dated Collections Library 2.0

sos.dated.util
Class ArrayListByDate<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.AbstractDatedList<E,D>
              extended by sos.dated.util.ArrayListByDate<E,D>
Type Parameters:
E - the type of elements maintained by this dated list
D - the type of dates used by this dated list
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.RandomAccess, DatedCollection<E,D>, DatedList<E,D>, DatedObject<D>

public class ArrayListByDate<E,D>
extends AbstractDatedList<E,D>
implements DatedList<E,D>, java.io.Serializable, java.lang.Cloneable, java.util.RandomAccess

An implementation of DatedList that can efficiently iterate through the list of elements at a given date by maintaining a java.util.ArrayList at each date. The following illustration shows a conceptual view of a small ArrayListByDate where the "dates" are integers and the elements are characters:

This implementation is serializable and cloneable; however, it is not synchronized. To use it safely in a multi-threaded situation, wrap an instance of the dated list with a call to DatedCollections.synchronizedDatedList.

Since:
1.0
See Also:
ArrayListByElement, DatedList, DatedCollections.synchronizedDatedList(DatedList)

Constructor Summary
ArrayListByDate()
          Creates an empty ArrayListByDate.
ArrayListByDate(DatedCollection<? extends E,D> datedCollection)
          Creates an ArrayListByDate initialized with the elements of datedCollection.
 
Method Summary
 Dates<D> add(E value, D from, D to)
          Adds the specified element to this dated collection for the specified date range (optional operation).
 void add(int index, E value, D from, D to)
          Inserts an element into this dated list for a specified date range (optional operation).
 void clear(D from, D to)
          Removes all elements from this dated collection for the specified dates (optional operation).
 java.lang.Object clone()
          Creates and returns a shallow copy of this object.
protected  java.util.List<E> copyList(java.util.List<E> list)
          Creates and returns a copy of the specified list.
protected  java.util.List<E> createList()
          Creates and returns a new empty list to hold the elements for a date range.
 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.
 E get(int index, D at)
          Retrieves the element at the specified position on the specified date.
 DatedValue<E,D> remove(int index, D from, D to)
          Removes from this dated list the element at the specified position for the specified date range (optional operation).
 DatedValue<E,D> set(int index, E value, D from, D to)
          Replaces the element at the specified position with the specified element for the specified date range.
 int size(D at)
          Returns the number of elements in this dated collection at the specified date.
 
Methods inherited from class sos.dated.util.AbstractDatedList
addAll, checkForComodification, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, modCount, removeRange, subList, upModCount
 
Methods inherited from class sos.dated.util.AbstractDatedCollection
addAll, contains, containsAll, containsThroughout, 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.DatedList
add, addAll, equals, get, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, set, subList
 
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

ArrayListByDate

public ArrayListByDate()
Creates an empty ArrayListByDate.


ArrayListByDate

public ArrayListByDate(DatedCollection<? extends E,D> datedCollection)
Creates an ArrayListByDate initialized with the elements of datedCollection.

Parameters:
datedCollection - collection with which to initialize the new ArrayListByDate
Throws:
java.lang.NullPointerException - if datedCollection is null
Method Detail

clone

public java.lang.Object clone()
Description copied from class: AbstractDatedList
Creates and returns a shallow copy of this object. Subclasses that wish to be cloneable should override this method but first call their parent's clone method.

Returns:
a copy of this dated list

createList

protected java.util.List<E> createList()
Creates and returns a new empty list to hold the elements for a date range. This implementation returns a new ArrayList. Subclasses may override this if they wish to use a different type of list, such as an ArrayList with an initial capacity.

Returns:
a new empty list

copyList

protected java.util.List<E> copyList(java.util.List<E> list)
Creates and returns a copy of the specified list. This implementation returns new ArrayList(list).

Parameters:
list - list to copy
Returns:
a shallow copy of list

add

public Dates<D> add(E value,
                    D from,
                    D to)
Adds the specified element to this dated collection for the specified date range (optional operation).

The returned value indicates when this dated collection changed as a result of the call and is applicable only for the specified date range. It may be read-only, and it is not tied to this dated collection.

This implementation throws an UnsupportedOperationException.

This implementation invokes add(int,Object,D,D) 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<E,D>
Overrides:
add in class AbstractDatedList<E,D>
Parameters:
value - element to add
from - starting date (inclusive) at which the element should be added
to - ending date (exclusive) at which the element should be added
Returns:
a series of date ranges indicating when the addition changed this dated collection
Throws:
java.lang.IllegalArgumentException - if from does not precede to or if some property of value prevents it from being added to this dated collection
java.lang.NullPointerException - if from or to is null or if value is null and this dated collection cannot hold null elements

add

public void add(int index,
                E value,
                D from,
                D to)
Description copied from class: AbstractDatedList
Inserts an element into this dated list for a specified date range (optional operation). This implementation throws an UnsupportedOperationException.

Specified by:
add in interface DatedList<E,D>
Overrides:
add in class AbstractDatedList<E,D>
Parameters:
index - position to insert the element
value - element to insert
from - starting date (inclusive) at which the element should be inserted
to - ending date (exclusive) at which the element should be inserted

clear

public void clear(D from,
                  D to)
Description copied from class: AbstractDatedList
Removes all elements from this dated collection for the specified dates (optional operation).

This implementation repeatedly invokes remove on the iterator, while iterating through the elements at each date within the specified range. 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<E,D>
Overrides:
clear in class AbstractDatedList<E,D>
Parameters:
from - starting date (inclusive) at which this dated collection should be cleared
to - ending date (exclusive) at which this dated collection should be cleared

dateIterator

public 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. 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>
Specified by:
dateIterator in class AbstractDatedCollection<E,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
Throws:
java.lang.NullPointerException

get

public E get(int index,
             D at)
Description copied from interface: DatedList
Retrieves the element at the specified position on the specified date.

Specified by:
get in interface DatedList<E,D>
Specified by:
get in class AbstractDatedList<E,D>
Parameters:
index - position to retrieve an element
at - date at which this dated list is to be queried
Returns:
the element at the specified position on the specified date

remove

public DatedValue<E,D> remove(int index,
                              D from,
                              D to)
Description copied from class: AbstractDatedList
Removes from this dated 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<E,D>
Overrides:
remove in class AbstractDatedList<E,D>
Parameters:
index - position at which to start the iteration
from - starting date (inclusive) at which the element should be removed
to - ending date (exclusive) at which the element should be removed
Returns:
the elements previously at the specified index from this list for the specified date range.

set

public DatedValue<E,D> set(int index,
                           E value,
                           D from,
                           D to)
Description copied from class: AbstractDatedList
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<E,D>
Overrides:
set in class AbstractDatedList<E,D>
Parameters:
index - position of the element to replace
value - element to place in this list
from - starting date (inclusive) at which the position should be set
to - ending date (exclusive) at which the position should be set

size

public int size(D at)
Description copied from class: AbstractDatedCollection
Returns the number of elements in this dated collection at the specified date.

This implementation iterates through the elements at the specified date, counting the elements as it goes.

A subclass that can determine the size of its collection more efficiently should override this method.

Specified by:
size in interface DatedCollection<E,D>
Specified by:
size in class AbstractDatedList<E,D>
Parameters:
at - date at which this dated collection is to be queried
Returns:
the number of elements on the specified date
See Also:
DatedCollection.hasSizeThroughout(int, D, D)

Side of Software
Dated Collections Library 2.0

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