Class TransformedList<S,E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<S,E>
-
- All Implemented Interfaces:
ListEventListener<S>,EventList<E>,java.lang.Iterable<E>,java.util.Collection<E>,java.util.EventListener,java.util.List<E>
- Direct Known Subclasses:
CachingList,CollectionList,FileList,FilterList,FreezableList,FunctionList,GroupingList,NetworkList,ObservableElementList,PluggableList,PopularityList,RangeList,SeparatorList,SequenceList,SortedList,TransactionList,UniqueList
public abstract class TransformedList<S,E> extends AbstractEventList<E> implements ListEventListener<S>
A convenience class forEventLists that decorate anotherEventList. Extending classes transform their sourceEventListby modifying the order, visibility and value of its elements.Extending classes may implement the method
getSourceIndex(int)to translate between indices of this and indices of the source.Extending classes may implement the method
isWritable()to make the source writable via this API.Extending classes must explicitly call
AbstractEventList.addListEventListener(ListEventListener)to receive change notifications from the sourceEventList.Warning: This class is thread ready but not thread safe. See
EventListfor an example of thread safe code.- Author:
- Jesse Wilson
-
-
Field Summary
Fields Modifier and Type Field Description protected EventList<S>sourcethe event list to transform-
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTransformedList(EventList<S> source)Creates aTransformedListto transform the specifiedEventList.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E value)Inserts the specified element at the specified position in this list (optional operation).booleanaddAll(int index, java.util.Collection<? extends E> values)Inserts all of the elements in the specified collection into this list at the specified position (optional operation).voidclear()Removes all of the elements from this list (optional operation).voiddispose()Releases the resources consumed by thisTransformedListso that it may eventually be garbage collected.Eget(int index)Returns the element at the specified position in this list.protected intgetSourceIndex(int mutationIndex)Gets the index in the sourceEventListthat corresponds to the specified index.protected abstract booleanisWritable()Gets whether the sourceEventListis writable via this API.abstract voidlistChanged(ListEvent<S> listChanges)When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.Eremove(int index)Removes the element at the specified position in this list (optional operation).booleanremoveAll(java.util.Collection<?> collection)Removes from this list all the elements that are contained in the specified collection (optional operation).booleanretainAll(java.util.Collection<?> values)Retains only the elements in this list that are contained in the specified collection (optional operation).Eset(int index, E value)Replaces the element at the specified position in this list with the specified element (optional operation).intsize()Returns the number of elements in this list.-
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
-
TransformedList
protected TransformedList(EventList<S> source)
Creates aTransformedListto transform the specifiedEventList.- Parameters:
source- theEventListto transform
-
-
Method Detail
-
getSourceIndex
protected int getSourceIndex(int mutationIndex)
Gets the index in the sourceEventListthat corresponds to the specified index. More formally, returns the index such thatthis.get(i) == source.get(getSourceIndex(i))for all legal values ofi.
-
isWritable
protected abstract boolean isWritable()
Gets whether the sourceEventListis writable via this API.Extending classes must override this method in order to make themselves writable.
-
listChanged
public abstract void listChanged(ListEvent<S> 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<S>- Parameters:
listChanges- aListEventdescribing the changes to the list
-
add
public void add(int index, E value)Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).- Specified by:
addin interfacejava.util.List<S>- Overrides:
addin classAbstractEventList<E>- Parameters:
index- index at which the specified element is to be inserted.value- element to be inserted.
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> values)Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Specified by:
addAllin interfacejava.util.List<S>- Overrides:
addAllin classAbstractEventList<E>- Parameters:
index- index at which to insert first element from the specified collection.values- elements to be inserted into this list.- Returns:
- true if this list changed as a result of the call.
-
clear
public void clear()
Removes all of the elements from this list (optional operation). This list will be empty after this call returns (unless it throws an exception).- Specified by:
clearin interfacejava.util.Collection<S>- Specified by:
clearin interfacejava.util.List<S>- Overrides:
clearin classAbstractEventList<E>
-
get
public E get(int index)
Returns the element at the specified position in this list.- Specified by:
getin interfacejava.util.List<S>- Specified by:
getin classAbstractEventList<E>- Parameters:
index- index of element to return.- Returns:
- the element at the specified position in this list.
-
remove
public E remove(int index)
Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.- Specified by:
removein interfacejava.util.List<S>- Overrides:
removein classAbstractEventList<E>- Parameters:
index- the index of the element to removed.- Returns:
- the element previously at the specified position.
-
removeAll
public boolean removeAll(java.util.Collection<?> collection)
Removes from this list all the elements that are contained in the specified collection (optional operation).- Specified by:
removeAllin interfacejava.util.Collection<S>- Specified by:
removeAllin interfacejava.util.List<S>- Overrides:
removeAllin classAbstractEventList<E>- Parameters:
collection- collection that defines which elements will be removed from this list.- Returns:
- true if this list changed as a result of the call.
- See Also:
AbstractEventList.remove(Object),AbstractEventList.contains(Object)
-
retainAll
public boolean retainAll(java.util.Collection<?> values)
Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all the elements that are not contained in the specified collection.- Specified by:
retainAllin interfacejava.util.Collection<S>- Specified by:
retainAllin interfacejava.util.List<S>- Overrides:
retainAllin classAbstractEventList<E>- Parameters:
values- collection that defines which elements this set will retain.- Returns:
- true if this list changed as a result of the call.
- See Also:
AbstractEventList.remove(Object),AbstractEventList.contains(Object)
-
set
public E set(int index, E value)
Replaces the element at the specified position in this list with the specified element (optional operation).- Specified by:
setin interfacejava.util.List<S>- Overrides:
setin classAbstractEventList<E>- Parameters:
index- index of element to replace.value- element to be stored at the specified position.- Returns:
- the element previously at the specified position.
-
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.- Specified by:
sizein interfacejava.util.Collection<S>- Specified by:
sizein interfacejava.util.List<S>- Specified by:
sizein classAbstractEventList<E>- Returns:
- the number of elements in this list.
-
dispose
public void dispose()
Releases the resources consumed by thisTransformedListso that it may eventually be garbage collected.A
TransformedListwill be garbage collected without a call todispose(), but not before its sourceEventListis garbage collected. By callingdispose(), you allow theTransformedListto be garbage collected before its sourceEventList. This is necessary for situations where aTransformedListis short-lived but its sourceEventListis long-lived.Warning: It is an error to call any method on a
TransformedListafter it has been disposed.
-
-