edu.wisc.cs.util
Class SortedList

java.lang.Object
  |
  +--edu.wisc.cs.util.SortedList

public class SortedList
extends java.lang.Object

Implements a list object which supports order perserving insertions and duplicate elements. This class is implemented as a doubly linked list, so that inserts do not require shifting of array elements.


Constructor Summary
SortedList()
          Constructs a new SortedList with the default comparator which sorts in ascending order.
SortedList(boolean rev)
          Constructs a new SortedList with the default comparator which sorts in the specified order.
SortedList(java.util.Comparator c)
          Constructs a new SortedList with the specified comparator which sorts in ascending order.
SortedList(java.util.Comparator c, boolean rev)
          Constructs a new SortedList with the specified comparator which sorts in the specified order.
 
Method Summary
 void clear()
          Removes all of the elements in the list.
 void insert(java.lang.Object o)
          Adds an object to the sorted list in a position specified by the partial order imposed by a comparator.
 boolean isReversed()
          Returns true if the list is in reverse sorted order, false otherwise.
 PeekIterator iterator()
          Returns an iterator containing all of the elements in sorted order.
 int size()
          Returns the number of elemets in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedList

public SortedList()
Constructs a new SortedList with the default comparator which sorts in ascending order.

SortedList

public SortedList(boolean rev)
Constructs a new SortedList with the default comparator which sorts in the specified order.
Parameters:
rev - true to sort in reversed order, false for ascending order.

SortedList

public SortedList(java.util.Comparator c)
Constructs a new SortedList with the specified comparator which sorts in ascending order.
Parameters:
c - the comparator to use in item comparisons.

SortedList

public SortedList(java.util.Comparator c,
                  boolean rev)
Constructs a new SortedList with the specified comparator which sorts in the specified order.
Parameters:
c - the comparator to use in item comparisons.
rev - true to sort in reversed order, false for ascending order.
Method Detail

isReversed

public boolean isReversed()
Returns true if the list is in reverse sorted order, false otherwise.
Returns:
true if the list is in reverse sorted order, false otherwise.

iterator

public PeekIterator iterator()
Returns an iterator containing all of the elements in sorted order.
Returns:
an iterator containing all of the elements in sorted order.

size

public int size()
Returns the number of elemets in the list.
Returns:
the number of elemets in the list.

clear

public void clear()
Removes all of the elements in the list.

insert

public void insert(java.lang.Object o)
Adds an object to the sorted list in a position specified by the partial order imposed by a comparator. Duplicate elements are allowed.
Parameters:
o - an object to insert into the list.