- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- javafx.collections.ObservableListBase<E>
-
- javafx.collections.ModifiableObservableListBase<E>
-
- Type Parameters:
E
- the type of the elements contained in the List
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
,Observable
,ObservableList<E>
public abstract class ModifiableObservableListBase<E> extends ObservableListBase<E>
Abstract class that serves as a base class forObservableList
implementations that are modifiable. To implement a modifiableObservableList
class, you just need to implement the following set of methods: and the notifications and built and fired automatically for you.Example of a simple
ObservableList
delegating to anotherList
would look like this:public class ArrayObservableList<E> extends ModifiableObservableList<E> { private final List<E> delegate = new ArrayList<>(); public E get(int index) { return delegate.get(index); } public int size() { return delegate.size(); } protected void doAdd(int index, E element) { delegate.add(index, element); } protected E doSet(int index, E element) { return delegate.set(index, element); } protected E doRemove(int index) { return delegate.remove(index); }
- Since:
- JavaFX 8.0
- See Also:
ObservableListBase
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ModifiableObservableListBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
Inserts the specified element at the specified position in this list (optional operation).boolean
addAll(int index, Collection<? extends E> c)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation).boolean
addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection (optional operation).protected abstract void
doAdd(int index, E element)
Adds theelement
to the List at the position ofindex
.protected abstract E
doRemove(int index)
Removes the element at position ofindex
.protected abstract E
doSet(int index, E element)
Sets theelement
in the List at the position ofindex
.abstract E
get(int index)
Returns the element at the specified position in this list.E
remove(int index)
Removes the element at the specified position in this list (optional operation).boolean
remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).boolean
removeAll(Collection<?> c)
Removes all of this collection's elements that are also contained in the specified collection (optional operation).protected void
removeRange(int fromIndex, int toIndex)
Removes from this list all of the elements whose index is betweenfromIndex
, inclusive, andtoIndex
, exclusive.boolean
retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).E
set(int index, E element)
Replaces the element at the specified position in this list with the specified element (optional operation).boolean
setAll(Collection<? extends E> col)
Clears the ObservableList and adds all elements from the collection.abstract int
size()
Returns the number of elements in this collection.List<E>
subList(int fromIndex, int toIndex)
Returns a view of the portion of this list between the specifiedfromIndex
, inclusive, andtoIndex
, exclusive.-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, toArray, toArray, toString
-
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
-
Methods inherited from interface java.util.List
add, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, of, of, of, of, of, of, of, of, of, of, of, of, replaceAll, sort, spliterator, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javafx.collections.ObservableList
filtered, sorted, sorted
-
Methods inherited from class javafx.collections.ObservableListBase
addAll, addListener, addListener, beginChange, endChange, fireChange, hasListeners, nextAdd, nextPermutation, nextRemove, nextRemove, nextReplace, nextSet, nextUpdate, remove, removeAll, removeListener, removeListener, retainAll, setAll
-
-
-
-
Method Detail
-
setAll
public boolean setAll(Collection<? extends E> col)
Description copied from interface:ObservableList
Clears the ObservableList and adds all elements from the collection.- Specified by:
setAll
in interfaceObservableList<E>
- Overrides:
setAll
in classObservableListBase<E>
- Parameters:
col
- the collection with elements that will be added to this observableArrayList- Returns:
- true (as specified by Collection.add(E))
-
addAll
public boolean addAll(Collection<? extends E> c)
Description copied from class:AbstractCollection
Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractCollection<E>
- Parameters:
c
- collection containing elements to be added to this collection- Returns:
true
if this collection changed as a result of the call- See Also:
AbstractCollection.add(Object)
-
addAll
public boolean addAll(int index, Collection<? extends E> c)
Description copied from class:AbstractList
Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
-
removeRange
protected void removeRange(int fromIndex, int toIndex)
Description copied from class:AbstractList
Removes from this list all of the elements whose index is betweenfromIndex
, inclusive, andtoIndex
, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by(toIndex - fromIndex)
elements. (IftoIndex==fromIndex
, this operation has no effect.)This method is called by the
clear
operation on this list and its subLists. Overriding this method to take advantage of the internals of the list implementation can substantially improve the performance of theclear
operation on this list and its subLists.- Overrides:
removeRange
in classAbstractList<E>
- Parameters:
fromIndex
- index of first element to be removedtoIndex
- index after last element to be removed
-
removeAll
public boolean removeAll(Collection<?> c)
Description copied from class:AbstractCollection
Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classAbstractCollection<E>
- Parameters:
c
- collection containing elements to be removed from this collection- Returns:
true
if this collection changed as a result of the call- See Also:
AbstractCollection.remove(Object)
,AbstractCollection.contains(Object)
-
retainAll
public boolean retainAll(Collection<?> c)
Description copied from class:AbstractCollection
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classAbstractCollection<E>
- Parameters:
c
- collection containing elements to be retained in this collection- Returns:
true
if this collection changed as a result of the call- See Also:
AbstractCollection.remove(Object)
,AbstractCollection.contains(Object)
-
add
public void add(int index, E element)
Description copied from class:AbstractList
Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
-
set
public E set(int index, E element)
Description copied from class:AbstractList
Replaces the element at the specified position in this list with the specified element (optional operation).
-
remove
public boolean remove(Object o)
Description copied from class:AbstractCollection
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an elemente
such thatObjects.equals(o, e)
, if this collection contains one or more such elements. Returnstrue
if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
- Parameters:
o
- element to be removed from this collection, if present- Returns:
true
if an element was removed as a result of this call
-
remove
public E remove(int index)
Description copied from class:AbstractList
Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
-
subList
public List<E> subList(int fromIndex, int toIndex)
Description copied from class:AbstractList
Returns a view of the portion of this list between the specifiedfromIndex
, inclusive, andtoIndex
, exclusive. (IffromIndex
andtoIndex
are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
Similar idioms may be constructed forlist.subList(from, to).clear();
indexOf
andlastIndexOf
, and all of the algorithms in theCollections
class can be applied to a subList.The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
-
get
public abstract E get(int index)
Description copied from class:AbstractList
Returns the element at the specified position in this list.
-
size
public abstract int size()
Description copied from interface:Collection
Returns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
- Returns:
- the number of elements in this collection
-
doAdd
protected abstract void doAdd(int index, E element)
Adds theelement
to the List at the position ofindex
.For the description of possible exceptions, please refer to the documentation of
AbstractList.add(java.lang.Object)
method.- Parameters:
index
- the position where to add the elementelement
- the element that will be added- Throws:
ClassCastException
- if the type of the specified element is incompatible with this listNullPointerException
- if the specified arguments contain one or more null elementsIllegalArgumentException
- if some property of this element prevents it from being added to this listIndexOutOfBoundsException
- if the index is out of range(index < 0 || index > size())
-
doSet
protected abstract E doSet(int index, E element)
Sets theelement
in the List at the position ofindex
.For the description of possible exceptions, please refer to the documentation of
set(int, java.lang.Object)
method.- Parameters:
index
- the position where to set the elementelement
- the element that will be set at the specified position- Returns:
- the old element at the specified position
- Throws:
ClassCastException
- if the type of the specified element is incompatible with this listNullPointerException
- if the specified arguments contain one or more null elementsIllegalArgumentException
- if some property of this element prevents it from being added to this listIndexOutOfBoundsException
- if the index is out of range(index < 0 || index >= size())
-
doRemove
protected abstract E doRemove(int index)
Removes the element at position ofindex
.- Parameters:
index
- the index of the removed element- Returns:
- the removed element
- Throws:
IndexOutOfBoundsException
- if the index is out of range(index < 0 || index >= size())
-
-