|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.elca.el4j.util.codingsupport.AbstractDefaultEnum
public abstract class AbstractDefaultEnum
The parent class for enums using the typesafe enum pattern (these enums are not comparable). Use the AbstractComparableEnum class as a parent if you need comparable enums. The pattern ensures that enums are correctly serialized and that there are some common accessor methods.
{ASSERT, REQUIRE, ENSURE}
:
package ch.elca.el4j.codingsupport;
import java.io.ObjectStreamException;
// only needed due to a IBM JDK 1.2.2 bug
/**
* Represents the type of an assertion.
* It uses the typesafe enum pattern for
* enum AssertType { ASSERT, REQUIRE, ENSURE };
*
*
* The code for class is potentially generated.
*
* /
public class AssertType extends AbstractDefaultEnum {
// define a private constructor with the two arguments
// and delegate construction
// to the parent class's constructor:
private AssertType(String name, int code) {
super(name, code);
}
// now define the elements:
public static final AssertType ASSERT =
new AssertType("ASSERT",1);
public static final AssertType REQUIRE =
new AssertType("REQUIRE",2);
public static final AssertType ENSURE =
new AssertType("ENSURE",3);
}
// Customize the get(String) method
public static AssertType get(String name) {
return (AssertType) AbstractDefaultEnum.get(AssertType.class, name);
}
}
readResolve
method in each enumeration is
not needed because JDK 1.2.2 is no longer supported by EL4J.
See also AbstractComparableEnum for a variant of this class that allow
comparisons (i.e. it implements Comparable).
Field Summary | |
---|---|
protected int |
m_code
The integer code for this enum element. |
protected String |
m_name
The name of this enum element. |
protected static Hashtable<String,Object> |
s_singletons
A hastable containing all instances of this class. |
Constructor Summary | |
---|---|
protected |
AbstractDefaultEnum(String name,
int code)
Constructor that initializes the name and and adds this instance into the signletons list along with its key. |
Method Summary | |
---|---|
boolean |
equals(Object that)
Return true if and only if that object is equivalent to the object this operation is invoked upon. |
protected static Object |
get(Class<?> myClass,
String name)
Return the named enum (names are case sensitive!). |
int |
hashCode()
Retruns the hash code of this instance. |
Object |
readResolve()
Performs an unique return of this instance after deserialzation. |
int |
toInt()
|
String |
toString()
Return the enum's name. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final Hashtable<String,Object> s_singletons
protected String m_name
protected int m_code
Constructor Detail |
---|
protected AbstractDefaultEnum(String name, int code)
name
- Is the name of this instance.code
- Is the code.Method Detail |
---|
protected static Object get(Class<?> myClass, String name)
myClass
- Is the type to get.name
- Is the name of the instantiated class.
public String toString()
toString
in class Object
public int toInt()
public final boolean equals(Object that)
equals
in class Object
public final int hashCode()
hashCode
in class Object
public Object readResolve() throws ObjectStreamException
readResolve
method must be duplicated in each
enum subclass. EL4J does not support it any longer.
ObjectStreamException
- On reading error.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |