ch.elca.el4j.util.codingsupport
Class AbstractComparableEnum
java.lang.Object
ch.elca.el4j.util.codingsupport.AbstractDefaultEnum
ch.elca.el4j.util.codingsupport.AbstractComparableEnum
- All Implemented Interfaces:
- Serializable, Comparable<AbstractComparableEnum>
public abstract class AbstractComparableEnum
- extends AbstractDefaultEnum
- implements Comparable<AbstractComparableEnum>
The parent class for comparable enums using the typesafe enum pattern.
How to Use
Usage example
The following code shows how to write an enumeration with the three possible
values
{EXPECTED, NORMAL, UNEXPECTED}:
/**
* Severity Levels for reporting exceptions with code traces.
* /
static public class SeverityLevel extends AbstractComparableEnum {
private SeverityLevel (String name, int code)
{
super (name, code);
}
static public final SeverityLevel EXPECTED =
new SeverityLevel ("EXPECTED",1);
static public final SeverityLevel NORMAL =
new SeverityLevel ("NORMAL",2);
static public final SeverityLevel UNEXPECTED =
new SeverityLevel ("UNEXPECTED",3);
}
Please refer also to the Javadoc of the uncomparable enums in
AbstractDefaultEnum. The duplication of readResolve
method in each enumeration is not needed because JDK 1.2.2 is no longer
supported by EL4J.
- Author:
- Raphael Boog (RBO)
- See Also:
- Serialized Form
- File-location:
- AbstractComparableEnum
- Last check-in date:
- 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) by swismer for revision 3873
ENUM_LIST
protected static final ArrayList<AbstractComparableEnum> ENUM_LIST
- The list of all comparable enums ever created.
m_ordinal
protected final int m_ordinal
- The ordinal assigned to this comparable enum. This value is directly used
for comparison.
AbstractComparableEnum
protected AbstractComparableEnum(String name,
int code)
- Override this default constructor with your own constructor.
- Parameters:
name - Is the name.code - Is the code.
size
protected static int size(Class<?> myClass)
- Parameters:
myClass - Is the type to count.
- Returns:
- Return the number of enums of an enumeration.
iterator
protected static Iterator<AbstractComparableEnum> iterator(Class<?> myClass)
- Parameters:
myClass - Is the class to be used.
- Returns:
- Return an iterator for the elements of the specified enum class.
compareTo
public int compareTo(AbstractComparableEnum o)
-
- Specified by:
compareTo in interface Comparable<AbstractComparableEnum>
Copyright © 2005-2011 ELCA. All Rights Reserved.