Module javafx.base

Class 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 for ObservableList implementations that are modifiable. To implement a modifiable ObservableList 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 another List 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
    • Constructor Detail

      • ModifiableObservableListBase

        public ModifiableObservableListBase​()
    • 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 interface ObservableList<E>
        Overrides:
        setAll in class ObservableListBase<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 interface Collection<E>
        Specified by:
        addAll in interface List<E>
        Overrides:
        addAll in class AbstractCollection<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.)
        Specified by:
        addAll in interface List<E>
        Overrides:
        addAll in class AbstractList<E>
        Parameters:
        index - index at which to insert the first element from the specified collection
        c - collection containing elements to be added to this list
        Returns:
        true if this list changed as a result of the call
      • removeRange

        protected void removeRange​(int fromIndex,
                                   int toIndex)
        Description copied from class: AbstractList
        Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. (If toIndex==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 the clear operation on this list and its subLists.

        Overrides:
        removeRange in class AbstractList<E>
        Parameters:
        fromIndex - index of first element to be removed
        toIndex - index after last element to be removed
      • 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).
        Specified by:
        add in interface List<E>
        Overrides:
        add in class AbstractList<E>
        Parameters:
        index - index at which the specified element is to be inserted
        element - element to be inserted
      • 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).
        Specified by:
        set in interface List<E>
        Overrides:
        set in class AbstractList<E>
        Parameters:
        index - index of the element to replace
        element - element to be stored at the specified position
        Returns:
        the element previously at the specified position
      • 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 element e such that Objects.equals(o, e), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).
        Specified by:
        remove in interface Collection<E>
        Specified by:
        remove in interface List<E>
        Overrides:
        remove in class AbstractCollection<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.
        Specified by:
        remove in interface List<E>
        Overrides:
        remove in class AbstractList<E>
        Parameters:
        index - the index of the element to be removed
        Returns:
        the element previously at the specified position
      • 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 specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex 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:

        
              list.subList(from, to).clear();
         
        Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections 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.)

        Specified by:
        subList in interface List<E>
        Overrides:
        subList in class AbstractList<E>
        Parameters:
        fromIndex - low endpoint (inclusive) of the subList
        toIndex - high endpoint (exclusive) of the subList
        Returns:
        a view of the specified range within this list
      • get

        public abstract E get​(int index)
        Description copied from class: AbstractList
        Returns the element at the specified position in this list.
        Specified by:
        get in interface List<E>
        Specified by:
        get in class AbstractList<E>
        Parameters:
        index - index of the element to return
        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 than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in interface List<E>
        Specified by:
        size in class AbstractCollection<E>
        Returns:
        the number of elements in this collection
      • doAdd

        protected abstract void doAdd​(int index,
                                      E element)
        Adds the element to the List at the position of index.

        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 element
        element - the element that will be added
        Throws:
        ClassCastException - if the type of the specified element is incompatible with this list
        NullPointerException - if the specified arguments contain one or more null elements
        IllegalArgumentException - if some property of this element prevents it from being added to this list
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size())
      • doSet

        protected abstract E doSet​(int index,
                                   E element)
        Sets the element in the List at the position of index.

        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 element
        element - 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 list
        NullPointerException - if the specified arguments contain one or more null elements
        IllegalArgumentException - if some property of this element prevents it from being added to this list
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • doRemove

        protected abstract E doRemove​(int index)
        Removes the element at position of index.
        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())