All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class EDU.bmrb.starlibj.VectorCheckType

java.lang.Object
   |
   +----EDU.bmrb.starlibj.VectorCheckType

public class VectorCheckType
extends Object
VectorCheckType is essentially the exact same thing as the standard Java class java.util.vector, but with the additional provisions to ensure that only objects of a specific type will be allowed to be put into the vector. Anything else is deemed an error and generates an exception. Essentially, what you do is you create an object of type VectorCheckType, then add the types you want it to be able to hold using addType(). Then prevent any future types from being added with freezeTypes(). Until you have done this, you cannot insert anything into the vector. Once you have called freezeTypes(), you cannot call addType() again. The idea is to provide a generic way to implement something like the C++ concept of template classes - we want to have a vector that only allows some types of object, not all types of object. Typically, addType() and freezeTypes() will have already been called internally in the library before the user programmer gets to use the vector. For example, StarFileNode will use a VectorCheckType that has been set up to only hold BlockNodes.

A typical piece of code using VectorCheckType might look like this:
Right
             VectorCheckType aVect =
                 new VectorCheckType();
             [...snip...]
             // Make the vector accept
             // only items and loops:
             aVect.addType(
                 Class.forName( StarValidity.clsNameDataItemNode) );
             aVect.addType( 
                 Class.forName( StarValidity.clsNameDataLoopNode) );
             aVect.freezeTypes();
             aVect.addElement( 
                 new DataItemNode([...snip...]);
         
Wrong Wrong
             VectorCheckType aVect =
                 new VectorCheckType();
             [...snip...]
             // Make the vector accept
             // only items and loops:
             aVect.addType(
                 Class.forName( StarValidity.clsNameDataItemNode) );
             aVect.addType( 
                 Class.forName( StarValidity.clsNameDataLoopNode) );
             // This attempt to add an element
             // before the list was frozen
             // produces and exception.
             aVect.addElement( 
                 new DataItemNode([...snip...]);
             aVect.freezeTypes();
         
             VectorCheckType aVect =
                 new VectorCheckType();
             [...snip...]
             // Make the vector accept
             // only items and loops:
             aVect.addType(
                 Class.forName( StarValidity.clsNameDataItemNode) );
             aVect.addType( 
                 Class.forName( StarValidity.clsNameDataLoopNode) );
             aVect.freezeTypes();
             // This attempt to add an
             // element of the wrong type
             // produces an exception.
             aVect.addElement( SomeOtherType );
             // This is also an exception:
             //   Attempting to add more
             //   types after freezeTypes()
             //   has been called.
             aVect.addType( SomeOtherType);
         


Variable Index

 o data
 o types
 o typesFrozen

Constructor Index

 o VectorCheckType()
makes an empty vector
 o VectorCheckType(int)
makes an empty vector with a starting capacity
 o VectorCheckType(int, int)
Constructs an empty vector with starting capacity and amount to increment it by when it is overflown.

Method Index

 o addElement(Object)
Just like the Vector method of the same name.
 o addType(Class)
Adds another type to the list of types that the class will allow to be inserted.
 o capacity()
Just like the Vector method of the same name.
 o contains(Object)
Just like the Vector method of the same name.
 o elementAt(int)
Just like the Vector method of the same name.
 o elements()
Just like the Vector method of the same name.
 o firstElement()
Just like the Vector method of the same name.
 o freezeTypes()
Freezes the class like it is such that no more types can be added to the list of acceptable types for this vector to hold.
 o indexOf(Object)
Just like the Vector method of the same name.
 o indexOf(Object, int)
Just like the Vector method of the same name.
 o insertElementAt(Object, int)
Just like the Vector method of the same name.
 o isEmpty()
Just like the Vector method of the same name.
 o isObjectAllowed(Object)
Used to ask "is this object allowed in this class?" (In other words, "Was there a previous call to addType() that allowed it to handle this kind of class?")
 o lastElement()
Just like the Vector method of the same name.
 o lastIndexOf(Object)
Just like the Vector method of the same name.
 o lastIndexOf(Object, int)
Just like the Vector method of the same name.
 o removeElement(Object)
Just like the Vector method of the same name.
 o removeElementAt(int)
Similar to the Vector method of the same name.
 o setElementAt(Object, int)
Just like the Vector method of the same name.
 o setSize(int)
Just like the Vector method of the same name.
 o size()
Just like the Vector method of the same name.

Variables

 o types
 protected Vector types
 o data
 protected Vector data
 o typesFrozen
 protected boolean typesFrozen

Constructors

 o VectorCheckType
 public VectorCheckType()
makes an empty vector

 o VectorCheckType
 public VectorCheckType(int startCap)
makes an empty vector with a starting capacity

 o VectorCheckType
 public VectorCheckType(int startCap,
                        int incr)
Constructs an empty vector with starting capacity and amount to increment it by when it is overflown.

Methods

 o addType
 public void addType(Class typ) throws TypesAreFrozen
Adds another type to the list of types that the class will allow to be inserted. This must be done before the vector can have any values inserted into it.

See Also:
freezeTypes
 o freezeTypes
 public void freezeTypes()
Freezes the class like it is such that no more types can be added to the list of acceptable types for this vector to hold. Until this is done, none of the insertion functions for this vector will be allowed.

 o setSize
 public void setSize(int newSize)
Just like the Vector method of the same name.

See Also:
setSize
 o capacity
 public int capacity()
Just like the Vector method of the same name.

See Also:
capacity
 o size
 public int size()
Just like the Vector method of the same name.

See Also:
size
 o isEmpty
 public boolean isEmpty()
Just like the Vector method of the same name.

See Also:
isEmpty
 o elements
 public Enumeration elements()
Just like the Vector method of the same name.

See Also:
Enumeration
 o contains
 public boolean contains(Object obj)
Just like the Vector method of the same name.

See Also:
contains
 o indexOf
 public int indexOf(Object obj)
Just like the Vector method of the same name.

See Also:
indexOf
 o indexOf
 public int indexOf(Object obj,
                    int index)
Just like the Vector method of the same name.

See Also:
indexOf
 o lastIndexOf
 public int lastIndexOf(Object obj)
Just like the Vector method of the same name.

See Also:
lastIndexOf
 o lastIndexOf
 public int lastIndexOf(Object obj,
                        int index)
Just like the Vector method of the same name.

See Also:
lastIndexOf
 o elementAt
 public Object elementAt(int index)
Just like the Vector method of the same name.

See Also:
elementAt
 o firstElement
 public Object firstElement()
Just like the Vector method of the same name.

See Also:
firstElement
 o lastElement
 public Object lastElement()
Just like the Vector method of the same name.

See Also:
lastElement
 o setElementAt
 public void setElementAt(Object obj,
                          int index) throws WrongElementType, TypesNotFrozenYet
Just like the Vector method of the same name.

See Also:
setElementAt
 o removeElementAt
 public void removeElementAt(int index)
Similar to the Vector method of the same name.

See Also:
removeElementAt
 o insertElementAt
 public void insertElementAt(Object obj,
                             int index) throws WrongElementType, TypesNotFrozenYet
Just like the Vector method of the same name.

See Also:
insertElementAt
 o addElement
 public void addElement(Object obj) throws WrongElementType, TypesNotFrozenYet
Just like the Vector method of the same name.

See Also:
addElement
 o removeElement
 public boolean removeElement(Object obj)
Just like the Vector method of the same name.

See Also:
removeElement
 o isObjectAllowed
 public boolean isObjectAllowed(Object o)
Used to ask "is this object allowed in this class?" (In other words, "Was there a previous call to addType() that allowed it to handle this kind of class?")

Parameters:
o - the object to check for.
See Also:
addType

All Packages  Class Hierarchy  This Package  Previous  Next  Index