Package evo.search.view.model
Class SortedListModel<E>
- java.lang.Object
-
- javax.swing.AbstractListModel<E>
-
- evo.search.view.model.SortedListModel<E>
-
- All Implemented Interfaces:
Serializable
,ListModel<E>
public class SortedListModel<E> extends AbstractListModel<E>
- Author:
- jotoh
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class javax.swing.AbstractListModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description SortedListModel(@NonNull Comparator<E> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addElement(E element)
Add an element to the list.E
getElementAt(int index)
int
getSize()
int
indexOf(E element)
Searches for the first occurrence ofelem
.void
remove(int index)
Removes the element at the given index.void
removeRange(int fromIndex, int toIndex)
Deletes the components at the specified range of indexes.void
sort()
Sort the list.-
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
-
-
-
-
Constructor Detail
-
SortedListModel
public SortedListModel(@NonNull @NonNull Comparator<E> comparator)
-
-
Method Detail
-
getSize
public int getSize()
-
getElementAt
public E getElementAt(int index)
-
addElement
public void addElement(E element)
Add an element to the list. Sorts the list.- Parameters:
element
- element to add
-
remove
public void remove(int index)
Removes the element at the given index.- Parameters:
index
- position to remove an element from
-
removeRange
public void removeRange(int fromIndex, int toIndex)
Deletes the components at the specified range of indexes. The removal is inclusive, so specifying a range of (1,5) removes the component at index 1 and the component at index 5, as well as all components in between.- Parameters:
fromIndex
- the index of the lower end of the rangetoIndex
- the index of the upper end of the range- Throws:
ArrayIndexOutOfBoundsException
- if the index was invalidIllegalArgumentException
- iffromIndex > toIndex
- See Also:
remove(int)
-
indexOf
public int indexOf(E element)
Searches for the first occurrence ofelem
.- Parameters:
element
- an object- Returns:
- the index of the first occurrence of the argument in this
list; returns
-1
if the object is not found - See Also:
Vector.indexOf(Object)
-
sort
public void sort()
Sort the list.
-
-