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 voiddefault voidThis method behaves the same asadd(int, Object), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.default booleandefault booleanaddAll(int aIndex, Collection<? extends T> aCollection) default booleanaddAll(int aIndex, Collection<? extends T> aCollection, int aEventMode) This method behaves the same asaddAll(int, Collection), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.default booleanaddAll(Collection<? extends T> aCollection) voidaddListListener(ILcdListListener<T> aListListener) Register the listeneraListListenerto be informed about changes in this list.default voidclear()default Tremove(int index) default Tremove(int aIndex, int aEventMode) This method behaves the same asremove(int), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.default booleandefault booleanremoveAll(Collection<?> aCollection) voidremoveListListener(ILcdListListener<T> aListListener) Unregister the listeneraListListenerso it will no longer be informed about changes in this collection.default booleanretainAll(Collection<?> aCollection) default Tdefault TThis method behaves the same asset(int, Object), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface com.luciad.util.collections.ILcdCollection
add, addAll, addCollectionListener, clear, fireCollectedChanges, remove, removeAll, removeCollectionListener, retainAllMethods 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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been added.addAll(int, Collection, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor 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_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor 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_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor 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_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor an example code snippet. -
addAll
This method behaves the same asaddAll(int, Collection), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATERis 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 javadocfor 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- theILcdFireEventModefor sending out the change event.- Returns:
- true if this list changed as a result of the call
- Since:
- 2024.1
- See Also:
-
set
This method behaves the same asset(int, Object), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATERis 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 javadocfor an example code snippet.- Parameters:
aIndex- index of the element to replace.aElement- element to be stored at the specified position.aEventMode- theILcdFireEventModefor sending out the change event.- Returns:
- the element previously at the specified position
- Since:
- 2024.1
- See Also:
-
add
This method behaves the same asadd(int, Object), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATERis 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 javadocfor an example code snippet.- Parameters:
aIndex- index at which the specified element is to be inserted.aElement- element to be inserted.aEventMode- theILcdFireEventModefor sending out the change event.- Since:
- 2024.1
- See Also:
-
remove
This method behaves the same asremove(int), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call. WhenILcdFireEventMode.FIRE_LATERis 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 javadocfor an example code snippet.- Parameters:
aIndex- the index of the element to be removed.aEventMode- theILcdFireEventModefor sending out the change event.- Returns:
- the element previously at the specified position
- Since:
- 2024.1
- See Also:
-
addListListener
Register the listener
aListListenerto be informed about changes in this list.- Parameters:
aListListener- the listener- See Also:
-
removeListListener
Unregister the listener
aListListenerso it will no longer be informed about changes in this collection.This method should do nothing when
aListListenerwas not registered previously.- Parameters:
aListListener- the listener- See Also:
-
addAll
Description copied from interface:ILcdCollectionThe 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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been added.ILcdCollection.addAll(Collection, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Specified by:
addAllin interfaceCollection<T>- Specified by:
addAllin interfaceILcdCollection<T>- Specified by:
addAllin interfaceList<T>- See Also:
-
removeAll
Description copied from interface:ILcdCollectionThe 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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been removed.ILcdCollection.removeAll(Collection, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Specified by:
removeAllin interfaceCollection<T>- Specified by:
removeAllin interfaceILcdCollection<T>- Specified by:
removeAllin interfaceList<T>- See Also:
-
retainAll
Description copied from interface:ILcdCollectionThe 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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been removed.ILcdCollection.retainAll(Collection, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Specified by:
retainAllin interfaceCollection<T>- Specified by:
retainAllin interfaceILcdCollection<T>- Specified by:
retainAllin interfaceList<T>- See Also:
-
add
Description copied from interface:ILcdCollectionThis 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_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceILcdCollection<T>- Specified by:
addin interfaceList<T>- See Also:
-
remove
Description copied from interface:ILcdCollectionThis 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_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Specified by:
removein interfaceCollection<T>- Specified by:
removein interfaceILcdCollection<T>- Specified by:
removein interfaceList<T>- See Also:
-
clear
default void clear()Description copied from interface:ILcdCollectionThe 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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been removed.ILcdCollection.clear(int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callILcdCollection.fireCollectedChanges()after the lock has been released. This can avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Specified by:
clearin interfaceCollection<T>- Specified by:
clearin interfaceILcdCollection<T>- Specified by:
clearin interfaceList<T>- See Also:
-