Side of Software
Dated Collections Library 2.0

sos.dated.util
Class ArrayListByElement<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.ArrayListByElement<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 ArrayListByElement<E,D>
extends AbstractDatedList<E,D>
implements DatedList<E,D>, java.io.Serializable, java.lang.Cloneable, java.util.RandomAccess

An implementation of DatedList that uses a single java.util.ArrayList to efficiently add and set values. The following illustration shows a conceptual view of a small ArrayListByElement where the "dates" are integers and the elements are characters:

In the above picture, the dated list contains the following elements for the following ranges:
   [1,2): [K,A,K]
   [3,5): [A,N,M]
   [5,6): [B]
   [6,9): [B,C]
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:
ArrayListByDate, DatedList, DatedCollections.synchronizedDatedList(DatedList)

Constructor Summary
ArrayListByElement()
          Creates an initially empty ArrayListByElement with a default size for the underlying list of elements.
ArrayListByElement(DatedCollection<? extends E,D> datedCollection)
          Creates an ArrayListByElement initially containing the elements and date ranges of the specified by datedCollection.
ArrayListByElement(int initialCapacity)
          Creates an initially empty ArrayListByElement with the specified initial capacity for the underlying list of elements.
 
Method Summary
 void add(int index, E value, D from, D to)
          Inserts an element into this dated list for a specified date range (optional operation).
 java.lang.Object clone()
          Creates and returns a shallow copy of this object.
 DateIterator<D> dateIterator(D date)
          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 date)
          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 date)
          Returns the number of elements in this dated collection at the specified date.
 
Methods inherited from class sos.dated.util.AbstractDatedList
add, addAll, checkForComodification, clear, 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
addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, subList
 
Methods inherited from interface sos.dated.util.DatedCollection
add, addAll, clear, contains, containsAll, containsThroughout, excludesThroughout, hasSizeThroughout, isEmpty, isEmptyThroughout, iterator, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface sos.dated.util.DatedObject
dateIterator, equals, hashCode, toString
 

Constructor Detail

ArrayListByElement

public ArrayListByElement()
Creates an initially empty ArrayListByElement with a default size for the underlying list of elements.


ArrayListByElement

public ArrayListByElement(DatedCollection<? extends E,D> datedCollection)
Creates an ArrayListByElement initially containing the elements and date ranges of the specified by datedCollection.

Parameters:
datedCollection - the dated collection whose elements and corresponding date ranges are to be placed in this date list
Throws:
java.lang.NullPointerException - if datedCollection is null

ArrayListByElement

public ArrayListByElement(int initialCapacity)
Creates an initially empty ArrayListByElement with the specified initial capacity for the underlying list of elements.

Parameters:
initialCapacity - the initial capacity for the underlying list of elements
Throws:
java.lang.IllegalArgumentException - if the initial capacity is negative
Method Detail

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

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.

Overrides:
clone in class AbstractDatedList<E,D>
Returns:
a copy of this dated list

dateIterator

public DateIterator<D> dateIterator(D date)
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>
Specified by:
dateIterator in class AbstractDatedCollection<E,D>
Parameters:
date - 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

get

public E get(int index,
             D date)
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
date - date at which this dated list is to be queried
Returns:
the element at the specified position on the specified date

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 date)
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:
date - 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)

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.

Side of Software
Dated Collections Library 2.0

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