sdsu.util
Class List

java.lang.Object
  |
  +--sdsu.util.List
Direct Known Subclasses:
SortedList

public class List
extends java.lang.Object
implements OrderedCollection, Stringizable, java.io.Serializable

A List object is a vector that can convert itself to a string and "recreate" itself from that string. The original List object can contain any objects, but the recreated List object will only contain string representations of the original elements in the list. In a List object string representation (Losr) the list elements are separated by a separatorChar, which defaults to ',', but can be changed. If the string representation of a list element contains a special character it is quoted. Special characters include separatorChar, a comment character, and white space characters. See sdsu.util.TokenCharacters for default values. White space and comments can be added to a Losr for readability. Comments start with a comment character and continue upto and include the next '\n' character.

Version:
3.0.1 24 April 1998
Author:
Roger Whitney (whitney@cs.sdsu.edu), Mark Boyns
See Also:
Stringizer, SimpleTokenizer, TokenCharacters, Serialized Form

Constructor Summary
List()
          Create a new list
List(int initialSize)
          Create a list with initial given size
List(java.lang.Object[] list)
          Create a list initial items from a list
List(java.util.Vector initialElements)
          Create a list initial items from a list
 
Method Summary
 void addElement(double aDouble)
          Adds the specified double as the last element of the list.
 void addElement(int anInt)
          Adds the specified int as the last element of the list.
 void addElement(java.lang.Object obj)
           
 void addElements(java.lang.Object[] elementsToAdd)
          Adds the array to the end of the list.
 void addElements(java.util.Vector elementsToAdd)
          Adds the vector to the end of the list.
 int capacity()
           
 java.lang.Object clone()
           
 boolean contains(java.lang.Object obj)
           
 double doubleAt(int index)
          Returns the double at the specified index.
 java.lang.Object elementAt(int i)
           
 java.util.Enumeration elements()
           
 java.util.Enumeration elementsReversed()
          Returns an enumeration of the elements inrevese order.
 void ensureCapacity(int minCapacity)
           
 java.lang.Object firstElement()
           
 void fromString(java.lang.String listString)
          Converts a string to a list.
 LabeledData getMetaData()
          Returns name-valeu pair of data used to parse a string version of a LabeledData object
 int indexOf(java.lang.Object obj)
           
 int indexOf(java.lang.Object obj, int i)
           
 void insertElementAt(java.lang.Object obj, int i)
           
 int intAt(int index)
          Returns the int at the specified index.
 boolean isEmpty()
           
 java.lang.Object lastElement()
           
 int lastIndexOf(java.lang.Object obj)
           
 int lastIndexOf(java.lang.Object obj, int i)
           
 void load(java.io.InputStream in)
          Converts a string to a list.
 void load(java.io.Reader in)
          Converts a string to a list.
 void removeAllElements()
           
 boolean removeElement(java.lang.Object obj)
           
 void removeElementAt(int i)
           
 void replaceElements(java.lang.Object[] objs)
          Deprecated. This method will be come protected in a future release. It was designed for internal use only. It does not work with SortedList
 OrderedCollection reversed()
          Returns a list with elements in the reverse order from present list
 void save(java.io.OutputStream out, java.lang.String header)
          Writes ascii representation of List to Outputstream
 void setElementAt(java.lang.Object obj, int i)
           
 void setMetaData(LabeledData metaData)
          Set the current objects metadata to be that found in metaData string
 void setSeparatorChar(char separatorChar)
          Set character used to separate elements of list in String representation of List
 void setSize(int size)
           
 void setTokenCharacters(TokenCharacters newParseTable)
          Sets TokenCharacters used to convert List from/to strings/streams.
 OrderedCollection shuffled()
          Returns a list with elements from present list, but in random order.
 int size()
           
 java.lang.Object[] toArray()
          Converts the list to an array.
 java.lang.String toString()
          Converts the list to a string
 java.lang.String toString(java.lang.String header)
          Converts the list to a string with given header information.
 java.util.Vector toVector()
          Converts the list to a vector.
 void trimToSize()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

List

public List()
Create a new list

List

public List(int initialSize)
Create a list with initial given size

List

public List(java.util.Vector initialElements)
Create a list initial items from a list

List

public List(java.lang.Object[] list)
Create a list initial items from a list
Method Detail

fromString

public void fromString(java.lang.String listString)
                throws ConversionException
Converts a string to a list. Converts strings created by a a list or vector Items in string are separated by separatorChar
Specified by:
fromString in interface Stringizable

load

public void load(java.io.InputStream in)
          throws ConversionException
Converts a string to a list. Converts strings created by a list or vector. Items in string are separated by separatorChar

load

public void load(java.io.Reader in)
          throws ConversionException
Converts a string to a list. Converts strings created by a list or vector. Items in string are separated by separatorChar

toString

public java.lang.String toString()
Converts the list to a string
Specified by:
toString in interface Stringizable
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String header)
Converts the list to a string with given header information.
Specified by:
toString in interface Stringizable

