Interface ILcdList<T>
- All Superinterfaces:
Collection<T>
,ILcdCollection<T>
,Iterable<T>
,List<T>
,SequencedCollection<T>
- All Known Implementing Classes:
TLcdArrayList
An extension of the Java List
which fires a TLcdCollectionEvent
and TLcdListEvent
for every element that is added to or removed from the list.
Due to those events, there is a decrease in performance compared to the traditional
List
when adding and/or removing multiple elements at once (e.g. addAll(java.util.Collection)
or removeAll(java.util.Collection)
). For every element
that is added or removed, those methods should fire an individual event. An example
implementation for such a method is:
public boolean addAll(Collection<? extends T> aCollection) {
boolean result = false;
for (T element : aCollection) {
result = add(element) || result;
}
return result;
}
ILcdFireEventMode
parameter.
This is useful for example when the list is protected by a read/write lock. In that case, the actual
modifications must be performed within the write lock, while the change events are only fired afterwards when the
lock has been released, in order to avoid potential deadlocks down the line. For example, as follows:
try (TLcdLockUtil.Lock writeLock = TLcdLockUtil.writeLock(collection)) {
collection.add(element, ILcdFireEventMode.FIRE_LATER);
} finally {
collection.fireCollectedChanges();
}
- Since:
- 9.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
default void
This method behaves the same asadd(int, Object)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.default boolean
default boolean
addAll
(int aIndex, Collection<? extends T> aCollection) default boolean
addAll
(int aIndex, Collection<? extends T> aCollection, int aEventMode) This method behaves the same asaddAll(int, Collection)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.default boolean
addAll
(Collection<? extends T> aCollection) void
addListListener
(ILcdListListener<T> aListListener) Register the listeneraListListener
to be informed about changes in this list.default void
clear()
default T
remove
(int index) default T
remove
(int aIndex, int aEventMode) This method behaves the same asremove(int)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.default boolean
default boolean
removeAll
(Collection<?> aCollection) void
removeListListener
(ILcdListListener<T> aListListener) Unregister the listeneraListListener
so it will no longer be informed about changes in this collection.default boolean
retainAll
(Collection<?> aCollection) default T
default T
This method behaves the same asset(int, Object)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface com.luciad.util.collections.ILcdCollection
add, addAll, addCollectionListener, clear, fireCollectedChanges, remove, removeAll, removeCollectionListener, retainAll
Methods inherited from interface java.util.List
addFirst, addLast, contains, containsAll, equals, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeFirst, removeLast, replaceAll, reversed, size, sort, spliterator, subList, toArray, toArray
-
Method Details
-
addAll
The elements should be added to the
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been added.addAll(int, Collection, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet. -
set
Replacing the element should be performed in two distinct steps. First the removal of the element (including an event) and afterwards the adding of the new element (including an event).
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callset(int, Object, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet. -
add
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, calladd(int, Object, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet. -
remove
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callremove(int, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet. -
addAll
This method behaves the same asaddAll(int, Collection)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATER
is passed, any change events are temporarily stored and only fired onceILcdCollection.fireCollectedChanges()
is called. This is useful for example when the list is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Parameters:
aIndex
- index at which to insert the first element from the specified collection.aCollection
- collection containing elements to be added to this list.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- true if this list changed as a result of the call
- Since:
- 2024.0.04
- See Also:
-
set
This method behaves the same asset(int, Object)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATER
is passed, any change events are temporarily stored and only fired onceILcdCollection.fireCollectedChanges()
is called. This is useful for example when the list is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Parameters:
aIndex
- index of the element to replace.aElement
- element to be stored at the specified position.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- the element previously at the specified position
- Since:
- 2024.0.04
- See Also:
-
add
This method behaves the same asadd(int, Object)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATER
is passed, any change events are temporarily stored and only fired onceILcdCollection.fireCollectedChanges()
is called. This is useful for example when the list is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Parameters:
aIndex
- index at which the specified element is to be inserted.aElement
- element to be inserted.aEventMode
- theILcdFireEventMode
for sending out the change event.- Since:
- 2024.0.04
- See Also:
-
remove
This method behaves the same asremove(int)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATER
is passed, any change events are temporarily stored and only fired onceILcdCollection.fireCollectedChanges()
is called. This is useful for example when the list is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Parameters:
aIndex
- the index of the element to be removed.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- the element previously at the specified position
- Since:
- 2024.0.04
- See Also:
-
addListListener
Register the listener
aListListener
to be informed about changes in this list.- Parameters:
aListListener
- the listener- See Also:
-
removeListListener
Unregister the listener
aListListener
so it will no longer be informed about changes in this collection.This method should do nothing when
aListListener
was not registered previously.- Parameters:
aListListener
- the listener- See Also:
-
addAll
Description copied from interface:ILcdCollection
The elements should be added to the
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been added.ILcdCollection.addAll(Collection, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Specified by:
addAll
in interfaceCollection<T>
- Specified by:
addAll
in interfaceILcdCollection<T>
- Specified by:
addAll
in interfaceList<T>
- See Also:
-
removeAll
Description copied from interface:ILcdCollection
The elements should be removed from the
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been removed.ILcdCollection.removeAll(Collection, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Specified by:
removeAll
in interfaceCollection<T>
- Specified by:
removeAll
in interfaceILcdCollection<T>
- Specified by:
removeAll
in interfaceList<T>
- See Also:
-
retainAll
Description copied from interface:ILcdCollection
The elements should be removed from the
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been removed.ILcdCollection.retainAll(Collection, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Specified by:
retainAll
in interfaceCollection<T>
- Specified by:
retainAll
in interfaceILcdCollection<T>
- Specified by:
retainAll
in interfaceList<T>
- See Also:
-
add
Description copied from interface:ILcdCollection
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callILcdCollection.add(Object, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceILcdCollection<T>
- Specified by:
add
in interfaceList<T>
- See Also:
-
remove
Description copied from interface:ILcdCollection
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callILcdCollection.remove(Object, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Specified by:
remove
in interfaceCollection<T>
- Specified by:
remove
in interfaceILcdCollection<T>
- Specified by:
remove
in interfaceList<T>
- See Also:
-
clear
default void clear()Description copied from interface:ILcdCollection
The elements should be removed from the
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been removed.ILcdCollection.clear(int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callILcdCollection.fireCollectedChanges()
after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadoc
for an example code snippet.- Specified by:
clear
in interfaceCollection<T>
- Specified by:
clear
in interfaceILcdCollection<T>
- Specified by:
clear
in interfaceList<T>
- See Also:
-