net.sourceforge.nite.util
Class SortedList

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by java.util.ArrayList
              extended by net.sourceforge.nite.util.SortedList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class SortedList
extends java.util.ArrayList

This class implements a sorted list. It is constructed with a comparator that can compare two objects and sort objects accordingly. When you add an object to the list, it is inserted in the correct place. Object that are equal according to the comparator, will be in the list in the order that they were added to this list. Add only objects that the comparator can compare.

See Also:
Serialized Form

Constructor Summary
SortedList(java.util.Comparator c)
          Constructs a new sorted list.
 
Method Summary
 void add(int index, java.lang.Object element)
          This method has no effect.
 boolean add(java.lang.Object o)
          Adds an object to the list.
 
Methods inherited from class java.util.ArrayList
addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

SortedList

public SortedList(java.util.Comparator c)

Constructs a new sorted list. The objects in the list will be sorted according to the specified comparator.

Parameters:
c - a comparator
Method Detail

add

public void add(int index,
                java.lang.Object element)

This method has no effect. It is not allowed to specify an index to insert an element as this might violate the sorting order of the objects in the list.

Specified by:
add in interface java.util.List
Overrides:
add in class java.util.ArrayList

add

public boolean add(java.lang.Object o)

Adds an object to the list. The object will be inserted in the correct place so that the objects in the list are sorted. When the list already contains objects that are equal according to the comparator, the new object will be inserted immediately after these other objects.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.ArrayList
Parameters:
o - the object to be added