jgnash.ui.components
Class SortedListModel<E extends java.lang.Comparable<? super E>>

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by jgnash.ui.components.SortedListModel<E>
All Implemented Interfaces:
java.io.Serializable, javax.swing.ListModel

public class SortedListModel<E extends java.lang.Comparable<? super E>>
extends javax.swing.AbstractListModel

A Sorted list model

Version:
$Id$
Author:
Craig Cavanaugh
See Also:
Serialized Form

Field Summary
private  java.util.List<E> list
           
private static long serialVersionUID
           
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
SortedListModel()
           
SortedListModel(java.util.Collection<E> list)
           
 
Method Summary
(package private)  void add(java.util.Collection<E> aList)
          Add a list of objects, does not fire a notification
 void addElement(E obj)
          Adds the specified component to the end of this list.
 java.util.List<E> asList()
          Returns a copy of the list
 void clear()
          Removes all of the elements from this list.
 boolean contains(E elem)
          Tests if the specified object is a component in this list.
 void fireContentsChanged()
          Resorts the list and fires a notification
 E get(int index)
           
 E getElementAt(int index)
          Returns the component at the specified index.
 int getSize()
          Returns the number of components in this list.
(package private)  int indexOf(java.lang.Object elem)
          Searches for the first occurrence of the given argument.
 java.lang.Object remove(int index)
          Removes the element at the specified position in this list.
 boolean removeElement(java.lang.Object obj)
          Removes the first (lowest-indexed) occurrence of the argument from this list.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this list in the correct order.
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

list

private final java.util.List<E extends java.lang.Comparable<? super E>> list
Constructor Detail

SortedListModel

public SortedListModel()

SortedListModel

public SortedListModel(java.util.Collection<E> list)
Method Detail

getSize

public int getSize()
Returns the number of components in this list.

This method is identical to size(), which implements the List interface defined in the 1.2 Collections framework. This method exists in conjunction with setSize() so that "size" is identifiable as a JavaBean property.

Returns:
the number of components in this list.
See Also:
ArrayList.size()

getElementAt

public E getElementAt(int index)
Returns the component at the specified index.
Note: Although this method is not deprecated, the preferred method to use is get(int), which implements the List interface defined in the 1.2 Collections framework.

Parameters:
index - an index into this list.
Returns:
the component at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is negative or not less than the current size of this list given.
See Also:
ArrayList.get(int)

get

public E get(int index)
Parameters:
index - index for the object
Returns:
object at the given index
See Also:
ArrayList.get(int)

add

void add(java.util.Collection<E> aList)
Add a list of objects, does not fire a notification

Parameters:
aList - collection of objects to add

contains

public boolean contains(E elem)
Tests if the specified object is a component in this list.

Parameters:
elem - an object.
Returns:
true if the specified object is the same as a component in this list
See Also:
Vector.contains(Object)

indexOf

int indexOf(java.lang.Object elem)
Searches for the first occurrence of the given argument.

Parameters:
elem - 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)

addElement

public void addElement(E obj)
Adds the specified component to the end of this list.

Parameters:
obj - the component to be added.
See Also:
Vector.addElement(Object)

removeElement

public boolean removeElement(java.lang.Object obj)
Removes the first (lowest-indexed) occurrence of the argument from this list.

Parameters:
obj - the component to be removed.
Returns:
true if the argument was a component of this list; false otherwise.
See Also:
ArrayList.remove(Object)

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this list in the correct order.

Throws an ArrayStoreException if the runtime type of the array a is not a supertype of the runtime type of every element in this list.

Returns:
an array containing the elements of the list.
See Also:
ArrayList.toArray()

asList

public java.util.List<E> asList()
Returns a copy of the list

Returns:
copy of the internal list

remove

public java.lang.Object remove(int index)
Removes the element at the specified position in this list. Returns the element that was removed from the list.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

Parameters:
index - the index of the element to removed.
Returns:
the object that was removed

clear

public void clear()
Removes all of the elements from this list. The list will be empty after this call returns (unless it throws an exception).


fireContentsChanged

public void fireContentsChanged()
Resorts the list and fires a notification