sdsu.util
Interface OrderedCollection

All Known Subinterfaces:
SortedCollection
All Known Implementing Classes:
List

public abstract interface OrderedCollection
extends java.lang.Cloneable

An OrderedCollection is a collection of objects where the objects have a location in the collection. The objects can be accessed by their location ( or index) in the collection. The first object is in location (index) 0 (zero).

Version:
1.0 6 June 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)

Method Summary
 void addElement(double aDouble)
          Adds the specified double as the last element of the OrderedCollection.
 void addElement(int anInt)
          Adds the specified int as the last element of the OrderedCollection.
 void addElement(java.lang.Object obj)
          Adds the specified object as the last element of the OrderedCollection.
 void addElements(java.lang.Object[] elementsToAdd)
          Adds the elements of an array to the end of the collection.
 void addElements(java.util.Vector elementsToAdd)
          Adds the elements of a Vector to the end of the collection.
 int capacity()
          Returns the current capacity of the OrderedCollection.
 boolean contains(java.lang.Object elem)
          Returns true if the specified object is a value of the collection.
 double doubleAt(int index)
          Returns the double at the specified index.
 java.lang.Object elementAt(int index)
          Returns the element at the specified index.
 java.util.Enumeration elements()
          Returns an enumeration of the elements.
 java.util.Enumeration elementsReversed()
          Returns an enumeration of the elements inrevese order.
 void ensureCapacity(int minCapacity)
          Ensures that the OrderedCollection has at least the specified capacity.
 java.lang.Object firstElement()
          Returns the first element of the sequence.
 int indexOf(java.lang.Object elem)
          Searches for the specified object, starting from the first position and returns an index to it.
 int indexOf(java.lang.Object elem, int index)
          Searches for the specified object, starting at the specified position and returns an index to it.
 void insertElementAt(java.lang.Object obj, int index)
          Inserts the specified object as an element at the specified index.
 int intAt(int index)
          Returns the int at the specified index.
 boolean isEmpty()
          Returns true if the collection contains no values.
 java.lang.Object lastElement()
          Returns the last element of the sequence.
 int lastIndexOf(java.lang.Object elem)
          Searches backwards for the specified object, starting from the last position and returns an index to it.
 int lastIndexOf(java.lang.Object elem, int index)
          Searches backwards for the specified object, starting from the specified position and returns an index to it.
 void removeAllElements()
          Removes all elements of the OrderedCollection.
 boolean removeElement(java.lang.Object obj)
          Removes the element from the OrderedCollection.
 void removeElementAt(int index)
          Deletes the element at the specified index.
 OrderedCollection reversed()
          Returns a OrderedCollection with elements in the reverse order from present OrderedCollection
 void setElementAt(java.lang.Object obj, int index)
          Sets the element at the specified index to be the specified object.
 void setSize(int newSize)
          Sets the size of the OrderedCollection.
 OrderedCollection shuffled()
          Returns a OrderedCollection with elements from present OrderedCollection, but in random order.
 int size()
          Returns the number of elements in the OrderedCollection.
 java.lang.Object[] toArray()
          Converts the OrderedCollection to an array.
 java.util.Vector toVector()
          Converts the OrderedCollection to a vector.
 void trimToSize()
          Trims the OrderedCollection's capacity down to size.
 

Method Detail

toVector

public java.util.Vector toVector()
Converts the OrderedCollection to a vector.

toArray

public java.lang.Object[] toArray()
Converts the OrderedCollection to an array.

trimToSize

public void trimToSize()
Trims the OrderedCollection's capacity down to size. Use this operation to minimize the storage of a OrderedCollection. Subsequent insertions will cause reallocation.

ensureCapacity

public void ensureCapacity(int minCapacity)
Ensures that the OrderedCollection has at least the specified capacity.
Parameters:
minCapacity - the desired minimum capacity

setSize

public void setSize(int newSize)
Sets the size of the OrderedCollection. If the size shrinks, the extra elements are lost; if the size increases, the new elements are set to null.
Parameters:
newSize - the new size of the OrderedCollection

capacity

public int capacity()
Returns the current capacity of the OrderedCollection.

size

public int size()
Returns the number of elements in the OrderedCollection. Note that this is not the same as the OrderedCollection's capacity.

isEmpty

public boolean isEmpty()
Returns true if the collection contains no values.

