public interface EventList<E>
extends java.util.List<E>
List. ListEventListeners can register to be
notified when this list changes. A ListEvent represents these changes
to an EventList.
EventLists may be writable or read-only. Consult the Javadoc for
your EventList if you are unsure.
Warning: EventLists
are thread ready but not thread safe. If you are sharing an EventList
between multiple threads, you can add thread safety by using the built-in
locks:
EventList myList = ...
myList.getReadWriteLock().writeLock().lock();
try {
// access myList here
if(myList.size() > 3) {
System.out.println(myList.get(3));
myList.remove(3);
}
} finally {
myList.getReadWriteLock().writeLock().unlock();
}
Note that you are also required to acquire and hold the lock during the
construction of an EventList if concurrent modifications are possible in
your environment, like so:
EventList source = ...
SortedList sorted;
source.getReadWriteLock().readLock().lock();
try {
sorted = new SortedList(source);
} finally {
source.getReadWriteLock().readLock().unlock();
}
Warning: EventLists
may break the contract required by List. For example, when
you add() on a SortedList, it will ignore the specified
index so that the element will be inserted in sorted order.
| Modifier and Type | Method and Description |
|---|---|
default void |
acceptWithReadLock(java.util.function.Consumer<EventList<E>> consumer)
Executes the block of code represented by the given consumer while holding the read lock of
this EventList.
|
default void |
acceptWithWriteLock(java.util.function.Consumer<EventList<E>> consumer)
Executes the block of code represented by the given consumer while holding the write lock of
this EventList.
|
void |
addListEventListener(ListEventListener<? super E> listChangeListener)
Registers the specified listener to receive change updates for this list.
|
default <R> R |
applyWithReadLock(java.util.function.Function<EventList<E>,R> function)
Applies the given function while holding the read lock of this EventList.
|
default <R> R |
applyWithWriteLock(java.util.function.Function<EventList<E>,R> function)
Applies the given function while holding the write lock of this EventList.
|
void |
dispose()
Disposing an EventList will make it eligible for garbage collection.
|
ListEventPublisher |
getPublisher()
Get the publisher used to distribute
ListEvents. |
ReadWriteLock |
getReadWriteLock()
Gets the lock required to share this list between multiple threads.
|
void |
removeListEventListener(ListEventListener<? super E> listChangeListener)
Removes the specified listener from receiving change updates for this list.
|
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArrayvoid addListEventListener(ListEventListener<? super E> listChangeListener)
listChangeListener - event listener != nulljava.lang.NullPointerException - if the specified listener is nullvoid removeListEventListener(ListEventListener<? super E> listChangeListener)
listChangeListener - event listener != nulljava.lang.NullPointerException - if the specified listener is nulljava.lang.IllegalArgumentException - if the specified listener wasn't added beforeReadWriteLock getReadWriteLock()
ReadWriteLock that guarantees thread safe
access to this list.ListEventPublisher getPublisher()
ListEvents. It's always defined.void dispose()
Warning: It is an error
to call any method on an EventList after it has been disposed.
default void acceptWithReadLock(java.util.function.Consumer<EventList<E>> consumer)
The consumer has access to the methods of the EventList interface. If you need access to
methods of the implementation class, consider the helper methods in the Guard class
instead.
consumer - the consumer != nullGuard.acceptWithReadLock(EventList, Consumer)default void acceptWithWriteLock(java.util.function.Consumer<EventList<E>> consumer)
The consumer has access to the methods of the EventList interface. If you need access to
methods of the implementation class, consider the helper methods in the Guard class
instead.
consumer - the consumer != nullGuard.acceptWithWriteLock(EventList, Consumer)default <R> R applyWithReadLock(java.util.function.Function<EventList<E>,R> function)
The function has access to the methods of the EventList interface. If you need access to
methods of the implementation class, consider the helper methods in the Guard class
instead.
R - the result type of the functionfunction - the function != nullGuard.applyWithReadLock(EventList, Function)default <R> R applyWithWriteLock(java.util.function.Function<EventList<E>,R> function)
The function has access to the methods of the EventList interface. If you need access to
methods of the implementation class, consider the helper methods in the Guard class
instead.
R - the result type of the functionfunction - the function != nullGuard.applyWithWriteLock(EventList, Function)Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by swimmesberger at Wed Feb 13 09:45:20 CET 2019