Package net.sf.jstuff.core.collection
Class ObservableCollection<E,C extends Collection<E>>
java.lang.Object
net.sf.jstuff.core.collection.ObservableCollection<E,C>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,CollectionExt<E>,EventListenable<ObservableCollection.ChangeEvent<E>>
- Direct Known Subclasses:
ObservableList,ObservableSet
public class ObservableCollection<E,C extends Collection<E>>
extends Object
implements CollectionExt<E>, EventListenable<ObservableCollection.ChangeEvent<E>>
A
Collection wrapper that emits ObservableCollection.ChangeEvents when modified through this ObservableCollection.
Changes made directly to the underlying Collection instance are not observable and will not trigger events.
ObservableCollection.ChangeEvents may include index information if the underlying collection has a defined order:
- For collections with insertion order (e.g.
List,LinkedHashSet), added and removed items include their index. - For collections with stable iteration order (e.g.
SortedSet), only removed items include their index. - For unordered collections (e.g.
HashSet), indices are-1.
Listeners can subscribe to receive ObservableCollection.ChangeEvents describing the type of change and the affected items.
- Author:
- Sebastian Thomschke
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDescribes a change that occurred in anObservableCollection. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final EventDispatcher<ObservableCollection.ChangeEvent<E>>protected final booleanprotected final booleanprotected static final intprotected final C -
Constructor Summary
ConstructorsConstructorDescriptionObservableCollection(C coll) ObservableCollection(C coll, EventDispatcher<ObservableCollection.ChangeEvent<E>> dispatcher) -
Method Summary
Modifier and TypeMethodDescriptionbooleanintAdds all items to the collection accepted by the excludeintAdds all items to the collection accepted by the excludeintAdds all items to the collectionintAdds all items to the collection accepted by the excludebooleanaddAll(Collection<? extends E> itemsToAdd) intAdds all items to the collectionintAdds all items to the collection accepted by the excludevoidclear()protected List<ObservableCollection.ChangeEvent.ItemChange<E>>booleanbooleancontainsAll(Collection<?> c) booleanCompares thisObservableCollectionto another object.protected voidfire(ObservableCollection.ChangeEvent.Operation action, List<ObservableCollection.ChangeEvent.ItemChange<E>> changes) protected voidfire(ObservableCollection.ChangeEvent.Operation action, ObservableCollection.ChangeEvent.ItemChange<E> change) inthashCode()booleanisEmpty()iterator()booleanbooleanbooleanremoveAll(Collection<?> itemsToRemove) booleanprotected booleanremoveMatching(Predicate<? super E> shouldRemove, ObservableCollection.ChangeEvent.Operation action) booleanbooleanretainAll(Collection<?> itemsToKeep) intsize()booleansubscribe(EventListener<ObservableCollection.ChangeEvent<E>> listener) Object[]toArray()<T> T[]toArray(T[] a) toString()booleanunsubscribe(EventListener<ObservableCollection.ChangeEvent<E>> listener) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, spliterator, stream, toArrayMethods inherited from interface net.sf.jstuff.core.collection.ext.CollectionExt
containsIdentical, isNotEmpty, removeIfNotMethods inherited from interface net.sf.jstuff.core.event.EventListenable
subscribe
-
Field Details
-
UNKNOWN_INDEX
protected static final int UNKNOWN_INDEX- See Also:
-
events
-
wrapped
-
supportsInsertionIndex
protected final boolean supportsInsertionIndex -
supportsRemovalIndex
protected final boolean supportsRemovalIndex
-
-
Constructor Details
-
ObservableCollection
-
ObservableCollection
public ObservableCollection(C coll, EventDispatcher<ObservableCollection.ChangeEvent<E>> dispatcher)
-
-
Method Details
-
add
- Specified by:
addin interfaceCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>
-
addAll
Description copied from interface:CollectionExtAdds all items to the collection accepted by the exclude- Specified by:
addAllin interfaceCollectionExt<E>- Returns:
- number of items added
-
addAll
Description copied from interface:CollectionExtAdds all items to the collection accepted by the exclude- Specified by:
addAllin interfaceCollectionExt<E>- Returns:
- number of items added
-
addAll
Description copied from interface:CollectionExtAdds all items to the collection- Specified by:
addAllin interfaceCollectionExt<E>- Returns:
- number of items added
-
addAll
Description copied from interface:CollectionExtAdds all items to the collection accepted by the exclude- Specified by:
addAllin interfaceCollectionExt<E>- Returns:
- number of items added
-
addAll
Description copied from interface:CollectionExtAdds all items to the collection- Specified by:
addAllin interfaceCollectionExt<E>- Returns:
- number of items added
-
addAll
Description copied from interface:CollectionExtAdds all items to the collection accepted by the exclude- Specified by:
addAllin interfaceCollectionExt<E>- Returns:
- number of items added
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>
-
clearInternal
-
contains
- Specified by:
containsin interfaceCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>
-
equals
Compares thisObservableCollectionto another object.Returns
trueif:- The other object is the same instance.
- The other object is an
ObservableCollectionwith an equal underlying collection. - The other object is a
Collectionequal to the underlying collection.
- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject
-
fire
protected void fire(ObservableCollection.ChangeEvent.Operation action, ObservableCollection.ChangeEvent.ItemChange<E> change) -
fire
protected void fire(ObservableCollection.ChangeEvent.Operation action, List<ObservableCollection.ChangeEvent.ItemChange<E>> changes) -
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject- Returns:
- the hash code based on the wrapped collection
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>
-
iterator
-
remove
- Specified by:
removein interfaceCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>
-
removeAll
-
removeIf
- Specified by:
removeIfin interfaceCollection<E>
-
removeMatching
protected boolean removeMatching(Predicate<? super E> shouldRemove, ObservableCollection.ChangeEvent.Operation action) -
retainAll
- Specified by:
retainAllin interfaceCollection<E>
-
retainAll
-
size
public int size()- Specified by:
sizein interfaceCollection<E>
-
subscribe
- Specified by:
subscribein interfaceEventListenable<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>
-
toString
-
unsubscribe
- Specified by:
unsubscribein interfaceEventListenable<E>
-