Interface ILcdCollection<T>
- All Superinterfaces:
Collection<T>,Iterable<T>
- All Known Subinterfaces:
ILcdList<T>
- All Known Implementing Classes:
TLcdArrayList,TLspGraphicsEffects
An extension of the Java Collection which fires a TLcdCollectionEvent for every element that is added to or removed
from the collection.
Due to those events, there is a decrease in performance compared to the traditional
Collection 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 collection 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 booleandefault booleanThis method behaves the same asadd(Object), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.default booleanaddAll(Collection<? extends T> aCollection) default booleanaddAll(Collection<? extends T> aCollection, int aEventMode) This method behaves the same asaddAll(Collection), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.voidaddCollectionListener(ILcdCollectionListener<T> aCollectionListener) Register the listeneraCollectionListenerto be informed about changes in this collection.default voidclear()default voidclear(int aEventMode) This method behaves the same asclear(), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.default voidFires all the collected change events from modifications performed with theILcdFireEventMode.FIRE_LATERfire event mode.default booleandefault booleanThis method behaves the same asremove(Object), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.default booleanremoveAll(Collection<?> aCollection) default booleanremoveAll(Collection<?> aCollection, int aEventMode) This method behaves the same asremoveAll(Collection), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.voidremoveCollectionListener(ILcdCollectionListener<T> aCollectionListener) Unregister the listeneraCollectionListenerso it will no longer be informed about changes in this collection.default booleanretainAll(Collection<?> aCollection) default booleanretainAll(Collection<?> aCollection, int aEventMode) This method behaves the same asretainAll(Collection), but additionally accepts anILcdFireEventModeparameter that allows to postpone firing change events resulting from this method call.Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeIf, size, spliterator, stream, toArray, 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(Collection, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callfireCollectedChanges()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>- See Also:
-
removeAll
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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been removed.removeAll(Collection, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callfireCollectedChanges()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>- See Also:
-
retainAll
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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been removed.retainAll(Collection, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callfireCollectedChanges()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>- See Also:
-
clear
default void clear()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, callCollectionone by one, and anTLcdCollectionEventfired each time an element has been removed.clear(int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callfireCollectedChanges()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>- See Also:
-
add
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, calladd(Object, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callfireCollectedChanges()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>- See Also:
-
remove
This method immediately fires change events to its registered change listeners. If this collection is protected by a read/write lock, callremove(Object, int)instead with theILcdFireEventMode.FIRE_LATERfire event mode, and subsequently callfireCollectedChanges()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>- See Also:
-
addAll
This method behaves the same asaddAll(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 oncefireCollectedChanges()is called. This is useful for example when the collection is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Parameters:
aCollection- collection containing elements to be added to this collection.aEventMode- theILcdFireEventModefor sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.1
- See Also:
-
removeAll
This method behaves the same asremoveAll(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 oncefireCollectedChanges()is called. This is useful for example when the collection is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Parameters:
aCollection- collection containing elements to be removed from this collection.aEventMode- theILcdFireEventModefor sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.1
- See Also:
-
retainAll
This method behaves the same asretainAll(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 oncefireCollectedChanges()is called. This is useful for example when the collection is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Parameters:
aCollection- collection containing elements to be retained in this collection.aEventMode- theILcdFireEventModefor sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.1
- See Also:
-
clear
default void clear(int aEventMode) This method behaves the same asclear(), 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 oncefireCollectedChanges()is called. This is useful for example when the collection is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Parameters:
aEventMode- theILcdFireEventModefor sending out the change event.- Since:
- 2024.1
- See Also:
-
add
This method behaves the same asadd(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 oncefireCollectedChanges()is called. This is useful for example when the collection is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Parameters:
aElement- element whose presence in this collection is to be ensured.aEventMode- theILcdFireEventModefor sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.1
- See Also:
-
remove
This method behaves the same asremove(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 oncefireCollectedChanges()is called. This is useful for example when the collection is protected by a read/write lock, in order to avoid potential deadlocks down the line. See theclass javadocfor an example code snippet.- Parameters:
aElement- element to be removed from this collection, if present.aEventMode- theILcdFireEventModefor sending out the change event.- Returns:
- true if an element was removed as a result of this call
- Since:
- 2024.1
- See Also:
-
fireCollectedChanges
default void fireCollectedChanges()Fires all the collected change events from modifications performed with theILcdFireEventMode.FIRE_LATERfire event mode.- Since:
- 2024.1
-
addCollectionListener
Register the listener
aCollectionListenerto be informed about changes in this collection.- Parameters:
aCollectionListener- the listener- See Also:
-
removeCollectionListener
Unregister the listener
aCollectionListenerso it will no longer be informed about changes in this collection.This method should do nothing when
aCollectionListenerwas not registered previously.- Parameters:
aCollectionListener- the listener- See Also:
-