Class LinkedListModel<E>

Type Parameters:
E - the type of the list elements
All Implemented Interfaces:
ObservableList<E>, ObservableList2<E>, Serializable, Cloneable, Iterable<E>, Collection<E>, Deque<E>, List<E>, Queue<E>, SequencedCollection<E>, ListModel

public final class LinkedListModel<E> extends LinkedList<E> implements ObservableList2<E>
Adds ListModel capabilities to its superclass. It allows to observe changes in the content and structure. Useful for Lists that are bound to list views such as JList, JComboBox and JTable.
See Also:
  • Field Details

  • Constructor Details

    • LinkedListModel

      public LinkedListModel()
      Constructs an empty LinkedListModel.
    • LinkedListModel

      public LinkedListModel(Collection<? extends E> c)
      Constructs a LinkedListModel containing the elements of the specified collection, in the order they are returned by the collection's iterator.
      Parameters:
      c - the collection whose elements are to be placed into this list.
      Throws:
      NullPointerException - if c is null
  • Method Details

    • add

      public final void add(int index, E element)
      Specified by:
      add in interface List<E>
      Overrides:
      add in class LinkedList<E>
    • add

      public final boolean add(E e)
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Deque<E>
      Specified by:
      add in interface List<E>
      Specified by:
      add in interface Queue<E>
      Overrides:
      add in class LinkedList<E>
    • addAll

      public final boolean addAll(int index, Collection<? extends E> c)
      Specified by:
      addAll in interface List<E>
      Overrides:
      addAll in class LinkedList<E>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Removes from this collection all of its elements that are contained in the specified collection (optional operation).

      This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.

      Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements in common with the specified collection.

      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface List<E>
      Overrides:
      removeAll in class AbstractCollection<E>
      Parameters:
      c - elements to be removed from this collection.
      Returns:
      true if this collection changed as a result of the call.
      Throws:
      UnsupportedOperationException - if the removeAll method is not supported by this collection.
      NullPointerException - if the specified collection is null.
      See Also:
    • retainAll

      public boolean retainAll(Collection<?> c)
      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.

      This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's not so contained, it's removed from this collection with the iterator's remove method.

      Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements not present in the specified collection.

      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface List<E>
      Overrides:
      retainAll in class AbstractCollection<E>
      Parameters:
      c - elements to be retained in this collection.
      Returns:
      true if this collection changed as a result of the call.
      Throws:
      UnsupportedOperationException - if the retainAll method is not supported by this Collection.
      NullPointerException - if the specified collection is null.
      See Also:
    • addFirst

      public final void addFirst(E e)
      Specified by:
      addFirst in interface Deque<E>
      Specified by:
      addFirst in interface List<E>
      Specified by:
      addFirst in interface SequencedCollection<E>
      Overrides:
      addFirst in class LinkedList<E>
    • addLast

      public final void addLast(E e)
      Specified by:
      addLast in interface Deque<E>
      Specified by:
      addLast in interface List<E>
      Specified by:
      addLast in interface SequencedCollection<E>
      Overrides:
      addLast in class LinkedList<E>
    • clear

      public final void clear()
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
      Overrides:
      clear in class LinkedList<E>
    • remove

      public final E remove(int index)
      Specified by:
      remove in interface List<E>
      Overrides:
      remove in class LinkedList<E>
    • remove

      public final boolean remove(Object o)
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface Deque<E>
      Specified by:
      remove in interface List<E>
      Overrides:
      remove in class LinkedList<E>
    • removeFirst

      public final E removeFirst()
      Specified by:
      removeFirst in interface Deque<E>
      Specified by:
      removeFirst in interface List<E>
      Specified by:
      removeFirst in interface SequencedCollection<E>
      Overrides:
      removeFirst in class LinkedList<E>
    • removeLast

      public final E removeLast()
      Specified by:
      removeLast in interface Deque<E>
      Specified by:
      removeLast in interface List<E>
      Specified by:
      removeLast in interface SequencedCollection<E>
      Overrides:
      removeLast in class LinkedList<E>
    • removeRange

      protected final void removeRange(int fromIndex, int toIndex)
      Overrides:
      removeRange in class AbstractList<E>
    • set

      public final E set(int index, E element)
      Specified by:
      set in interface List<E>
      Overrides:
      set in class LinkedList<E>
    • listIterator

      public final ListIterator<E> listIterator(int index)
      Specified by:
      listIterator in interface List<E>
      Overrides:
      listIterator in class LinkedList<E>
    • addListDataListener

      public final void addListDataListener(ListDataListener l)
      Specified by:
      addListDataListener in interface ListModel<E>
    • removeListDataListener

      public final void removeListDataListener(ListDataListener l)
      Specified by:
      removeListDataListener in interface ListModel<E>
    • getElementAt

      public final E getElementAt(int index)
      Specified by:
      getElementAt in interface ListModel<E>
    • getSize

      public final int getSize()
      Specified by:
      getSize in interface ListModel<E>
    • fireContentsChanged

      public final void fireContentsChanged(int index)
      Description copied from interface: ObservableList2
      Notifies all registered ListDataListeners that the element at the specified index has changed. Useful if there's a content change without any structural change.

      This method must be called after the element of the list changes.

      Specified by:
      fireContentsChanged in interface ObservableList2<E>
      Parameters:
      index - the index of the element that has changed
      See Also:
    • fireContentsChanged

      public final void fireContentsChanged(int index0, int index1)
      Notifies all registered ListDataListeners that the element at the specified index has changed. Useful if there's a content change without any structural change.

      This method must be called after one or more elements of the list change. The changed elements are specified by the closed interval index0, index1 -- the end points are included. Note that index0 need not be less than or equal to index1.

      Specified by:
      fireContentsChanged in interface ObservableList2<E>
      Parameters:
      index0 - one end of the new interval
      index1 - the other end of the new interval
      Since:
      1.7
      See Also:
    • getListDataListeners

      public final ListDataListener[] getListDataListeners()
      Returns an array of all the list data listeners registered on this LinkedListModel.
      Returns:
      all of this model's ListDataListeners, or an empty array if no list data listeners are currently registered
      See Also:
    • fireIntervalAdded

      private void fireIntervalAdded(int index0, int index1)
      This method must be called after one or more elements are added to the model. The new elements are specified by a closed interval index0, index1 -- the end points are included. Note that index0 need not be less than or equal to index1.
      Parameters:
      index0 - one end of the new interval
      index1 - the other end of the new interval
      See Also:
    • fireIntervalRemoved

      private void fireIntervalRemoved(int index0, int index1)
      This method must be called after one or more elements are removed from the model. index0 and index1 are the end points of the interval that's been removed. Note that index0 need not be less than or equal to index1.
      Parameters:
      index0 - one end of the removed interval, including index0
      index1 - the other end of the removed interval, including index1
      See Also:
    • getEventListenerList

      private EventListenerList getEventListenerList()
      Lazily initializes and returns the event listener list used to notify registered listeners.
      Returns:
      the event listener list used to notify listeners