uk.ac.man.bioinf.util
Class AbstractEnumeration
java.lang.Object
|
+--uk.ac.man.bioinf.util.AbstractEnumeration
- Direct Known Subclasses:
- AbstractElement, AbstractEnumeratedModuleIdentifier, CinemaProperties, Direction, ModuleExceptionType, SequenceEventType
- public abstract class AbstractEnumeration
- extends Object
AbstractEnumeration.java
Provides support for Enumerated Types in Java. This class provides
several methods useful for all Enumerated Types including a
sensible printable toString method, the total
number of instances of a given type, an Iterator through all the
types, and an ordinal number running from 0 upwards for each type.
This class is used by extending it with a new class which
- is declared final, which prevents subclasses from
introducing new instances
- has a private constructor
- declares a public static final data member for each instance
that is required
So for example
public final class TrafficLight extends AbstractEnumeration
{
private TrafficLight( String toString ){
{
super( toString );
}
public static final TrafficLight RED
= new TrafficLight( "TrafficLight Enumerated Type:- RED" );
public static final TrafficLight ORANGE
= new Traffic( "TrafficLight Enumerated Type:- ORANGE" );
public static final TrafficLight GREEN
= new Traffic( TrafficLight Enumerated Type:- GREEN" );
}
Currently this class can not be serialised. Having one of the
subclasses implement Serializable would be a mistake as it would
provide an alternative route for the instances of the class to be
produced. This could be circumvented using the
replaceObject/writeObject methods introduced in the 1.2
serialisation spec, but I haven't got around to implementing this
yet!
It should be noted that there are problems in compiling this class
with some versions of javac. This is bug in javac (Bug ID:4157676),
not my code which is perfectly legal java. Jikes works
fine. Alternatively you can comment out the references to the ord
variable and do without this functionality, or make it non final,
in which case attempts to alter it will no longer produce compiler
errors as they should.
Created: Mon Feb 21 14:11:41 2000
- Version:
- $Id: AbstractEnumeration.java,v 1.9 2001/04/11 17:04:43 lord Exp $
- Author:
- Phillip Lord
ord
public final int ord
AbstractEnumeration
protected AbstractEnumeration(String toString)
iterator
public static Iterator iterator(Class cla)
getAllElements
public static AbstractEnumeration[] getAllElements(Class cla)
getSize
public static int getSize(Class cla)
toString
public String toString()
- Overrides:
toString
in class Object