toVector

public java.util.Vector toVector()
Converts the list to a vector.
Specified by:
toVector in interface OrderedCollection

toArray

public java.lang.Object[] toArray()
Converts the list to an array.
Specified by:
toArray in interface OrderedCollection

save

public void save(java.io.OutputStream out,
                 java.lang.String header)
Writes ascii representation of List to Outputstream

setSeparatorChar

public void setSeparatorChar(char separatorChar)
Set character used to separate elements of list in String representation of List

setTokenCharacters

public void setTokenCharacters(TokenCharacters newParseTable)
Sets TokenCharacters used to convert List from/to strings/streams. Current values for separatorChar override separator settings in TokenCharacters object.

setMetaData

public void setMetaData(LabeledData metaData)
Set the current objects metadata to be that found in metaData string
Specified by:
setMetaData in interface Stringizable
Throws:
java.io.IOException - If there is an error in parsing metaDataString

getMetaData

public LabeledData getMetaData()
Returns name-valeu pair of data used to parse a string version of a LabeledData object
Specified by:
getMetaData in interface Stringizable

elementsReversed

public final java.util.Enumeration elementsReversed()
Returns an enumeration of the elements inrevese order. That is starts at the back of the list and goes toward the front of the list.
Specified by:
elementsReversed in interface OrderedCollection

intAt

public final int intAt(int index)
Returns the int at the specified index.
Specified by:
intAt in interface OrderedCollection
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 final double doubleAt(int index)
Returns the double at the specified index.
Specified by:
doubleAt in interface OrderedCollection
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.

addElement

public final void addElement(int anInt)
Adds the specified int as the last element of the list.
Specified by:
addElement in interface OrderedCollection
Parameters:
anInt - the element to be added

addElement

public final void addElement(double aDouble)
Adds the specified double as the last element of the list.
Specified by:
addElement in interface OrderedCollection
Parameters:
aFloat - the element to be added

addElements

public void addElements(java.lang.Object[] elementsToAdd)
Adds the array to the end of the list.
Specified by:
addElements in interface OrderedCollection

addElements

public void addElements(java.util.Vector elementsToAdd)
Adds the vector to the end of the list.
Specified by:
addElements in interface OrderedCollection

reversed

public OrderedCollection reversed()
Returns a list with elements in the reverse order from present list
Specified by:
reversed in interface OrderedCollection

shuffled

public OrderedCollection shuffled()
Returns a list with elements from present list, but in random order.
Specified by:
shuffled in interface OrderedCollection

elements

public java.util.Enumeration elements()
Specified by:
elements in interface OrderedCollection

trimToSize

public void trimToSize()
Specified by:
trimToSize in interface OrderedCollection

ensureCapacity

public void ensureCapacity(int minCapacity)
Specified by:
ensureCapacity in interface OrderedCollection

setSize

public void setSize(int size)
Specified by:
setSize in interface OrderedCollection

capacity

public int capacity()
Specified by:
capacity in interface OrderedCollection

size

public int size()
Specified by:
size in interface OrderedCollection

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface OrderedCollection

contains

public boolean contains(java.lang.Object obj)
Specified by:
contains in interface OrderedCollection

indexOf

public int indexOf(java.lang.Object obj)
Specified by:
indexOf in interface OrderedCollection

indexOf

public int indexOf(java.lang.Object obj,
                   int i)
Specified by:
indexOf in interface OrderedCollection

lastIndexOf

public int lastIndexOf(java.lang.Object obj)
Specified by:
lastIndexOf in interface OrderedCollection

lastIndexOf

public int lastIndexOf(java.lang.Object obj,
                       int i)
Specified by:
lastIndexOf in interface OrderedCollection

elementAt

public java.lang.Object elementAt(int i)
Specified by:
elementAt in interface OrderedCollection

firstElement

public java.lang.Object firstElement()
Specified by:
firstElement in interface OrderedCollection

lastElement

public java.lang.Object lastElement()
Specified by:
lastElement in interface OrderedCollection

setElementAt

public void setElementAt(java.lang.Object obj,
                         int i)
Specified by:
setElementAt in interface OrderedCollection

removeElementAt

public void removeElementAt(int i)
Specified by:
removeElementAt in interface OrderedCollection

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int i)
Specified by:
insertElementAt in interface OrderedCollection

addElement

public void addElement(java.lang.Object obj)
Specified by:
addElement in interface OrderedCollection

removeElement

public boolean removeElement(java.lang.Object obj)
Specified by:
removeElement in interface OrderedCollection

removeAllElements

public void removeAllElements()
Specified by:
removeAllElements in interface OrderedCollection

replaceElements

public void replaceElements(java.lang.Object[] objs)
Deprecated. This method will be come protected in a future release. It was designed for internal use only. It does not work with SortedList

clone

public java.lang.Object clone()