home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / utils / paintablevector.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.9 KB  |  86 lines

  1. // PaintableVector.java
  2. // 27.02.96
  3. // 
  4. // Puts a lot of typecasting in one place
  5.  
  6. package cybcerone.utils;
  7.  
  8. import java.util.Vector;
  9. import java.util.Enumeration;
  10.  
  11.  
  12. /**
  13.  * No, this isn't a Vector that knows how to paint itself, it is
  14.  * a Vector of Paintable objects.  See the comments for the
  15.  * Vector class, they all apply.  The only difference is that it
  16.  * only takes and returns Paintable's.  Note: I didn't implement
  17.  * the entire set of Vector methods, just the one's I use.  I would
  18.  * have extended the Vector class, but most of its methods are final.
  19.  *
  20.  * @see Vector;
  21.  * @see Paintable;
  22.  */
  23. public class PaintableVector {
  24.  
  25.   /* the real Vector behind the scenes */
  26.   private Vector objects;
  27.  
  28.   public PaintableVector () {
  29.     objects = new Vector ();
  30.   }
  31.  
  32.   public PaintableVector (int initCapacity) {
  33.     objects = new Vector (initCapacity);
  34.   }
  35.  
  36.   /**
  37.    * Converts a Vector into a PaintableVector.
  38.    */
  39.   public PaintableVector (Vector oldVector) {
  40.     objects = oldVector;
  41.   }
  42.  
  43.   public synchronized void addElement (Paintable newElement) {
  44.     objects.addElement (newElement);
  45.   }
  46.  
  47.   public synchronized Paintable elementAt (int index) {
  48.     return (Paintable)objects.elementAt (index);
  49.   }
  50.  
  51.   public synchronized Paintable firstElement () {
  52.     return (Paintable)objects.firstElement ();
  53.   }
  54.  
  55.   public synchronized Paintable lastElement () {
  56.     return (Paintable)objects.lastElement ();
  57.   }
  58.  
  59.   /**
  60.    * Ok, so the Paintable type info is lost in the Enumeration. 
  61.    */
  62.   public synchronized Enumeration elements () {
  63.     return objects.elements ();
  64.   }
  65.  
  66.   public int size () {
  67.     return objects.size ();
  68.   }
  69.  
  70.   public boolean isEmpty () {
  71.     return objects.isEmpty ();
  72.   }
  73.  
  74.   public synchronized void removeElementAt (int index) {
  75.     objects.removeElementAt (index);
  76.   }
  77.  
  78.   public synchronized String toString () {
  79.     return objects.toString ();
  80.   }
  81.  
  82.   public synchronized Vector toVector () {
  83.     return objects;
  84.   }
  85. }
  86.