Class SequenceList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.SequenceList<E>
-
- All Implemented Interfaces:
ListEventListener<E>,EventList<E>,java.lang.Iterable<E>,java.util.Collection<E>,java.util.EventListener,java.util.List<E>,java.util.RandomAccess
public final class SequenceList<E> extends TransformedList<E,E> implements java.util.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 aComparatorand aSequenceList.Sequencercan 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 endWarning: This class is thread ready but not thread safe. See
EventListfor 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
Nested Classes Modifier and Type Class Description static interfaceSequenceList.Sequencer<E>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
source
-
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
-
-
Constructor Summary
Constructors Constructor Description SequenceList(EventList<E> source, SequenceList.Sequencer<E> sequencer)Constructs a SequenceList containing a sequence of values produced by thesequencerwhich cover the range of values contained within thesource.SequenceList(EventList<E> source, SequenceList.Sequencer<E> sequencer, java.util.Comparator<? super E> comparator)Constructs a SequenceList containing a sequence of values produced by thesequencerwhich cover the range of values contained within thesource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Eget(int index)Returns the element at the specified position in this list.EgetNextSequenceValue(E value)Returns the next value in the sequence defined by this list orvalueitself if it is a sequence value.EgetPreviousSequenceValue(E value)Returns the previous value in the sequence defined by this list orvalueitself if it is a sequence value.protected booleanisWritable()Gets whether the sourceEventListis writable via this API.voidlistChanged(ListEvent<E> listChanges)When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.intsize()Returns the number of elements in this list.-
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, dispose, getSourceIndex, remove, removeAll, retainAll, set
-
Methods inherited from class ca.odell.glazedlists.AbstractEventList
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
SequenceList
public SequenceList(EventList<E> source, SequenceList.Sequencer<E> sequencer)
Constructs a SequenceList containing a sequence of values produced by thesequencerwhich cover the range of values contained within thesource.- Parameters:
source- the raw values to build a sequence aroundsequencer- the logic to produce sequence values relative to a value
-
SequenceList
public SequenceList(EventList<E> source, SequenceList.Sequencer<E> sequencer, java.util.Comparator<? super E> comparator)
Constructs a SequenceList containing a sequence of values produced by thesequencerwhich cover the range of values contained within thesource. The givencomparatordetermines the order of the sequence values.- Parameters:
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 values
-
-
Method Detail
-
isWritable
protected boolean isWritable()
Description copied from class:TransformedListGets whether the sourceEventListis writable via this API.Extending classes must override this method in order to make themselves writable.
- Specified by:
isWritablein classTransformedList<E,E>- Returns:
- false; SequenceList is readonly
-
size
public int size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
-
get
public E get(int index)
Returns the element at the specified position in this list.- Specified by:
getin interfacejava.util.List<E>- Overrides:
getin classTransformedList<E,E>- Parameters:
index- index of element to return.- Returns:
- the element at the specified position in this list.
-
getPreviousSequenceValue
public E getPreviousSequenceValue(E value)
Returns the previous value in the sequence defined by this list orvalueitself 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
-
getNextSequenceValue
public E getNextSequenceValue(E value)
Returns the next value in the sequence defined by this list orvalueitself 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
-
listChanged
public void listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.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.
- Specified by:
listChangedin interfaceListEventListener<E>- Specified by:
listChangedin classTransformedList<E,E>- Parameters:
listChanges- aListEventdescribing the changes to the list
-
-