ca.odell.glazedlists
Class PluggableList<E>

java.lang.Object
  extended by ca.odell.glazedlists.AbstractEventList<E>
      extended by ca.odell.glazedlists.TransformedList<E,E>
          extended by ca.odell.glazedlists.PluggableList<E>
All Implemented Interfaces:
ListEventListener<E>, EventList<E>, Iterable<E>, Collection<E>, EventListener, List<E>

public class PluggableList<E>
extends TransformedList<E,E>

An EventList which delegates all List methods to a given source EventList that may be replaced at runtime using setSource(EventList).

Note that the source EventList must use the same ListEventPublisher and ReadWriteLock, particularly if this EventList is to be used by multiple threads concurrently. To construct an EventList that shares the ListEventPublisher and ReadWriteLock with this PluggableList, use createSourceList().

Warning: This class is thread ready but not thread safe. See EventList for an example of thread safe code.

EventList Overview
Writable:yes
Concurrency:only setSource(EventList)
Performance:delegates to source EventList
Memory:N/A
Unit Tests:N/A
Issues:

Author:
James Lemieux

Field Summary
 
Fields inherited from class ca.odell.glazedlists.TransformedList
source
 
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
 
Constructor Summary
PluggableList(EventList<E> source)
          Constructs a PluggableList which delegates all List methods to the given source.
PluggableList(ListEventPublisher publisher, ReadWriteLock lock)
          Constructs a PluggableList which uses the given publisher and lock.
 
Method Summary
 EventList<E> createSourceList()
          Creates a new EventList that shares its ReadWriteLock and ListEventPublisher with this PluggableList.
 void dispose()
          Releases the resources consumed by this TransformedList so that it may eventually be garbage collected.
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.
 void setSource(EventList<E> source)
          Sets the source EventList to which this PluggableList will delegate all calls.
 
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, get, getSourceIndex, remove, removeAll, retainAll, set, size
 
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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PluggableList

public PluggableList(ListEventPublisher publisher,
                     ReadWriteLock lock)
Constructs a PluggableList which uses the given publisher and lock. The PluggableList will default to use a BasicEventList that also uses the same publisher and lock.

Parameters:
publisher - the ListEventPublisher to use within the PluggableList
lock - the ReadWriteLock to use within the PluggableList

PluggableList

public PluggableList(EventList<E> source)
Constructs a PluggableList which delegates all List methods to the given source. At some future time, the source EventList may be replaced using setSource(EventList) and this PluggableList will produce a ListEvent describing the change in data.

Parameters:
source - the source of data to this PluggableList
Method Detail

createSourceList

public EventList<E> createSourceList()
Creates a new EventList that shares its ReadWriteLock and ListEventPublisher with this PluggableList. This is necessary when this PluggableList will be used by multiple threads.

Note that the created EventList must be explicitly set as the source of this PluggableList using setSource(EventList).

Returns:
a new EventList appropriate for use as the source of this PluggableList

setSource

public void setSource(EventList<E> source)
Sets the source EventList to which this PluggableList will delegate all calls. This method is the entire reason that PluggableList exists. It allows the data source of the remaining pipeline to be altered.

To ensure correct behaviour when this PluggableList is used by multiple threads, the given source must share the same ReadWriteLock and ListEventPublisher with this PluggableList.

Parameters:
source - the new source of data for this PluggableList, and all downstream EventLists
Throws:
IllegalStateException - if this PluggableList is already disposed
IllegalArgumentException - if any of the following are true
  • the given source is null
  • the given source has a different ListEventPublisher than this PluggableList
  • the given source has a different ReadWriteLock than this PluggableList

isWritable

protected boolean isWritable()
Description copied from class: TransformedList
Gets whether the source EventList is writable via this API.

Extending classes must override this method in order to make themselves writable.

Specified by:
isWritable in class TransformedList<E,E>

listChanged

public void listChanged(ListEvent<E> listChanges)
Description copied from class: TransformedList
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:
listChanged in interface ListEventListener<E>
Specified by:
listChanged in class TransformedList<E,E>
Parameters:
listChanges - a ListEvent describing the changes to the list

dispose

public void dispose()
Description copied from class: TransformedList
Releases the resources consumed by this TransformedList so that it may eventually be garbage collected.

A TransformedList will be garbage collected without a call to TransformedList.dispose(), but not before its source EventList is garbage collected. By calling TransformedList.dispose(), you allow the TransformedList to be garbage collected before its source EventList. This is necessary for situations where a TransformedList is short-lived but its source EventList is long-lived.

Warning: It is an error to call any method on a TransformedList after it has been disposed.

Specified by:
dispose in interface EventList<E>
Overrides:
dispose in class TransformedList<E,E>


Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by hbrands at 2017-03-13 22:58