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 boolean
default boolean
This method behaves the same asadd(Object)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.default boolean
addAll
(Collection<? extends T> aCollection) default boolean
addAll
(Collection<? extends T> aCollection, int aEventMode) This method behaves the same asaddAll(Collection)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.void
addCollectionListener
(ILcdCollectionListener<T> aCollectionListener) Register the listeneraCollectionListener
to be informed about changes in this collection.default void
clear()
default void
clear
(int aEventMode) This method behaves the same asclear()
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.default void
Fires all the collected change events from modifications performed with theILcdFireEventMode.FIRE_LATER
fire event mode.default boolean
default boolean
This method behaves the same asremove(Object)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.default boolean
removeAll
(Collection<?> aCollection) default boolean
removeAll
(Collection<?> aCollection, int aEventMode) This method behaves the same asremoveAll(Collection)
, but additionally accepts anILcdFireEventMode
parameter that allows to postpone firing change events resulting from this method call.void
removeCollectionListener
(ILcdCollectionListener<T> aCollectionListener) Unregister the listeneraCollectionListener
so it will no longer be informed about changes in this collection.default boolean
retainAll
(Collection<?> aCollection) default boolean
retainAll
(Collection<?> aCollection, int aEventMode) This method behaves the same asretainAll(Collection)
, but additionally accepts anILcdFireEventMode
parameter 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, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been added.addAll(Collection, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callfireCollectedChanges()
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>
- 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, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been removed.removeAll(Collection, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callfireCollectedChanges()
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>
- 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, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been removed.retainAll(Collection, int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callfireCollectedChanges()
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>
- 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, callCollection
one by one, and anTLcdCollectionEvent
fired each time an element has been removed.clear(int)
instead with theILcdFireEventMode.FIRE_LATER
fire event mode, and subsequently callfireCollectedChanges()
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>
- 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_LATER
fire event mode, and subsequently callfireCollectedChanges()
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>
- 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_LATER
fire event mode, and subsequently callfireCollectedChanges()
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>
- See Also:
-
addAll
This method behaves the same asaddAll(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 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 javadoc
for an example code snippet.- Parameters:
aCollection
- collection containing elements to be added to this collection.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.0.04
- See Also:
-
removeAll
This method behaves the same asremoveAll(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 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 javadoc
for an example code snippet.- Parameters:
aCollection
- collection containing elements to be removed from this collection.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.0.04
- See Also:
-
retainAll
This method behaves the same asretainAll(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 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 javadoc
for an example code snippet.- Parameters:
aCollection
- collection containing elements to be retained in this collection.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.0.04
- See Also:
-
clear
default void clear(int aEventMode) This method behaves the same asclear()
, 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 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 javadoc
for an example code snippet.- Parameters:
aEventMode
- theILcdFireEventMode
for sending out the change event.- Since:
- 2024.0.04
- See Also:
-
add
This method behaves the same asadd(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 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 javadoc
for an example code snippet.- Parameters:
aElement
- element whose presence in this collection is to be ensured.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- true if this collection changed as a result of the call
- Since:
- 2024.0.04
- See Also:
-
remove
This method behaves the same asremove(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 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 javadoc
for an example code snippet.- Parameters:
aElement
- element to be removed from this collection, if present.aEventMode
- theILcdFireEventMode
for sending out the change event.- Returns:
- true if an element was removed as a result of this call
- Since:
- 2024.0.04
- See Also:
-
fireCollectedChanges
default void fireCollectedChanges()Fires all the collected change events from modifications performed with theILcdFireEventMode.FIRE_LATER
fire event mode.- Since:
- 2024.0.04
-
addCollectionListener
Register the listener
aCollectionListener
to be informed about changes in this collection.- Parameters:
aCollectionListener
- the listener- See Also:
-
removeCollectionListener
Unregister the listener
aCollectionListener
so it will no longer be informed about changes in this collection.This method should do nothing when
aCollectionListener
was not registered previously.- Parameters:
aCollectionListener
- the listener- See Also:
-