jds.collection
Class SparseVector

java.lang.Object
  |
  +--jds.collection.SparseVector

public class SparseVector
extends java.lang.Object
implements Indexed

SparseVector - sparse collection with elements accessible via index; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
Collection, Serialized Form

Constructor Summary
SparseVector()
          initialize a newly created sparse vector
SparseVector(java.lang.Object d)
          initialize a newly created sparse vector
 
Method Summary
 void addElementAt(java.lang.Object val, int index)
          add a new element into the collection, making collection one element larger
 java.lang.Object elementAt(int indx)
          find value at specific index location
 java.util.Enumeration elements()
          Yields enumerator for collection
 boolean isEmpty()
          Determines whether the collection is empty
 void removeElementAt(int index)
          remove a value from a collection, making collection one element smaller
 void setElementAt(java.lang.Object v, int indx)
          set value at specific location
 void setSize(int size)
          set number of elements in collection
 int size()
          Determines number of elements in collection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SparseVector

public SparseVector()
initialize a newly created sparse vector

SparseVector

public SparseVector(java.lang.Object d)
initialize a newly created sparse vector
Parameters:
d - default value to return for unassigned index positions
Method Detail

isEmpty

public boolean isEmpty()
Determines whether the collection is empty
Returns:
true if the collection is empty

size

public int size()
Determines number of elements in collection
Returns:
number of elements in collection as integer

elements

public java.util.Enumeration elements()
Yields enumerator for collection
Returns:
an Enumeration that will yield the elements of the collection
See Also:
Enumeration

setSize

public void setSize(int size)
set number of elements in collection
Specified by:
setSize in interface Indexed
Parameters:
size - the new size of the collection

elementAt

public java.lang.Object elementAt(int indx)
find value at specific index location
Specified by:
elementAt in interface Indexed
Parameters:
indx - the index of the desired value
Returns:
the desired value
Throws:
java.lang.ArrayIndexOutOfBoundsException - array index is illegal

setElementAt

public void setElementAt(java.lang.Object v,
                         int indx)
set value at specific location
Specified by:
setElementAt in interface Indexed
Parameters:
v - the value to be inserted
index - the position at which value will be inserted
Throws:
java.lang.ArrayIndexOutOfBoundsException - array index is illegal

addElementAt

public void addElementAt(java.lang.Object val,
                         int index)
add a new element into the collection, making collection one element larger
Specified by:
addElementAt in interface Indexed
Parameters:
val - the value to be inserted
index - the position at which value will be inserted, other elements will be moved upwards

removeElementAt

public void removeElementAt(int index)
remove a value from a collection, making collection one element smaller
Specified by:
removeElementAt in interface Indexed
Parameters:
index - the index of the element to be removed
Throws:
java.util.NoSuchElementException - array index is illegal