jds.collection
Class IndexedDeque

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

public class IndexedDeque
extends java.lang.Object
implements Indexed, Deque

IndexedDeque - Deque implemented in the fashion of a Vector; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
jds.Vector, Serialized Form

Constructor Summary
IndexedDeque()
           
 
Method Summary
 void addElementAt(java.lang.Object val, int index)
          add a new element into the collection, making collection one element larger
 void addFirst(java.lang.Object val)
          add a new value to front of the collection
 void addLast(java.lang.Object val)
          add a new value to end of the collection
 int capacity()
          capacity return the capacity of this structure
 java.lang.Object elementAt(int index)
          find value at specific index location
 java.util.Enumeration elements()
          Yields enumerator for collection
 void ensureCapacity(int newCapacity)
          ensure that buffer has sufficient capacity
 java.lang.Object getFirst()
          access the first value in collection
 java.lang.Object getLast()
          access the last value in 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 removeFirst()
          remove first value in collection
 void removeLast()
          remove last value in collection
 void setElementAt(java.lang.Object val, int index)
          set value at specific location
 void setSize(int newSize)
          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

IndexedDeque

public IndexedDeque()
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

elementAt

public java.lang.Object elementAt(int index)
find value at specific index location
Specified by:
elementAt in interface Indexed
Parameters:
index - 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 val,
                         int index)
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

setSize

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

capacity

public int capacity()
capacity return the capacity of this structure
Returns:
an integer indicating current capacity

ensureCapacity

public void ensureCapacity(int newCapacity)
ensure that buffer has sufficient capacity
Parameters:
newCapacity - proposed new capacity of buffer

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

getFirst

public java.lang.Object getFirst()
access the first value in collection
Returns:
element at front of collection
Throws:
java.util.NoSuchElementException - no matching value

getLast

public java.lang.Object getLast()
access the last value in collection
Returns:
element at top of collection
Throws:
java.util.NoSuchElementException - no matching value

addLast

public void addLast(java.lang.Object val)
add a new value to end of the collection
Parameters:
value - element to be inserted into collection

addFirst

public void addFirst(java.lang.Object val)
add a new value to front of the collection
Specified by:
addFirst in interface Deque
Parameters:
value - element to be inserted into collection

removeLast

public void removeLast()
remove last value in collection
Throws:
java.util.NoSuchElementException - no matching value

removeFirst

public void removeFirst()
remove first value in collection
Throws:
java.util.NoSuchElementException - no matching value