home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / OSpace / jgl.exe / jgl_2_0 / src / COM / objectspace / jgl / ObjectArray.java < prev    next >
Encoding:
Java Source  |  1997-03-14  |  2.8 KB  |  128 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. // Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.
  3.  
  4. package COM.objectspace.jgl;
  5.  
  6. import java.util.Enumeration;
  7.  
  8. /**
  9.  * ObjectArray allows a native array of Objects to be accessed like a Container.
  10.  * It is particularly useful for applying generic algorithms like Sorting.sort()
  11.  * to a native array.
  12.  * <p>
  13.  * @version 2.0.2
  14.  * @author ObjectSpace, Inc.
  15.  */
  16.  
  17. public class ObjectArray extends ArrayAdapter
  18.   {
  19.   Object myArray[];
  20.  
  21.   public ObjectArray()
  22.     {
  23.     myArray = new Object[ 0 ];
  24.     }
  25.  
  26.   public ObjectArray( Object array[] )
  27.     {
  28.     synchronized( array )
  29.       {
  30.       myArray = array;
  31.       }
  32.     }
  33.  
  34.   public ObjectArray( ObjectArray array )
  35.     {
  36.     synchronized( array )
  37.       {
  38.       myArray = array.myArray;
  39.       }
  40.     }
  41.  
  42.   /**
  43.    * Return a shallow copy of myself.
  44.    */
  45.   public synchronized Object clone()
  46.     {
  47.     return new ObjectArray( this );
  48.     }
  49.  
  50.   /**
  51.    * Return a string that describes me.
  52.    */
  53.   public synchronized String toString()
  54.     {
  55.     return Printing.toString( this, "Object[]" );
  56.     }
  57.  
  58.   /**
  59.    * Return true if I'm equal to a specified object.
  60.    * @param object The object to compare myself against.
  61.    * @return true if I'm equal to the specified object.
  62.    */
  63.   public boolean equals( Object object )
  64.     {
  65.     return Comparing.equal( this, (ObjectArray)object );
  66.     }
  67.  
  68.   /**
  69.    * Return the number of objects that I contain.
  70.    */
  71.   public int size()
  72.     {
  73.     return myArray.length;
  74.     }
  75.  
  76.   /**
  77.    * Return the maximum number of objects that I can contain.
  78.    */
  79.   public int maxSize()
  80.     {
  81.     return myArray.length;
  82.     }
  83.  
  84.   /**
  85.    * Return an Enumeration of my elements.
  86.    */
  87.   public synchronized Enumeration elements()
  88.     {
  89.     return ObjectIterator.begin( myArray, this );
  90.     }
  91.  
  92.   /**
  93.    * Return an iterator positioned at my first item.
  94.    */
  95.   public synchronized ForwardIterator start()
  96.     {
  97.     return ObjectIterator.begin( myArray, this );
  98.     }
  99.  
  100.   /**
  101.    * Return an iterator positioned immediately after my last item.
  102.    */
  103.   public synchronized ForwardIterator finish()
  104.     {
  105.     return ObjectIterator.end( myArray, this );
  106.     }
  107.  
  108.   /**
  109.    * Return the object at the specified index.
  110.    * @param index The index.
  111.    */
  112.   public synchronized Object at( int index )
  113.     {
  114.     return myArray[ index ];
  115.     }
  116.  
  117.   /**
  118.    * Set the object at a specified index.  The object must be a Integer
  119.    * @param index The index.
  120.    * @param object The object to place at the specified index.
  121.    * @exception java.lang.IndexOutOfBoundsException if index is not in range.
  122.    */
  123.   public synchronized void put( int index, Object object )
  124.     {
  125.     myArray[ index ] = object;
  126.     }
  127.   }
  128.