|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.util14.Enum14
public class Enum14
Enum14
is a pre-JDK1.5-enum helper class for declaring a set of
symbolic constants which have names, ordinals, and possibly descriptions. The
ordinals do not have to be contiguous.
Typically, for a particular set of constants, you derive a class from this
interface, and declare the constants as public static final
members. Give it a private constructor, and a public static final
ClassName instance
member to hold the singleton instance.
Nested Class Summary | |
---|---|
static class |
Enum14.BasicValue
BasicValue is an obvious implementation of Enum14.Value . |
static class |
Enum14.SerializableValue
SerializableValue extends BasicValue to provide
better support for serializable subclasses. |
static interface |
Enum14.Value
A Value represents a member of an enumerated type. |
Field Summary | |
---|---|
private static String[] |
emptyStringArray
|
private int |
max
the largest ordinal value |
private int |
min
the smallest ordinal value |
private Enum14.Value[] |
ordinalToValueMap
An array mapping ordinals to Enum14.Value s. |
private HashMap |
valuesByName
map symbol names to values |
Constructor Summary | |
---|---|
Enum14()
Creates a new empty, mutable enumeration. |
|
Enum14(Enum14.Value[] values)
Creates an enumeration, with an array of values, and freezes it. |
|
Enum14(String[] names)
Creates an enumeration, initialize it with an array of strings, and freezes it. |
|
Enum14(String[] names,
int[] codes)
Create an enumeration, initializes it with arrays of code/name pairs, and freezes it. |
|
Enum14(String[] names,
int[] codes,
String[] descriptions)
Create an enumeration, initializes it with arrays of code/name pairs, and freezes it. |
Method Summary | |
---|---|
Error |
badValue(int ordinal)
Returns an error indicating that the value is illegal. |
protected Object |
clone()
|
boolean |
containsName(String name)
Returns true if this enumerationr contains name , else false. |
String |
getDescription(int ordinal)
Returns the description associated with an ordinal; the return value is null if the ordinal is not a member of the enumeration. |
int |
getMax()
Returns the largest ordinal defined by this enumeration. |
int |
getMin()
Returns the smallest ordinal defined by this enumeration. |
Enum14 |
getMutableClone14()
Creates a mutable enumeration from an existing enumeration, which may already be immutable. |
String |
getName(int ordinal)
Returns the name associated with an ordinal; the return value is null if the ordinal is not a member of the enumeration. |
String[] |
getNames()
Returns the names in this enumeration, in no particular order. |
int |
getOrdinal(String name)
Returns the ordinal associated with a name |
int |
getSize()
Returns the number of enumerated values currently contained in this enumeration |
Enum14.Value |
getValue(int ordinal)
Returns the value associated with an ordinal; the return value is null if the ordinal is not a member of the enumeration. |
Enum14.Value |
getValue(String name)
Returns the ordinal associated with a name. |
boolean |
isImmutable()
|
boolean |
isValid(int ordinal)
Returns whether ordinal is valid for this enumeration. |
Iterator |
iterator()
Returns an iterator over the values of this enumeration. |
void |
makeImmutable()
Freezes the enumeration, preventing it from being further modified. |
void |
register(Enum14.Value value)
Associates a symbolic name with an ordinal value. |
Error |
unexpected(Enum14.Value value)
Returns an exception indicating that we didn't expect to find this value here. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String[] emptyStringArray
private HashMap valuesByName
private Enum14.Value[] ordinalToValueMap
Enum14.Value
s. It is biased by the min
value. It is built by makeImmutable()
.
private int max
private int min
Constructor Detail |
---|
public Enum14()
public Enum14(Enum14.Value[] values)
public Enum14(String[] names)
public Enum14(String[] names, int[] codes)
public Enum14(String[] names, int[] codes, String[] descriptions)
Method Detail |
---|
public final String getDescription(int ordinal)
public final boolean isImmutable()
public final int getSize()
public final int getMax()
public final int getMin()
public Enum14 getMutableClone14()
public final String getName(int ordinal)
public final Enum14.Value getValue(int ordinal)
public final int getOrdinal(String name)
Error
- if the name is not a member of the enumerationpublic final boolean isValid(int ordinal)
ordinal
is valid for this enumeration. This
method is particularly useful in pre- and post-conditions, for example
@param axisCode Axis code, must be a {@link AxisCode} value @pre AxisCode.instance.isValid(axisCode)
ordinal
- Suspected ordinal from this enumeration.
ordinal
is valid.public Iterator iterator()
public String[] getNames()
public Enum14.Value getValue(String name)
Error
- if the name is not a member of the enumerationpublic boolean containsName(String name)
name
, else false.
public Error badValue(int ordinal)
public void makeImmutable()
public void register(Enum14.Value value)
public Error unexpected(Enum14.Value value)
Util.unexpected(E)
protected Object clone()
clone
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |