/**
 * A objects of values which can be indexed by 
 * integers from 0 to size().  Basically, a wrapper
 * class for Java's built-in arrays.
 * 
 * @author Samuel A. Rebelsky
 * @version 1.0 of September 1999
 */
public class Array {
  // +--------+--------------------------------------------------
  // | Fields |
  // +--------+
 
  /** The elements of the objects. */
  public Object[] objects;

  // +--------------+-------------------------------------------- 
  // | Constructors |
  // +--------------+

  /** 
   * Build a new array which holds up to n elements. 
   * Initially, each element is null.
   */
  public Array(int n) {
    objects = new Object[n];
  } // Array(int)

  /**
   * Build a new array which holds the specified 
   * set of elements.
   */
  public Array(Object[] elements) {
    objects = elements;
    
  } // Array(Object[])
 
  // +-----------+----------------------------------------------- 
  // | Accessors |
  // +-----------+

  /**
   * Get the ith element of the array.
   *
   * @exception ArrayIndexOutOfBoundsException
   *   For the obvious reasons.
   */
public Object get(int i) {
    return objects[i];
} // get(int)

  /**
   * Get the number of elements in the array.
   */
  public int size() {
    return objects.length;
  } // size()

  // +-----------+----------------------------------------------- 
  // | Modifiers |
  // +-----------+

  /**
   * Set the ith element of the array.
   *
   * @exception ArrayIndexOutOfBoundsException
   *   For the obvious reasons.
   */
  public void set(int i, Object value) {
    objects[i] = value;
  } // set(int, Object)

  /**
   * Swap the ith and jth elements of the array.
   * Included because it's commonly used during sorting.
   */
  public void swap(int i, int j) {
    Object temp = objects[i];
    //System.out.println("Just switched " + i + " " + j); 
    objects[i] = objects[j];
    objects[j] = temp;
  } // swap(int,int)

} // class Array 
