datastructures

net.datastructures
Class ArrayVector

java.lang.Object
  extended bynet.datastructures.ArrayVector
All Implemented Interfaces:
Vector

public class ArrayVector
extends Object
implements Vector

Realization of a vector by means of an array. The array has initial length 16 and is doubled when the size of the vector exceeds the capacity of the array. No shrinking of the array is performed.

Author:
Roberto Tamassia

Constructor Summary
ArrayVector()
          Creates the vector with initial capacity 16.
 
Method Summary
protected  void checkRank(int r, int n)
          Checks whether the given rank is in the range [0, n - 1]
 Object elemAtRank(int r)
          Returns the element stored at the given rank.
 void insertAtRank(int r, Object e)
          Inserts an element at the given rank.
 boolean isEmpty()
          Returns whether the vector is empty.
 Object removeAtRank(int r)
          Removes the element stored at the given rank.
 Object replaceAtRank(int r, Object e)
          Replaces the element stored at the given rank.
 int size()
          Returns the number of elements in the vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayVector

public ArrayVector()
Creates the vector with initial capacity 16.

Method Detail

size

public int size()
Returns the number of elements in the vector.

Specified by:
size in interface Vector

isEmpty

public boolean isEmpty()
Returns whether the vector is empty.

Specified by:
isEmpty in interface Vector

elemAtRank

public Object elemAtRank(int r)
                  throws BoundaryViolationException
Returns the element stored at the given rank.

Specified by:
elemAtRank in interface Vector
Parameters:
r - Rank to query
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size() - 1

replaceAtRank

public Object replaceAtRank(int r,
                            Object e)
                     throws BoundaryViolationException
Replaces the element stored at the given rank.

Specified by:
replaceAtRank in interface Vector
Parameters:
r - Rank at which to replace
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size() - 1

insertAtRank

public void insertAtRank(int r,
                         Object e)
                  throws BoundaryViolationException
Inserts an element at the given rank.

Specified by:
insertAtRank in interface Vector
Parameters:
r - Rank at which to replace
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size()

removeAtRank

public Object removeAtRank(int r)
                    throws BoundaryViolationException
Removes the element stored at the given rank.

Specified by:
removeAtRank in interface Vector
Parameters:
r - Rank at which to replace
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size() - 1

checkRank

protected void checkRank(int r,
                         int n)
                  throws BoundaryViolationException
Checks whether the given rank is in the range [0, n - 1]

Throws:
BoundaryViolationException

datastructures