ca.odell.glazedlists

Class SequenceList<E>

Implemented Interfaces:
EventListener, List, RandomAccess, EventList<E>, ListEventListener<E>

public final class SequenceList<E>
extends TransformedList<S,E>
implements RandomAccess

A SequenceList contains values in adjacent indices which occur at predictable intervals from each other. A simple SequenceList could be:
 {-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
Author:
James Lemieux

Nested Class Summary

static interface
SequenceList.Sequencer
A Sequencer defines the logic required to calculate the previous and next sequence values given any value.

Field Summary

Fields inherited from class ca.odell.glazedlists.TransformedList<S,E>

source

Fields inherited from class ca.odell.glazedlists.AbstractEventList<E>

publisher, readWriteLock, updates

Constructor Summary

SequenceList(EventList source, Sequencer 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 source, Sequencer sequencer, E> comparator)
Constructs a SequenceList containing a sequence of values produced by the sequencer which cover the range of values contained within the source.

Method Summary

E
get(int index)
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()
void
listChanged(ListEvent listChanges)
int
size()

Methods inherited from class ca.odell.glazedlists.TransformedList<S,E>

add, addAll, clear, dispose, get, getSourceIndex, isWritable, listChanged, remove, removeAll, retainAll, set, size

Methods inherited from class ca.odell.glazedlists.AbstractEventList<E>

T[] toArray, add, add, addAll, addAll, addListEventListener, clear, contains, containsAll, equals, get, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeListEventListener, retainAll, set, size, subList, toArray, toString

Constructor Details

SequenceList

public SequenceList(EventList source,
                    Sequencer sequencer)
Constructs a SequenceList containing a sequence of values produced by the sequencer which cover the range of values contained within the source.
Parameters:
source - the raw values to build a sequence around
sequencer - the logic to produce sequence values relative to a value

SequenceList

public SequenceList(EventList source,
                    Sequencer sequencer,
                    E> comparator)
Constructs a SequenceList containing a sequence of values produced by the sequencer which cover the range of values contained within the source. The given comparator determines the order of the sequence values.
Parameters:
source - the raw values to build a sequence around
sequencer - the logic to produce sequence values relative to a value
comparator - determines the order of the sequence values

Method Details

get

public E get(int index)
Overrides:
get in interface TransformedList<S,E>

getNextSequenceValue

public E getNextSequenceValue(E value)
Returns the next value in the sequence defined by this list or value itself if it is a sequence value.
Parameters:
value - the value relative to which the next sequence value is returned
Returns:
the next sequence value relative to the given value

getPreviousSequenceValue

public E getPreviousSequenceValue(E value)
Returns the previous value in the sequence defined by this list or value itself if it is a sequence value.
Parameters:
value - the value relative to which the previous sequence value is returned
Returns:
the previous sequence value relative to the given value

isWritable

protected boolean isWritable()
Overrides:
isWritable in interface TransformedList<S,E>
Returns:
false; SequenceList is readonly

listChanged

public void listChanged(ListEvent listChanges)
Specified by:
listChanged in interface ListEventListener<E>

size

public int size()
Overrides:
size in interface TransformedList<S,E>

Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2009-07-14 22:05