elements

public java.util.Enumeration elements()
Returns an enumeration of the elements. Use the Enumeration methods on the returned object to fetch the elements sequentially.

elementsReversed

public java.util.Enumeration elementsReversed()
Returns an enumeration of the elements inrevese order. That is starts at the back of the OrderedCollection and goes toward the front of the OrderedCollection.

contains

public boolean contains(java.lang.Object elem)
Returns true if the specified object is a value of the collection.
Parameters:
elem - the desired element

indexOf

public int indexOf(java.lang.Object elem)
Searches for the specified object, starting from the first position and returns an index to it.
Parameters:
elem - the desired element
Returns:
the index of the element, or -1 if it was not found.

indexOf

public int indexOf(java.lang.Object elem,
                   int index)
Searches for the specified object, starting at the specified position and returns an index to it.
Parameters:
elem - the desired element
index - the index where to start searching
Returns:
the index of the element, or -1 if it was not found.

lastIndexOf

public int lastIndexOf(java.lang.Object elem)
Searches backwards for the specified object, starting from the last position and returns an index to it.
Parameters:
elem - the desired element
Returns:
the index of the element, or -1 if it was not found.

lastIndexOf

public int lastIndexOf(java.lang.Object elem,
                       int index)
Searches backwards for the specified object, starting from the specified position and returns an index to it.
Parameters:
elem - the desired element
index - the index where to start searching
Returns:
the index of the element, or -1 if it was not found.

elementAt

public java.lang.Object elementAt(int index)
Returns the element at the specified index.
Parameters:
index - the index of the desired element
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.

intAt

public int intAt(int index)
Returns the int at the specified index.
Parameters:
index - the index of the desired element
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.
java.lang.ClassCastException - If element at index is not really a numeric type which can be converted to an int.

doubleAt

public double doubleAt(int index)
Returns the double at the specified index.
Parameters:
index - the index of the desired element
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.
java.lang.ClassCastException - If element at index is not really a numeric type which can be converted to a double.

firstElement

public java.lang.Object firstElement()
Returns the first element of the sequence.
Throws:
NoSuchElementException - If the sequence is empty.

lastElement

public java.lang.Object lastElement()
Returns the last element of the sequence.
Throws:
NoSuchElementException - If the sequence is empty.

setElementAt

public void setElementAt(java.lang.Object obj,
                         int index)
Sets the element at the specified index to be the specified object. The previous element at that position is discarded.
Parameters:
obj - what the element is to be set to
index - the specified index
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the index was invalid.

removeElementAt

public void removeElementAt(int index)
Deletes the element at the specified index. Elements with an index greater than the current index are moved down.
Parameters:
index - the element to remove
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the index was invalid.

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
Inserts the specified object as an element at the specified index. Elements with an index greater or equal to the current index are shifted up.
Parameters:
obj - the element to insert
index - where to insert the new element
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the index was invalid.

addElement

public void addElement(java.lang.Object obj)
Adds the specified object as the last element of the OrderedCollection.
Parameters:
obj - the element to be added

addElement

public void addElement(int anInt)
Adds the specified int as the last element of the OrderedCollection.
Parameters:
anInt - the element to be added

addElement

public void addElement(double aDouble)
Adds the specified double as the last element of the OrderedCollection.
Parameters:
aFloat - the element to be added

addElements

public void addElements(java.util.Vector elementsToAdd)
Adds the elements of a Vector to the end of the collection.
Parameters:
elementsToAdd - the elements to be added

addElements

public void addElements(java.lang.Object[] elementsToAdd)
Adds the elements of an array to the end of the collection.
Parameters:
elementsToAdd - the elements to be added

removeElement

public boolean removeElement(java.lang.Object obj)
Removes the element from the OrderedCollection. If the object occurs more than once, only the first is removed. If the object is not an element, returns false.
Parameters:
obj - the element to be removed
Returns:
true if the element was actually removed; false otherwise.

removeAllElements

public void removeAllElements()
Removes all elements of the OrderedCollection. The OrderedCollection becomes empty.

reversed

public OrderedCollection reversed()
Returns a OrderedCollection with elements in the reverse order from present OrderedCollection

shuffled

public OrderedCollection shuffled()
Returns a OrderedCollection with elements from present OrderedCollection, but in random order.