org.garret.consus
Class POSortedList

java.lang.Object
  extended by org.garret.consus.Persistent
      extended by org.garret.consus.POCollection
          extended by org.garret.consus.POList
              extended by org.garret.consus.POSortedList
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.lang.Comparable, java.lang.Iterable, java.util.List

public class POSortedList
extends POList
implements java.lang.Comparable

Objects inserted into this list should implement the Comparable interface and be derived from the Persistent class. Alternatively you can specify the Comparator in the constructor. Nulls cannot be placed in the sorted list.


Field Summary
 
Fields inherited from class org.garret.consus.Persistent
db, oid, PO_DELETED, PO_LOADED, PO_NEW, PO_STUB, state, type
 
Constructor Summary
POSortedList()
          Constructs an empty list.
POSortedList(java.util.Collection c)
          Constructs a list containing the elements of the specified collection, in the order they are returned by the collections iterator.
POSortedList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
POSortedList(int initialCapacity, POComparator c)
          Constructs an empty list with the specified initial capacity.
POSortedList(POComparator c)
          Constructs an empty list and associates a comparator with the list.
 
Method Summary
 boolean add(java.lang.Object o)
          Appends the specified element to the end of this list.
 boolean addAll(java.util.Collection c)
          Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collections Iterator.
 int compareTo(java.lang.Object o)
          Compare two sorted lists
 int compareTo(POSortedList anotherList)
          Compare two ordered lists.
 int findInsertPosition(java.lang.Object elem)
          Find the position where the element should be inserted into the list using the compare method of Comparator or the compareTo method of the elements.
 int indexOf(java.lang.Object elem)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 int lastIndexOf(java.lang.Object elem)
          Returns the index of the last occurrence of the specified object in this list.
 
Methods inherited from class org.garret.consus.POList
add, addAll, clear, clone, contains, ensureCapacity, get, isEmpty, iterator, listIterator, listIterator, loadClosure, remove, removeRange, set, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class org.garret.consus.POCollection
containsAll, equals, hashCode, remove, removeAll, retainAll, toString
 
Methods inherited from class org.garret.consus.Persistent
assignOID, become, beginUpdate, endUpdate, get, get, getOid, getOid, getRef, getRef, isDeleted, isLoaded, isNew, load, loadComponents, lock, remove, save, store, store, unget
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, remove, removeAll, retainAll
 

Constructor Detail

POSortedList

public POSortedList()
Constructs an empty list.


POSortedList

public POSortedList(java.util.Collection c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collections iterator. The POList instance has an initial capacity of 110% of the size of the specified collection.


POSortedList

public POSortedList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.

POSortedList

public POSortedList(int initialCapacity,
                    POComparator c)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.
c - the comparator to be associated with the list

POSortedList

public POSortedList(POComparator c)
Constructs an empty list and associates a comparator with the list.

Method Detail

add

public boolean add(java.lang.Object o)
Appends the specified element to the end of this list.

Specified by:
add in interface java.util.List
Overrides:
add in class POList
Parameters:
o - element to be appended to this list.
Returns:
true (as per the general contract of Collection.add).

addAll

public boolean addAll(java.util.Collection c)
Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collections Iterator. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this list, and this list is nonempty.)

Specified by:
addAll in interface java.util.List
Overrides:
addAll in class POList
Parameters:
c - elements to be inserted into this list.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index > size()).
See Also:
POCollection.add(Object)

compareTo

public int compareTo(java.lang.Object o)
Compare two sorted lists

Specified by:
compareTo in interface java.lang.Comparable

compareTo

public int compareTo(POSortedList anotherList)
Compare two ordered lists. Comparision is made by sequential comparison of elements from each sorted list. If there is no index position at which they differ, then the shorter list lexicographically precedes the longer list. In this case, compareTo returns the difference of the lengths of the lists -- that is, the value:
 this.length()-anotherList.length()
 

Parameters:
anotherList - the POSortedList to be compared.
Returns:
the value 0 if all elements in the first list are equal to the elements in the corresponding position in the second list and that the lists have the same size; a value less than 0 is returned if the first element is not equal to the corresponding element in the second list, is smaller than the element from the second list or there is not such index position in the second list; a value greater than zero is returned otherwise.
Throws:
java.lang.NullPointerException - if anotherList is null.

findInsertPosition

public int findInsertPosition(java.lang.Object elem)
Find the position where the element should be inserted into the list using the compare method of Comparator or the compareTo method of the elements.

Parameters:
elem - an object.
Returns:
position after the last smaller element
See Also:
Object.equals(Object)

indexOf

public int indexOf(java.lang.Object elem)
Searches for the first occurence of the given argument, testing for equality using the equals method.

Specified by:
indexOf in interface java.util.List
Overrides:
indexOf in class POList
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:
Object.equals(Object)

lastIndexOf

public int lastIndexOf(java.lang.Object elem)
Returns the index of the last occurrence of the specified object in this list.

Specified by:
lastIndexOf in interface java.util.List
Overrides:
lastIndexOf in class POList
Parameters:
elem - the desired element.
Returns:
the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.