home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 1.9 KB | 86 lines |
- // PaintableVector.java
- // 27.02.96
- //
- // Puts a lot of typecasting in one place
-
- package cybcerone.utils;
-
- import java.util.Vector;
- import java.util.Enumeration;
-
-
- /**
- * No, this isn't a Vector that knows how to paint itself, it is
- * a Vector of Paintable objects. See the comments for the
- * Vector class, they all apply. The only difference is that it
- * only takes and returns Paintable's. Note: I didn't implement
- * the entire set of Vector methods, just the one's I use. I would
- * have extended the Vector class, but most of its methods are final.
- *
- * @see Vector;
- * @see Paintable;
- */
- public class PaintableVector {
-
- /* the real Vector behind the scenes */
- private Vector objects;
-
- public PaintableVector () {
- objects = new Vector ();
- }
-
- public PaintableVector (int initCapacity) {
- objects = new Vector (initCapacity);
- }
-
- /**
- * Converts a Vector into a PaintableVector.
- */
- public PaintableVector (Vector oldVector) {
- objects = oldVector;
- }
-
- public synchronized void addElement (Paintable newElement) {
- objects.addElement (newElement);
- }
-
- public synchronized Paintable elementAt (int index) {
- return (Paintable)objects.elementAt (index);
- }
-
- public synchronized Paintable firstElement () {
- return (Paintable)objects.firstElement ();
- }
-
- public synchronized Paintable lastElement () {
- return (Paintable)objects.lastElement ();
- }
-
- /**
- * Ok, so the Paintable type info is lost in the Enumeration.
- */
- public synchronized Enumeration elements () {
- return objects.elements ();
- }
-
- public int size () {
- return objects.size ();
- }
-
- public boolean isEmpty () {
- return objects.isEmpty ();
- }
-
- public synchronized void removeElementAt (int index) {
- objects.removeElementAt (index);
- }
-
- public synchronized String toString () {
- return objects.toString ();
- }
-
- public synchronized Vector toVector () {
- return objects;
- }
- }
-