/**
 * A objects of values which can be indexed by integers from 0 to size()-1.  
 * Initially, a wrapper class for Java's built-in arrays, now partially
 * extended to support subarrays.
 * 
 * @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 = new Object[elements.length];
    for (int i = 0; i < elements.length; i++) {
      objects[i] = elements[i];
    }
  } // Array(Object[])

  /**
   * Build a new array which holds the Integers that correspond
   * to the values given in the array.
   */
  public Array(int[] values) {
    objects = new Object[values.length];
    for (int i = 0; i < values.length; i++) {
      objects[i] = new Integer(values[i]);
    } // for
  } // Array(int[])

  /**
   * Build a new subarray which holds the elements in positions
   * start .. finish of stuff.  Modifications to the subarray should
   * affect the original array and vice versa.
   */
  public Array(Array stuff, int start, int finish) {
    // STUB.  Write this.
  } // Array(stuff, start, finish)

  // +-----------+----------------------------------------------- 
  // | 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];
    objects[i] = objects[j];
    objects[j] = temp;
  } // swap(int,int)

} // class Array 

