Package mondrian.olap
Class EnumeratedValues<V extends EnumeratedValues.Value>
- java.lang.Object
-
- mondrian.olap.EnumeratedValues<V>
-
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
Category
public class EnumeratedValues<V extends EnumeratedValues.Value> extends Object implements Cloneable
EnumeratedValuesis a 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 finalmembers. Give it a private constructor, and apublic static final ClassName instancemember to hold the singleton instance.Accessis a simple example of this.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEnumeratedValues.BasicValueBasicValueis an obvious implementation ofEnumeratedValues.Value.static interfaceEnumeratedValues.ValueAValuerepresents a member of an enumerated type.
-
Constructor Summary
Constructors Constructor Description EnumeratedValues()Creates a new empty, mutable enumeration.EnumeratedValues(Class<? extends Enum> clazz)EnumeratedValues(String[] names)Creates an enumeration, initialize it with an array of strings, and freezes it.EnumeratedValues(String[] names, int[] codes)Create an enumeration, initializes it with arrays of code/name pairs, and freezes it.EnumeratedValues(String[] names, int[] codes, String[] descriptions)Create an enumeration, initializes it with arrays of code/name pairs, and freezes it.EnumeratedValues(V[] values)Creates an enumeration, with an array of values, and freezes it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RuntimeExceptionbadValue(int ordinal)Returns an error indicating that the value is illegal.EnumeratedValues<V>clone()StringgetDescription(int ordinal)Returns the description associated with an ordinal; the return value is null if the ordinal is not a member of the enumeration.intgetMax()Returns the largest ordinal defined by this enumeration.intgetMin()Returns the smallest ordinal defined by this enumeration.EnumeratedValuesgetMutableClone()Creates a mutable enumeration from an existing enumeration, which may already be immutable.StringgetName(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 declaration order.intgetOrdinal(String name)Returns the ordinal associated with a nameVgetValue(int ordinal)Returns the name associated with an ordinal; the return value is null if the ordinal is not a member of the enumeration.VgetValue(String name, boolean fail)Returns the value associated with a name.List<V>getValuesSortedByName()Returns the members of this enumeration, sorted by name.booleanisImmutable()booleanisValid(int ordinal)Returns whetherordinalis valid for this enumeration.voidmakeImmutable()Freezes the enumeration, preventing it from being further modified.voidregister(V value)Associates a symbolic name with an ordinal value.RuntimeExceptionunexpected(V value)Returns an exception indicating that we didn't expect to find this value here.
-
-
-
Constructor Detail
-
EnumeratedValues
public EnumeratedValues()
Creates a new empty, mutable enumeration.
-
EnumeratedValues
public EnumeratedValues(V[] values)
Creates an enumeration, with an array of values, and freezes it.
-
EnumeratedValues
public EnumeratedValues(String[] names)
Creates an enumeration, initialize it with an array of strings, and freezes it.
-
EnumeratedValues
public EnumeratedValues(String[] names, int[] codes)
Create an enumeration, initializes it with arrays of code/name pairs, and freezes it.
-
EnumeratedValues
public EnumeratedValues(String[] names, int[] codes, String[] descriptions)
Create an enumeration, initializes it with arrays of code/name pairs, and freezes it.
-
-
Method Detail
-
clone
public EnumeratedValues<V> clone()
-
getMutableClone
public EnumeratedValues getMutableClone()
Creates a mutable enumeration from an existing enumeration, which may already be immutable.
-
register
public void register(V value)
Associates a symbolic name with an ordinal value.
-
makeImmutable
public void makeImmutable()
Freezes the enumeration, preventing it from being further modified.
-
isImmutable
public final boolean isImmutable()
-
getMin
public final int getMin()
Returns the smallest ordinal defined by this enumeration.
-
getMax
public final int getMax()
Returns the largest ordinal defined by this enumeration.
-
isValid
public final boolean isValid(int ordinal)
Returns whetherordinalis 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)- Parameters:
ordinal- Suspected ordinal from this enumeration.- Returns:
- Whether
ordinalis valid.
-
getValue
public final V getValue(int ordinal)
Returns the name associated with an ordinal; the return value is null if the ordinal is not a member of the enumeration.
-
getName
public final 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.
-
getDescription
public final 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.
-
getOrdinal
public final int getOrdinal(String name)
Returns the ordinal associated with a name- Throws:
Error- if the name is not a member of the enumeration
-
getValue
public V getValue(String name, boolean fail)
Returns the value associated with a name.- Parameters:
name- Name of enumerated valuefail- Whether to throw if not found- Throws:
Error- if the name is not a member of the enumeration andfailis true
-
getNames
public String[] getNames()
Returns the names in this enumeration, in declaration order.
-
getValuesSortedByName
public List<V> getValuesSortedByName()
Returns the members of this enumeration, sorted by name.
-
badValue
public RuntimeException badValue(int ordinal)
Returns an error indicating that the value is illegal. (The client needs to throw the error.)
-
unexpected
public RuntimeException unexpected(V value)
Returns an exception indicating that we didn't expect to find this value here.
-
-