|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gjt.lindfors.util.TypeSupport
public abstract class TypeSupport
Support class for creating enumerated types. You can use this abstract class to easily create immutable type classes. Type classes are useful for creating enumerated types which provide type safety for objects and their methods.
To create a unique type for a class with help of the TypeSupport
class, you need to define a top-level inner class within the class
that requires enumerated types. This inner class can then extend
the TypeSupport
class and provide its own
private constructor that calls the protected
constructor in TypeSupport
. The constructors of your
inner class must be private in order to guarantee
the safety of this type. The inner class must be immutable as well.
Here's an example:
public class TypeSafeClass { public static final ClassType FOO = new ClassType("Foo"); public static final ClassType BAR = new ClassType("Bar"); public static class ClassType extends TypeSupport { private ClassType(String name) { super(name); } } public void TypeSafeMethod(ClassType type) { // ... do something ... } }
In the example above, the TypeSafeMethod
method of
TypeSafeClass
is guaranteed to get as an argument
either FOO
or BAR
. The ClassType
inner class has a private constructor, so the only class that can
instantiate it, is TypeSafeClass
. And since
TypeSafeClass
only creates two instances of
ClassType
ever, FOO
and BAR
, that
are public to other classes, no other arguments can ever be passed to
TypeSafeMethod
method.
For more detailed documentation, refer to the Util Library Tutorial .
Constructor Summary | |
---|---|
protected |
TypeSupport(java.lang.String name)
Constructs a new type with given name. |
Method Summary | |
---|---|
java.lang.String |
getName()
Returns the name of this type. |
java.awt.Component |
toComponent()
[PENDING] Returns a visual representation of this object. |
java.lang.String |
toString()
Returns a string representation of this type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected TypeSupport(java.lang.String name)
java.lang.IllegalArgumentException
- if a null pointer is passed
as a nameMethod Detail |
---|
public java.lang.String toString()
The output is similar to the following:
TypeSupport[name="type name"]
toString
in class java.lang.Object
public java.lang.String getName()
public java.awt.Component toComponent()
toComponent
in interface Visualizable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |