E
- The type of elements in this collection.public abstract class ObservableCollection<E> extends DelegateCollection<E>
DelegateCollection
that provides callback methods to observe the
addition and removal of elements, either due to direct method invocation on
the collection instance itself, or via iterator()
,
spliterator()
, forEach(Consumer)
, and any other entrypoint
that facilitates modification of the elements in this list.Modifier and Type | Class and Description |
---|---|
protected class |
ObservableCollection.ObservableIterator
A
DelegateIterator that delegates callback methods to the parent
ObservableCollection instance for the retrieval and removal of
elements. |
target
Constructor and Description |
---|
ObservableCollection(Collection<E> collection) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
boolean |
addAll(Collection<? extends E> c) |
protected void |
afterAdd(E element,
RuntimeException e)
Callback method that is invoked immediately after an element is added to
the enclosed
Collection . |
protected E |
afterGet(E value,
RuntimeException e)
Callback method that is invoked immediately after a value is retrieved via
Iterator.next() . |
protected void |
afterRemove(Object element,
RuntimeException e)
Callback method that is invoked immediately after an element is removed
from the enclosed
Collection . |
protected boolean |
beforeAdd(E element)
Callback method that is invoked immediately before an element is added to
the enclosed
Collection . |
protected boolean |
beforeRemove(Object element)
Callback method that is invoked immediately before an element is removed
from the enclosed
Collection . |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object obj) |
void |
forEach(Consumer<? super E> action) |
int |
hashCode() |
Iterator<E> |
iterator()
Returns an iterator over the elements in this collection.
|
Stream<E> |
parallelStream() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
removeIf(Predicate<? super E> filter) |
boolean |
retainAll(Collection<?> c) |
Spliterator<E> |
spliterator() |
Stream<E> |
stream() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
isEmpty, size, superForEach, superParallelStream, superRemoveIf, superSpliterator, superStream
public ObservableCollection(Collection<E> collection)
protected E afterGet(E value, RuntimeException e)
Iterator.next()
.value
- The value desired to be returned by the
Iterator.next()
operation.e
- A RuntimeException
that occurred during the add
operation, or null
if no exception occurred.Iterator.next()
operation.protected boolean beforeAdd(E element)
Collection
.element
- The element to be added to the enclosed Collection
.true
, the subsequent add
operation will be performed; if this method returns false
,
the subsequent add operation will not be performed.protected void afterAdd(E element, RuntimeException e)
Collection
.element
- The element added to the enclosed Collection
.e
- A RuntimeException
that occurred during the add
operation, or null
if no exception occurred.protected boolean beforeRemove(Object element)
Collection
.element
- The element to be removed from the enclosed
Collection
.true
, the subsequent remove
operation will be performed; if this method returns false
,
the subsequent remove operation will not be performed.protected void afterRemove(Object element, RuntimeException e)
Collection
.element
- The element removed from the enclosed Collection
, or
attempted to be removed from the Collection
in case of a
RuntimeException
.e
- A RuntimeException
that occurred during the add operation,
or null
if no exception occurred.public Iterator<E> iterator()
Iterator.remove()
will delegate a callback to
beforeRemove(Object)
and
afterRemove(Object,RuntimeException)
on this instance. All
elements for which beforeRemove(Object)
returns false will not be
removed from this collection.iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in class DelegateCollection<E>
Iterator
over the elements in this collection.Collection.iterator()
public boolean contains(Object o)
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved to
be tested for equality.
contains
in interface Collection<E>
contains
in class DelegateCollection<E>
public boolean containsAll(Collection<?> c)
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved to
be tested for equality.
containsAll
in interface Collection<E>
containsAll
in class DelegateCollection<E>
public boolean add(E e)
The callback methods beforeAdd(Object)
and
afterAdd(Object, RuntimeException)
are called
immediately before and after the enclosed collection is modified. If
beforeAdd(Object)
returns false, the element will not be added.
add
in interface Collection<E>
add
in class DelegateCollection<E>
public boolean addAll(Collection<? extends E> c)
The callback methods beforeAdd(Object)
and
afterAdd(Object,RuntimeException)
are called immediately before
and after the enclosed collection is modified for the addition of each
element in the argument Collection. All elements for which
beforeAdd(Object)
returns false will not be added to this
collection.
addAll
in interface Collection<E>
addAll
in class DelegateCollection<E>
public boolean remove(Object o)
The callback methods beforeRemove(Object)
and
afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed collection is modified. If
beforeRemove(Object)
returns false, the element will not be
removed.
remove
in interface Collection<E>
remove
in class DelegateCollection<E>
public boolean removeAll(Collection<?> c)
The callback methods beforeRemove(Object)
and
afterRemove(Object,RuntimeException)
are called immediately
before and after the enclosed collection is modified for the removal of
each element in the argument Collection. All elements for which
beforeRemove(Object)
returns false will not be removed from this
collection.
removeAll
in interface Collection<E>
removeAll
in class DelegateCollection<E>
public boolean removeIf(Predicate<? super E> filter)
The callback methods beforeRemove(Object)
and
afterRemove(Object,RuntimeException)
are called immediately
before and after the enclosed collection is modified for the removal of
each element. If beforeRemove(Object)
returns false, the element
will not be removed.
removeIf
in interface Collection<E>
removeIf
in class DelegateCollection<E>
public boolean retainAll(Collection<?> c)
The callback methods beforeRemove(Object)
and
afterRemove(Object,RuntimeException)
are called immediately
before and after the enclosed collection is modified for the removal of
each element not in the argument Collection.
retainAll
in interface Collection<E>
retainAll
in class DelegateCollection<E>
public void clear()
The callback methods beforeRemove(Object)
and
afterRemove(Object,RuntimeException)
are called immediately
before and after the enclosed collection is modified for the removal of
each element.
clear
in interface Collection<E>
clear
in class DelegateCollection<E>
public Object[] toArray()
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
toArray
in interface Collection<E>
toArray
in class DelegateCollection<E>
public <T> T[] toArray(T[] a)
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
toArray
in interface Collection<E>
toArray
in class DelegateCollection<E>
public void forEach(Consumer<? super E> action)
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
public Spliterator<E> spliterator()
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
spliterator
in interface Iterable<E>
spliterator
in interface Collection<E>
spliterator
in class DelegateCollection<E>
public Stream<E> stream()
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
stream
in interface Collection<E>
stream
in class DelegateCollection<E>
public Stream<E> parallelStream()
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
parallelStream
in interface Collection<E>
parallelStream
in class DelegateCollection<E>
public boolean equals(Object obj)
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
equals
in interface Collection<E>
equals
in class DelegateCollection<E>
public int hashCode()
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
hashCode
in interface Collection<E>
hashCode
in class DelegateCollection<E>
public String toString()
The callback method afterGet(Object,RuntimeException)
is called
immediately after each element of the enclosed collection is retrieved.
toString
in class DelegateCollection<E>
Copyright © 2020 LibJ. All rights reserved.