laser.util
Class BoundedArray

java.lang.Object
  extended by laser.util.BoundedArray

public class BoundedArray
extends java.lang.Object

Java only supports arrays with indices in the range from 0 to upperBound. This class implements a bounded array of objects with indices in the range from lowerBound to upperBound inclusive and length ( upperBound - lowerBound ) + 1. It can then set and get the object at a given index in the range from lowerBound to upperBound.

Version:
1.0 August 3, 1998
Author:
Heather Conboy ( hconboy@cs.umass.edu )

Constructor Summary
BoundedArray(int min, int max)
          Create a new bounded array with the given lower and upper bound.
 
Method Summary
 java.util.Set elements()
          Return the elements within the bounded array.
 java.lang.Object getItem(int index)
          Given an index in the range from lowerBound to upperBound, this returns the item at that index.
 int getLowerBound()
          Get the lower bound of the range of the bounded array.
 int getUpperBound()
          Get the upper bound of the range of the bounded array.
 int length()
          Get the length of the bounded array.
 void setItem(java.lang.Object item, int index)
          Set the object at the specified index in the range from lowerBound to upperBound to be the given item.
 java.lang.String toString()
          Return a string representation of the bounded array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoundedArray

public BoundedArray(int min,
                    int max)
Create a new bounded array with the given lower and upper bound. If (max - min) + 1 is less than zero, then a NegativeArraySizeException will be thrown.

Parameters:
min - the lower bound of the bounded array
max - the upper bound of the bounded array
Method Detail

getLowerBound

public int getLowerBound()
Get the lower bound of the range of the bounded array.

Returns:
The lower bound

getUpperBound

public int getUpperBound()
Get the upper bound of the range of the bounded array.

Returns:
The upper bound

length

public int length()
Get the length of the bounded array.

Returns:
The length of the bounded array

getItem

public java.lang.Object getItem(int index)
Given an index in the range from lowerBound to upperBound, this returns the item at that index. If the index is outside of the range lowerBound to upperBound then an ArrayIndexOutOfBoundsException will be thrown.

Parameters:
index - an int to use as an index into the bounded array
Returns:
the Object at index

setItem

public void setItem(java.lang.Object item,
                    int index)
Set the object at the specified index in the range from lowerBound to upperBound to be the given item. If the index is outside of the range lowerBound to upperBound then an ArrayIndexOutOfBoundsException will be thrown.

Parameters:
item - the object to add to the array
index - an int to use as an index into the bounded array

elements

public java.util.Set elements()
Return the elements within the bounded array.

Returns:
A set of the elements within the bounded array

toString

public java.lang.String toString()
Return a string representation of the bounded array.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the bounded array