public final class SequenceList<E> extends TransformedList<E,E> implements java.util.RandomAccess
{-10, -5, 0, 5, 10, 15}while a more sophisticated example could be:
{Jun 1, Jul 1, Aug 1, Sep 1, Oct 1}As long as the values can be ordered via a
Comparator
and a
SequenceList.Sequencer
can be implemented to reliably produce the next or previous
value in a sequence using only some value from the source list.
SequenceList is a readonly list; calling any write method on this list
will produce an UnsupportedOperationException
.
The start and end values of the sequence are the smallest sequence values
which maintain the invariant that:
sequence start <= each value in the source list <= sequence end
Warning: This class is
thread ready but not thread safe. See EventList
for an example
of thread safe code.
EventList Overview | |
Writable: | no |
Concurrency: | thread ready, not thread safe |
Performance: | reads: O(1) |
Memory: | O(N) |
Unit Tests: | SequenceListTest |
Issues: | N/A |
Modifier and Type | Class and Description |
---|---|
static interface |
SequenceList.Sequencer<E>
A Sequencer defines the logic required to calculate the previous and
next sequence values given any value.
|
source
publisher, readWriteLock, updates
Constructor and Description |
---|
SequenceList(EventList<E> source,
SequenceList.Sequencer<E> sequencer)
Constructs a SequenceList containing a sequence of values produced by
the
sequencer which cover the range of values contained
within the source . |
SequenceList(EventList<E> source,
SequenceList.Sequencer<E> sequencer,
java.util.Comparator<? super E> comparator)
Constructs a SequenceList containing a sequence of values produced by
the
sequencer which cover the range of values contained
within the source . |
Modifier and Type | Method and Description |
---|---|
E |
get(int index)
Returns the element at the specified position in this list.
|
E |
getNextSequenceValue(E value)
Returns the next value in the sequence defined by this list or
value itself if it is a sequence value. |
E |
getPreviousSequenceValue(E value)
Returns the previous value in the sequence defined by this list or
value itself if it is a sequence value. |
protected boolean |
isWritable()
Gets whether the source
EventList is writable via this API. |
void |
listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the
object to repaint itself or update itself as necessary.
|
int |
size()
Returns the number of elements in this list.
|
add, addAll, clear, dispose, getSourceIndex, remove, removeAll, retainAll, set
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
public SequenceList(EventList<E> source, SequenceList.Sequencer<E> sequencer)
sequencer
which cover the range of values contained
within the source
.source
- the raw values to build a sequence aroundsequencer
- the logic to produce sequence values relative to a valuepublic SequenceList(EventList<E> source, SequenceList.Sequencer<E> sequencer, java.util.Comparator<? super E> comparator)
sequencer
which cover the range of values contained
within the source
. The given comparator
determines the order of the sequence values.source
- the raw values to build a sequence aroundsequencer
- the logic to produce sequence values relative to a valuecomparator
- determines the order of the sequence valuesprotected boolean isWritable()
TransformedList
EventList
is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable
in class TransformedList<E,E>
public int size()
public E get(int index)
get
in interface java.util.List<E>
get
in class TransformedList<E,E>
index
- index of element to return.public E getPreviousSequenceValue(E value)
value
itself if it is a sequence value.value
- the value relative to which the previous sequence value is returnedvalue
public E getNextSequenceValue(E value)
value
itself if it is a sequence value.value
- the value relative to which the next sequence value is returnedvalue
public void listChanged(ListEvent<E> listChanges)
It is mandatory that the calling thread has obtained the write lock on the source list. This is because the calling thread will have written to the source list to cause this event. This condition guarantees that no writes can occur while the listener is handling this event. It is an error to write to the source list while processing an event.
listChanged
in interface ListEventListener<E>
listChanged
in class TransformedList<E,E>
listChanges
- a ListEvent
describing the changes to the listGlazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by mockbuild at 2015-06-17 9:24