public class PluggableList<E> extends TransformedList<E,E>
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: |
source
publisher, readWriteLock, updates
Constructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
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.
|
add, addAll, clear, get, getSourceIndex, remove, removeAll, retainAll, set, size
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
replaceAll, sort, spliterator
parallelStream, removeIf, stream
public PluggableList(ListEventPublisher publisher, ReadWriteLock lock)
publisher
and lock
.
The PluggableList will default to use a BasicEventList
that also uses the same
publisher
and lock
.publisher
- the ListEventPublisher
to use within the PluggableList
lock
- the ReadWriteLock
to use within the PluggableList
public PluggableList(EventList<E> source)
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.source
- the source of data to this PluggableListpublic EventList<E> createSourceList()
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)
.
source
of this
PluggableListpublic void setSource(EventList<E> source)
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.
source
- the new source of data for this PluggableList, and all downstream EventListsIllegalStateException
- if this PluggableList is already disposedIllegalArgumentException
- if any of the following are true
protected 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 void listChanged(ListEvent<E> listChanges)
TransformedList
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 listpublic void dispose()
TransformedList
TransformedList
so that it may eventually be
garbage collected.
A TransformedList
will be garbage collected without a call to dispose()
, but
not before its source EventList
is garbage collected. By calling #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.
Copyright © 2024 levigo holding gmbh. All rights reserved.