Class LinkedListModel<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.AbstractSequentialList<E>
-
- java.util.LinkedList<E>
-
- com.jgoodies.common.collect.LinkedListModel<E>
-
- Type Parameters:
E
- the type of the list elements
- All Implemented Interfaces:
ObservableList<E>
,ObservableList2<E>
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Deque<E>
,java.util.List<E>
,java.util.Queue<E>
,javax.swing.ListModel
public final class LinkedListModel<E> extends java.util.LinkedList<E> implements ObservableList2<E>
AddsListModel
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:
ObservableList
,ArrayListModel
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
LinkedListModel.ReportingListIterator
A ListIterator that fires ListDataEvents if elements are added or removed.
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.event.EventListenerList
listenerList
Holds the registered ListDataListeners.private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description LinkedListModel()
Constructs an empty LinkedListModel.LinkedListModel(java.util.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E e)
boolean
addAll(int index, java.util.Collection<? extends E> c)
void
addFirst(E e)
void
addLast(E e)
void
addListDataListener(javax.swing.event.ListDataListener l)
void
clear()
void
fireContentsChanged(int index)
Notifies all registeredListDataListeners
that the element at the specified index has changed.void
fireContentsChanged(int index0, int index1)
Notifies all registeredListDataListeners
that the element at the specified index has changed.private void
fireIntervalAdded(int index0, int index1)
This method must be called after one or more elements are added to the model.private void
fireIntervalRemoved(int index0, int index1)
This method must be called after one or more elements are removed from the model.E
getElementAt(int index)
private javax.swing.event.EventListenerList
getEventListenerList()
Lazily initializes and returns the event listener list used to notify registered listeners.javax.swing.event.ListDataListener[]
getListDataListeners()
Returns an array of all the list data listeners registered on thisLinkedListModel
.int
getSize()
java.util.ListIterator<E>
listIterator(int index)
E
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation).E
removeFirst()
E
removeLast()
void
removeListDataListener(javax.swing.event.ListDataListener l)
protected void
removeRange(int fromIndex, int toIndex)
boolean
retainAll(java.util.Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).E
set(int index, E element)
-
Methods 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, toArray
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
listenerList
private javax.swing.event.EventListenerList listenerList
Holds the registered ListDataListeners. The list that holds these listeners is initialized lazily in#getEventListenerList
.
-
-
Constructor Detail
-
LinkedListModel
public LinkedListModel()
Constructs an empty LinkedListModel.
-
LinkedListModel
public LinkedListModel(java.util.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:
java.lang.NullPointerException
- ifc
isnull
-
-
Method Detail
-
add
public final void add(int index, E element)
-
add
public final boolean add(E e)
-
addAll
public final boolean addAll(int index, java.util.Collection<? extends E> c)
-
removeAll
public boolean removeAll(java.util.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 interfacejava.util.Collection<E>
- Specified by:
removeAll
in interfacejava.util.List<E>
- Overrides:
removeAll
in classjava.util.AbstractCollection<E>
- Parameters:
c
- elements to be removed from this collection.- Returns:
- true if this collection changed as a result of the call.
- Throws:
java.lang.UnsupportedOperationException
- if the removeAll method is not supported by this collection.java.lang.NullPointerException
- if the specified collection is null.- See Also:
remove(Object)
,LinkedList.contains(Object)
-
retainAll
public boolean retainAll(java.util.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 interfacejava.util.Collection<E>
- Specified by:
retainAll
in interfacejava.util.List<E>
- Overrides:
retainAll
in classjava.util.AbstractCollection<E>
- Parameters:
c
- elements to be retained in this collection.- Returns:
- true if this collection changed as a result of the call.
- Throws:
java.lang.UnsupportedOperationException
- if the retainAll method is not supported by this Collection.java.lang.NullPointerException
- if the specified collection is null.- See Also:
remove(Object)
,LinkedList.contains(Object)
-
addFirst
public final void addFirst(E e)
-
addLast
public final void addLast(E e)
-
clear
public final void clear()
-
remove
public final E remove(int index)
-
remove
public final boolean remove(java.lang.Object o)
-
removeFirst
public final E removeFirst()
-
removeLast
public final E removeLast()
-
removeRange
protected final void removeRange(int fromIndex, int toIndex)
- Overrides:
removeRange
in classjava.util.AbstractList<E>
-
listIterator
public final java.util.ListIterator<E> listIterator(int index)
-
addListDataListener
public final void addListDataListener(javax.swing.event.ListDataListener l)
- Specified by:
addListDataListener
in interfacejavax.swing.ListModel<E>
-
removeListDataListener
public final void removeListDataListener(javax.swing.event.ListDataListener l)
- Specified by:
removeListDataListener
in interfacejavax.swing.ListModel<E>
-
getElementAt
public final E getElementAt(int index)
- Specified by:
getElementAt
in interfacejavax.swing.ListModel<E>
-
getSize
public final int getSize()
- Specified by:
getSize
in interfacejavax.swing.ListModel<E>
-
fireContentsChanged
public final void fireContentsChanged(int index)
Description copied from interface:ObservableList2
Notifies all registeredListDataListeners
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 interfaceObservableList2<E>
- Parameters:
index
- the index of the element that has changed- See Also:
EventListenerList
-
fireContentsChanged
public final void fireContentsChanged(int index0, int index1)
Notifies all registeredListDataListeners
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 interfaceObservableList2<E>
- Parameters:
index0
- one end of the new intervalindex1
- the other end of the new interval- Since:
- 1.7
- See Also:
EventListenerList
-
getListDataListeners
public final javax.swing.event.ListDataListener[] getListDataListeners()
Returns an array of all the list data listeners registered on thisLinkedListModel
.- Returns:
- all of this model's
ListDataListener
s, or an empty array if no list data listeners are currently registered - See Also:
addListDataListener(ListDataListener)
,removeListDataListener(ListDataListener)
-
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:
EventListenerList
-
fireIntervalRemoved
private void fireIntervalRemoved(int index0, int index1)
This method must be called after one or more elements are removed from the model.index0
andindex1
are the end points of the interval that's been removed. Note thatindex0
need not be less than or equal toindex1
.- Parameters:
index0
- one end of the removed interval, includingindex0
index1
- the other end of the removed interval, includingindex1
- See Also:
EventListenerList
-
getEventListenerList
private javax.swing.event.EventListenerList getEventListenerList()
Lazily initializes and returns the event listener list used to notify registered listeners.- Returns:
- the event listener list used to notify listeners
-
-