Package org.jibx.runtime
Class EnumSet
- java.lang.Object
-
- org.jibx.runtime.EnumSet
-
public class EnumSet extends Object
Named value set support class. This provides convenience methods to support working with a set of namedstatic final intvalues, including translating them to and fromStringrepresentations. It's intended for use with relatively small nonnegative int values.- Author:
- Dennis M. Sosnoski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEnumSet.EnumItemEnumeration pair information.
-
Field Summary
Fields Modifier and Type Field Description static intVALUE_LIMITMaximumintvalue supported for enumerations.
-
Constructor Summary
Constructors Constructor Description EnumSet(int start, String[] names)Constructor from array of names.EnumSet(EnumSet.EnumItem[] items)Constructor from array of enumeration items.EnumSet(EnumSet base, int start, String[] names)Constructor from existing enumeration with added names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckValue(int value)Check value with exception.StringgetName(int value)Get name for value if defined.StringgetNameChecked(int value)Get name for value.intgetValue(String name)Get value for name if defined.intgetValueChecked(String name)Get value for name.intmaxIndex()Get maximum index value in enumeration set.
-
-
-
Field Detail
-
VALUE_LIMIT
public static final int VALUE_LIMIT
Maximumintvalue supported for enumerations.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EnumSet
public EnumSet(EnumSet.EnumItem[] items)
Constructor from array of enumeration items. The supplied items can be in any order, and the numeric values do not need to be contiguous (but must be unique, nonnegative, and should be fairly small). Note that this constructor will reorder the items in the supplied array as a side effect.- Parameters:
items- array of enumeration items (will be reordered)
-
EnumSet
public EnumSet(int start, String[] names)Constructor from array of names. The value associated with each name is just the position index in the array added to the start value.- Parameters:
start- item value for first added namenames- array of names (nonullentries allowed)
-
EnumSet
public EnumSet(EnumSet base, int start, String[] names)
Constructor from existing enumeration with added names. The value associated with each name is just the position index in the array added to the start value.- Parameters:
base- base enumeration to be extendedstart- item value for first added namenames- array of names (nonullentries allowed)
-
-
Method Detail
-
getName
public String getName(int value)
Get name for value if defined.- Parameters:
value- enumeration value- Returns:
- name for value, or
nullif not defined
-
getNameChecked
public String getNameChecked(int value)
Get name for value. If the supplied value is not defined in the enumeration this throws an exception.- Parameters:
value- enumeration value- Returns:
- name for value
-
getValue
public int getValue(String name)
Get value for name if defined.- Parameters:
name- possible enumeration name- Returns:
- value for name, or
-1if not found in enumeration
-
getValueChecked
public int getValueChecked(String name)
Get value for name. If the supplied name is not present in the enumeration this throws an exception.- Parameters:
name- enumeration name- Returns:
- value for name
-
checkValue
public void checkValue(int value)
Check value with exception. Throws an exception if the supplied value is not defined by this enumeration.- Parameters:
value- Value to check
-
maxIndex
public int maxIndex()
Get maximum index value in enumeration set.- Returns:
- maximum
-
-