|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.lc.util.SafeEnumeration
Base class for strongly-typed enumerations, which know the name that was used to declare them in the Java source code.
The concrete class defines at once
A concrete class derived from SafeEnumeration
should be
implemented as follows :
public final class <MyClass> extends SafeEnumeration { private <MyClass>() { } public static final <MyClass> VALUE_A = new <MyClass>() ; public static final <MyClass> VALUE_B = new <MyClass>() ; public static final <MyClass> VALUE_C = new <MyClass>() ; }Or, as well :
public final class <MyClass> extends SafeEnumeration { private <MyClass>( String name ) { super( name ) ; } public static final <MyClass> VALUE_A = new <MyClass>( "value a" ) ; // ... }
This kind of enumeration may be iterated as follows :
<MyClass>[] elements = ( <MyClass>[] ) SafeEnumeration.getElements( <MyClass>.class ) ; for( int i = 0 ; i < elements.length ; i++ ) { <MyClass> = elements[ i ] ) ; // ... }For convenience, the concrete class could define wrappers for type-safety, depending of the needs.
Known issue : one should avoid to define a SafeEnumeration
as a nested class, since it has been observed that
SafeEnumerationPropertyEditor
does not handle them (at least with JBuilder 4.0).
Constructor Summary | |
SafeEnumeration()
Constructor. |
|
SafeEnumeration(java.lang.String userDefinedName)
Constructor. |
Method Summary | |
int |
compareTo(java.lang.Object obj)
Compares the declaring names. |
static SafeEnumeration |
getByDeclaringName(java.lang.Class aClass,
java.lang.String name)
Returns the item of a concrete class, of the given name. |
java.lang.String |
getDeclaringName()
Returns the name of the item, as defined in the Java source code. |
static SafeEnumeration[] |
getElements(java.lang.Class aClass)
Returns an array of the concrete type of the enumeration. |
static SafeEnumeration |
getFirstElement(java.lang.Class aClass)
Returns the 1st item declared in the source code. |
java.lang.String |
getName()
Returns the name of the item. |
java.lang.String |
toString()
Idem getDeclaringName() . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public SafeEnumeration()
public SafeEnumeration(java.lang.String userDefinedName)
Method Detail |
public final java.lang.String getName()
public final java.lang.String getDeclaringName()
public final java.lang.String toString()
getDeclaringName()
.toString
in class java.lang.Object
public static final SafeEnumeration[] getElements(java.lang.Class aClass)
public static final SafeEnumeration getFirstElement(java.lang.Class aClass)
public static final SafeEnumeration getByDeclaringName(java.lang.Class aClass, java.lang.String name)
aClass
- The concrete class of the enumeration.name
- The name used in the Java source code.null
if not found.public final int compareTo(java.lang.Object obj)
compareTo
in interface java.lang.Comparable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |