E
- The type of elements in this list.public abstract class ObservableList<E> extends DelegateList<E>
DelegateList
that provides callback methods to observe the
retrieval, addition, and removal of elements, either due to direct method
invocation on the list instance itself, or via iterator()
,
listIterator()
, subList(int,int)
, and any other entrypoint
that facilitates access to the elements in this list, either for modification
or retrieval.Modifier and Type | Class and Description |
---|---|
protected class |
ObservableList.ObservableListIterator
A
CursorListIterator that delegates callback methods to the
defining ObservableList instance for the retrieval, addition, and
removal of elements. |
protected class |
ObservableList.ObservableSubList
An
ObservableList that delegates callback methods to the
parent ObservableList instance for the retrieval, addition, and
removal of elements. |
target
modCount
Modifier | Constructor and Description |
---|---|
|
ObservableList(List<E> list)
Creates a new
ObservableList with the specified target
List . |
protected |
ObservableList(List<E> list,
int fromIndex,
int toIndex)
Creates a new
ObservableList with the specified target list, and
from and to indexes to limit the scope of the target list. |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
void |
add(int index,
E element) |
boolean |
addAll(Collection<? extends E> c) |
boolean |
addAll(int index,
Collection<? extends E> c) |
protected void |
addFast(int index,
E element) |
protected void |
afterAdd(int index,
E element,
RuntimeException e)
Callback method that is invoked immediately after an element is added to
the enclosed
List . |
protected void |
afterGet(int index,
E element,
ListIterator<? super E> iterator,
RuntimeException e)
Callback method that is invoked immediately after an element is retrieved
from the enclosed
List . |
protected void |
afterRemove(Object element,
RuntimeException e)
Callback method that is invoked immediately after an element is removed
from the enclosed
List . |
protected void |
afterSet(int index,
E oldElement,
RuntimeException e)
Callback method that is invoked immediately after an element is set at an
index to the enclosed
List . |
protected boolean |
beforeAdd(int index,
E element)
Callback method that is invoked immediately before an element is added to
the enclosed
List . |
protected void |
beforeGet(int index,
ListIterator<E> iterator)
Callback method that is invoked immediately before an element is retrieved
from the enclosed
List . |
protected boolean |
beforeRemove(int index)
Callback method that is invoked immediately before an element is removed
from the enclosed
List . |
protected boolean |
beforeSet(int index,
E newElement)
Callback method that is invoked immediately before an element is set at an
index in the enclosed
List . |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object obj) |
void |
forEach(Consumer<? super E> action) |
E |
get(int index) |
protected E |
getFast(int index) |
int |
hashCode() |
int |
indexOf(Object o) |
Iterator<E> |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator<E> |
listIterator() |
ListIterator<E> |
listIterator(int index) |
protected ObservableList.ObservableListIterator |
newListIterator(ListIterator<? extends E> iterator)
Factory method that returns a new instance of an
ObservableList.ObservableListIterator for the specified ListIterator<E> . |
protected ObservableList.ObservableSubList |
newSubList(int fromIndex,
int toIndex)
Factory method that returns a new instance of an
ObservableList.ObservableSubList
for the specified fromIndex and toIndex . |
Stream<E> |
parallelStream() |
E |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
protected E |
removeFast(int index) |
boolean |
removeIf(Predicate<? super E> filter) |
void |
replaceAll(UnaryOperator<E> operator) |
boolean |
retainAll(Collection<?> c) |
E |
set(int index,
E element) |
int |
size() |
void |
sort(Comparator<? super E> c) |
Spliterator<E> |
spliterator() |
Stream<E> |
stream() |
ObservableList<E> |
subList(int fromIndex,
int toIndex) |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
isEmpty, superForEach, superParallelStream, superRemoveIf, superReplaceAll, superSort, superSpliterator, superStream
removeRange
public ObservableList(List<E> list)
ObservableList
with the specified target
List
.list
- The target List
.NullPointerException
- If list
is null.protected ObservableList(List<E> list, int fromIndex, int toIndex)
ObservableList
with the specified target list, and
from and to indexes to limit the scope of the target list.list
- The target List
object.fromIndex
- The starting index as the lower limit of the elements in
the target list, inclusive.toIndex
- The starting index as the upper limit of the elements in the
target list, exclusive.NullPointerException
- If list
is null.protected void beforeGet(int index, ListIterator<E> iterator)
List
.index
- The index of the element to be retrieved from the enclosed
List
.iterator
- The ListIterator
instance if the get is a result of
an iterator reference, otherwise null
.protected void afterGet(int index, E element, ListIterator<? super E> iterator, RuntimeException e)
List
.index
- The index of the element retrieved from the enclosed
List
.element
- The element retrieved from the enclosed List
.iterator
- The Iterator
instance if the get is a result of an
iterator reference, otherwise null
.e
- A RuntimeException
that occurred during the get operation,
or null
if no exception occurred.protected boolean beforeAdd(int index, E element)
List
.
Note: It is possible for index
to be -1
, in case the
add operation is executed from an Iterator
when a prior
Iterator.remove()
or ListIterator.add(Object)
or
ListIterator.set(Object)
has already been called.
index
- The index for the element to be added to the enclosed
List
.element
- The element to be added to the enclosed List
.true
, the subsequent add
operation will be performed; if this method returns false
,
the subsequent add operation will not be performed.protected void afterAdd(int index, E element, RuntimeException e)
List
.index
- The index of the element added to the enclosed List
.element
- The element to be added to the enclosed List
.e
- A RuntimeException
that occurred during the add operation,
or null
if no exception occurred.protected boolean beforeRemove(int index)
List
.
Note: It is possible for index
to be -1
, in case the
remove operation is executed from an Iterator
when a prior
Iterator.remove()
or ListIterator.add(Object)
or
ListIterator.set(Object)
has already been called.
index
- The index of the element to be removed from the enclosed
List
.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)
List
.element
- The element removed from the enclosed List
, or
attempted to be removed from the List
in case of a
RuntimeException
.e
- A RuntimeException
that occurred during the remove
operation, or null
if no exception occurred.protected boolean beforeSet(int index, E newElement)
List
.
Note: It is possible for index
to be -1
, in case the
set operation is executed from an Iterator
when a prior
Iterator.remove()
or ListIterator.add(Object)
or
ListIterator.set(Object)
has already been called.
index
- The index for the element to be set in the enclosed
List
.newElement
- The element to be set in the enclosed List
.true
, the subsequent set
operation will be performed; if this method returns false
,
the subsequent set operation will not be performed.protected void afterSet(int index, E oldElement, RuntimeException e)
List
.index
- The index of the element set in the enclosed List
.oldElement
- The old element at the index of the enclosed
List
.e
- A RuntimeException
that occurred during the set
operation, or null
if no exception occurred.protected void addFast(int index, E element)
public boolean add(E e)
The callback methods beforeAdd(int,Object)
and
afterAdd(int,Object,RuntimeException)
are called immediately
before and after the enclosed List
is modified for the addition of
the element. If beforeAdd(int,Object)
returns false
, the
element will not be added.
add
in interface Collection<E>
add
in interface List<E>
add
in class DelegateList<E>
public void add(int index, E element)
The callback methods beforeAdd(int,Object)
and
afterAdd(int,Object,RuntimeException)
are called immediately
before and after the enclosed List
is modified for the addition of
the element. If beforeAdd(int,Object)
returns false
, the
element will not be added.
public boolean addAll(Collection<? extends E> c)
The callback methods beforeAdd(int,Object)
and
afterAdd(int,Object,RuntimeException)
are called immediately
before and after the enclosed List
is modified for the addition of
each element in the specified Collection
. All elements for which
beforeAdd(int,Object)
returns false
will not be added to
this List
.
addAll
in interface Collection<E>
addAll
in interface List<E>
addAll
in class DelegateList<E>
public boolean addAll(int index, Collection<? extends E> c)
The callback methods beforeAdd(int,Object)
and
afterAdd(int,Object,RuntimeException)
are called immediately
before and after the enclosed List
is modified for the addition of
each element in the specified Collection
. All elements for which
beforeAdd(int,Object)
returns false
will not be added to
this List
.
public void clear()
The callback methods beforeRemove(int)
and
afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed List
is modified for the removal of each
element. All elements for which beforeRemove(int)
returns
false
will not be removed from this List
.
clear
in interface Collection<E>
clear
in interface List<E>
clear
in class DelegateList<E>
public boolean contains(Object o)
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
contains
in interface Collection<E>
contains
in interface List<E>
contains
in class DelegateList<E>
public boolean containsAll(Collection<?> c)
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
containsAll
in interface Collection<E>
containsAll
in interface List<E>
containsAll
in class DelegateList<E>
protected E getFast(int index)
public E get(int index)
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after the get operation on the enclosed List
.
public int indexOf(Object o)
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
public int lastIndexOf(Object o)
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
lastIndexOf
in interface List<E>
lastIndexOf
in class DelegateList<E>
public Iterator<E> iterator()
Calling Iterator.remove()
will delegate a callback to
beforeRemove(int)
and
afterRemove(Object,RuntimeException)
on this instance. All
elements for which beforeRemove(int)
returns false
will
not be removed from this List
.
public ListIterator<E> listIterator()
Calling ListIterator.remove()
will delegate a callback to
beforeRemove(int)
and
afterRemove(Object,RuntimeException)
on this instance. All
elements for which beforeRemove(int)
returns false
will
not be removed from this List
. Calling
ListIterator.set(Object)
will delegate a callback to
beforeSet(int,Object)
and
afterSet(int,Object,RuntimeException)
on this instance. All
elements for which beforeSet(int,Object)
returns false
will not be set in this List
. Calling
ListIterator.add(Object)
will delegate a callback to
beforeAdd(int,Object)
and
afterAdd(int,Object,RuntimeException)
on this instance. All
elements for which beforeAdd(int,Object)
returns false
will not be added to this List
.
listIterator
in interface List<E>
listIterator
in class DelegateList<E>
protected ObservableList.ObservableListIterator newListIterator(ListIterator<? extends E> iterator)
ObservableList.ObservableListIterator
for the specified ListIterator<E>
. This method is intended to be overridden by
subclasses in order to provide instances of the subclass.iterator
- The target ListIterator<E>
.ObservableList.ObservableListIterator
.public ListIterator<E> listIterator(int index)
Calling ListIterator.remove()
will delegate a callback to
beforeRemove(int)
and
afterRemove(Object,RuntimeException)
on this instance. All
elements for which beforeRemove(int)
returns false
will
not be removed from this List
. Calling
ListIterator.set(Object)
will delegate a callback to
beforeSet(int,Object)
and
afterSet(int,Object,RuntimeException)
on this instance. All
elements for which beforeSet(int,Object)
returns false
will not be set in this List
. Calling
ListIterator.add(Object)
will delegate a callback to
beforeAdd(int,Object)
and
afterAdd(int,Object,RuntimeException)
on this instance. All
elements for which beforeAdd(int,Object)
returns false
will not be added to this List
.
listIterator
in interface List<E>
listIterator
in class DelegateList<E>
protected E removeFast(int index)
public E remove(int index)
The callback methods beforeRemove(int)
and
afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed List
is modified for the removal of the
element. If beforeRemove(int)
returns false
, the element
will not be removed, and this method will return null
.
public boolean remove(Object o)
The callback methods beforeRemove(int)
and
afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed List
is modified. If
beforeRemove(int)
returns false
, the element will not be
removed.
remove
in interface Collection<E>
remove
in interface List<E>
remove
in class DelegateList<E>
public E set(int index, E element)
The callback methods beforeSet(int,Object)
and
afterSet(int,Object,RuntimeException)
are called immediately
before and after the enclosed List
is modified. If
beforeSet(int,Object)
returns false
, the element will not
be set, and this method will return null
.
public boolean removeAll(Collection<?> c)
The callback methods beforeRemove(int)
and
afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed List
is modified for the removal of each
element in the specified Collection
. All elements for which
beforeRemove(int)
returns false
will not be removed from
this List
.
removeAll
in interface Collection<E>
removeAll
in interface List<E>
removeAll
in class DelegateList<E>
Collection.removeAll(Collection)
public boolean removeIf(Predicate<? super E> filter)
The callback methods beforeRemove(int)
and
afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed List
is modified for the removal of each
element. All elements for which beforeRemove(int)
returns
false
will not be removed from this List
.
removeIf
in interface Collection<E>
removeIf
in class DelegateList<E>
public boolean retainAll(Collection<?> c)
The callback methods beforeRemove(int)
and
afterRemove(Object,RuntimeException)
are called immediately before
and after the enclosed List
is modified for the removal of each
element not in the specified Collection
. All elements for which
beforeRemove(int)
returns false
will not be removed from
this List
.
retainAll
in interface Collection<E>
retainAll
in interface List<E>
retainAll
in class DelegateList<E>
public void replaceAll(UnaryOperator<E> operator)
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is
retrieved.
The callback methods beforeSet(int,Object)
and
afterSet(int,Object,RuntimeException)
are called immediately
before and after the enclosed List
is modified. If
beforeSet(int,Object)
returns false
, the element will not
be set.
replaceAll
in interface List<E>
replaceAll
in class DelegateList<E>
public int size()
size
in interface Collection<E>
size
in interface List<E>
size
in class DelegateList<E>
protected ObservableList.ObservableSubList newSubList(int fromIndex, int toIndex)
ObservableList.ObservableSubList
for the specified fromIndex
and toIndex
. This method is
intended to be overridden by subclasses in order to provide instances of
the subclass.fromIndex
- The starting index as the lower limit of the elements in
the target list, inclusive.toIndex
- The starting index as the upper limit of the elements in the
target list, exclusive.ObservableList.ObservableSubList
.public ObservableList<E> subList(int fromIndex, int toIndex)
DelegateList
The class DelegateList
does not itself implement
#subList(int,int)
, so calling this method on an instance of a
subclass of DelegateList
that does not override this method will
result in a UnsupportedOperationException
.
public void sort(Comparator<? super E> c)
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
public Object[] toArray()
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in class DelegateList<E>
public <T> T[] toArray(T[] a)
The callback methods beforeGet(int,ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each member of the enclosed list is
referenced.
toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in class DelegateList<E>
public void forEach(Consumer<? super E> action)
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is retrieved.
public Spliterator<E> spliterator()
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is retrieved.
spliterator
in interface Iterable<E>
spliterator
in interface Collection<E>
spliterator
in interface List<E>
spliterator
in class DelegateList<E>
public Stream<E> stream()
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is retrieved.
stream
in interface Collection<E>
stream
in class DelegateList<E>
public Stream<E> parallelStream()
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is retrieved.
parallelStream
in interface Collection<E>
parallelStream
in class DelegateList<E>
public boolean equals(Object obj)
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is retrieved.
equals
in interface Collection<E>
equals
in interface List<E>
equals
in class DelegateList<E>
public int hashCode()
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is retrieved.
hashCode
in interface Collection<E>
hashCode
in interface List<E>
hashCode
in class DelegateList<E>
public String toString()
The callback methods beforeGet(int, ListIterator)
and
afterGet(int,Object,ListIterator,RuntimeException)
are called
immediately before and after each element of the enclosed list is retrieved.
toString
in class DelegateList<E>
Copyright © 2020 LibJ. All rights reserved.