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>,ListModel
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classA ListIterator that fires ListDataEvents if elements are added or removed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate EventListenerListHolds the registered ListDataListeners.private static final longFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty LinkedListModel.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. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidfinal booleanfinal booleanaddAll(int index, Collection<? extends E> c) final voidfinal voidfinal voidfinal voidclear()final voidfireContentsChanged(int index) Notifies all registeredListDataListenersthat the element at the specified index has changed.final voidfireContentsChanged(int index0, int index1) Notifies all registeredListDataListenersthat the element at the specified index has changed.private voidfireIntervalAdded(int index0, int index1) This method must be called after one or more elements are added to the model.private voidfireIntervalRemoved(int index0, int index1) This method must be called after one or more elements are removed from the model.final EgetElementAt(int index) private EventListenerListLazily initializes and returns the event listener list used to notify registered listeners.final ListDataListener[]Returns an array of all the list data listeners registered on thisLinkedListModel.final intgetSize()final ListIterator<E>listIterator(int index) final Eremove(int index) final booleanbooleanremoveAll(Collection<?> c) Removes from this collection all of its elements that are contained in the specified collection (optional operation).final Efinal Efinal voidprotected final voidremoveRange(int fromIndex, int toIndex) booleanretainAll(Collection<?> c) Retains only the elements in this collection that are contained in the specified collection (optional operation).final EMethods inherited from class java.util.LinkedList
addAll, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, removeFirstOccurrence, removeLastOccurrence, size, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractSequentialList
iteratorMethods inherited from class java.util.AbstractList
equals, hashCode, listIterator, subListMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, replaceAll, size, sort, spliterator, subList, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
listenerList
Holds the registered ListDataListeners. The list that holds these listeners is initialized lazily in#getEventListenerList.
-
-
Constructor Details
-
LinkedListModel
public LinkedListModel()Constructs an empty LinkedListModel. -
LinkedListModel
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- ifcisnull
-
-
Method Details
-
add
-
add
-
addAll
-
removeAll
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:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractCollection<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
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:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Overrides:
retainAllin classAbstractCollection<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
-
addLast
-
clear
public final void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classLinkedList<E>
-
remove
-
remove
-
removeFirst
- Specified by:
removeFirstin interfaceDeque<E>- Overrides:
removeFirstin classLinkedList<E>
-
removeLast
- Specified by:
removeLastin interfaceDeque<E>- Overrides:
removeLastin classLinkedList<E>
-
removeRange
protected final void removeRange(int fromIndex, int toIndex) - Overrides:
removeRangein classAbstractList<E>
-
set
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classLinkedList<E>
-
addListDataListener
- Specified by:
addListDataListenerin interfaceListModel<E>
-
removeListDataListener
- Specified by:
removeListDataListenerin interfaceListModel<E>
-
getElementAt
- Specified by:
getElementAtin interfaceListModel<E>
-
getSize
public final int getSize() -
fireContentsChanged
public final void fireContentsChanged(int index) Description copied from interface:ObservableList2Notifies all registeredListDataListenersthat 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:
fireContentsChangedin interfaceObservableList2<E>- Parameters:
index- the index of the element that has changed- See Also:
-
fireContentsChanged
public final void fireContentsChanged(int index0, int index1) Notifies all registeredListDataListenersthat 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:
fireContentsChangedin interfaceObservableList2<E>- Parameters:
index0- one end of the new intervalindex1- the other end of the new interval- Since:
- 1.7
- See Also:
-
getListDataListeners
Returns an array of all the list data listeners registered on thisLinkedListModel.- 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 intervalindex1- 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.index0andindex1are the end points of the interval that's been removed. Note thatindex0need not be less than or equal toindex1.- Parameters:
index0- one end of the removed interval, includingindex0index1- the other end of the removed interval, includingindex1- See Also:
-
getEventListenerList
Lazily initializes and returns the event listener list used to notify registered listeners.- Returns:
- the event listener list used to notify listeners
-