|
Platform SDK Java 8.5 API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.genesyslab.platform.commons.GEnum
public abstract class GEnum
Superclass for classes that represent C-like (or JDK 1.5) enumerations. "Type safe enumeration" pattern implementation with some extensions to retrieve enumeration values by their "ordinal" integer values and names.
Field Summary | |
---|---|
protected static java.util.Locale |
LOCALE_ENGLISH
|
Constructor Summary | |
---|---|
protected |
GEnum(int ordinal,
java.lang.String name,
java.lang.Class enumClass)
Creates enumeration value. |
Method Summary | ||
---|---|---|
java.lang.Integer |
asInteger()
Returns Integer value of the enumeration member. |
|
static int |
enumSize(java.lang.Class enumClass)
Returns size (count of values) for the given enumeration (specified by enumClass). |
|
boolean |
equals(GEnum e1,
GEnum e2)
|
|
boolean |
equals(java.lang.Object obj)
|
|
protected static
|
getEnumMap(java.lang.Class<E> enumClass)
|
|
protected static
|
getEnumValues(java.lang.Class<E> enumClass)
|
|
static GEnum |
getValue(java.lang.Class enumClass,
int ordinal)
Returns enumeration value with specified ordinal value or null if no such value exists. |
|
static GEnum |
getValue(java.lang.Class enumClass,
java.lang.Integer ordinal)
Returns enumeration value with specified ordinal value or null if no such value exists. |
|
static GEnum |
getValue(java.lang.Class enumClass,
java.lang.String name)
Returns enumeration value with specified name or null if no such value exists. |
|
int |
hashCode()
|
|
java.lang.String |
name()
Returns name of the enumeration member. |
|
int |
ordinal()
Returns the enumeration value as an integer. |
|
java.lang.String |
toString()
|
|
static
|
valueOf(java.lang.Class<E> enumClass,
int ordinal)
Returns enumeration value by given ordinal number. |
|
static
|
valueOf(java.lang.Class<E> enumClass,
java.lang.String name)
Returns enumeration value with specified name or null if no such value exists. |
|
static java.util.Collection |
values(java.lang.Class enumClass)
Returns all values of the given (specified by enumClass) enumeration. |
|
static
|
valuesBy(java.lang.Class<E> enumClass)
Returns all values of the given (specified by enumClass) enumeration. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final java.util.Locale LOCALE_ENGLISH
Constructor Detail |
---|
protected GEnum(int ordinal, java.lang.String name, java.lang.Class enumClass)
class MyEnum extends GEnum {
public static final MyEnum BLACK = new MyEnum(0, "Black");
public static final MyEnum WHITE = new MyEnum(1, "White");
private MyEnum(final int ordinal, final String name) {
super(ordinal, name, MyEnum.class);
}
}
Note: This class does NOT support parallel multithreaded construction
of enumeration options (It uses unsynchronized internal structures during
creation and some operations). But while it's usage is similar to
example above (static constants) we can rely on safe creation
of static members.
ordinal
- ordinal value of the enumeration optionname
- name of the enumeration optionenumClass
- class of the enumerationMethod Detail |
---|
public int ordinal()
public java.lang.String name()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(GEnum e1, GEnum e2)
public static java.util.Collection values(java.lang.Class enumClass)
enumClass
- actual class of the enumeration
java.lang.NullPointerException
- if given enumClass is null
java.lang.IllegalArgumentException
- if enumClass is not enumerationvaluesBy(Class)
public static <E extends GEnum> E valueOf(java.lang.Class<E> enumClass, int ordinal)
enumClass
- actual class of the enumerationordinal
- ordinal number of the enumeration value
public static <E extends GEnum> E valueOf(java.lang.Class<E> enumClass, java.lang.String name)
enumClass
- actual class of the enumerationname
- name of value in the enumeration
public static <E extends GEnum> java.util.Collection<E> valuesBy(java.lang.Class<E> enumClass)
enumClass
- actual class of the enumeration
public static int enumSize(java.lang.Class enumClass)
enumClass
- actual class of the enumeration
java.lang.IllegalArgumentException
- if enumClass is not enumerationpublic static GEnum getValue(java.lang.Class enumClass, java.lang.Integer ordinal)
enumClass
- actual class of the enumerationordinal
- order of value in the enumeration
java.lang.IllegalArgumentException
- if enumClass is not enumerationvalueOf(Class, int)
public static GEnum getValue(java.lang.Class enumClass, int ordinal)
enumClass
- actual class of the enumerationordinal
- order of value in the enumeration
java.lang.IllegalArgumentException
- if enumClass is not enumerationvalueOf(Class, int)
public static GEnum getValue(java.lang.Class enumClass, java.lang.String name)
enumClass
- actual class of the enumerationname
- name of value in the enumeration
java.lang.IllegalArgumentException
- if enumClass is not enumerationvalueOf(Class, String)
public java.lang.Integer asInteger()
ordinal()
method.
ordinal()
protected static <E extends GEnum> java.util.Map<java.lang.Object,E> getEnumMap(java.lang.Class<E> enumClass)
protected static <E extends GEnum> java.util.Set<E> getEnumValues(java.lang.Class<E> enumClass)
|
Platform SDK Java 8.5 API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |