org.jibx.runtime
Class EnumSet

java.lang.Object
  extended byorg.jibx.runtime.EnumSet

public class EnumSet
extends java.lang.Object

Named value set support class. This provides convenience methods to support working with a set of named static final int values, including translating them to and from String representations. It's intended for use with relatively small nonnegative int values.

Author:
Dennis M. Sosnoski

Nested Class Summary
static class EnumSet.EnumItem
          Enumeration pair information.
 
Field Summary
private  java.lang.String[] m_indexedNames
          Enumeration names in index number order.
private  EnumSet.EnumItem[] m_items
          Actual item definitions (used for extensions).
private  int[] m_orderedIndexes
          Index values corresponding to sorted names.
private  java.lang.String[] m_orderedNames
          Enumeration names in sort order.
static int VALUE_LIMIT
          Maximum int value supported for enumerations.
 
Constructor Summary
EnumSet(EnumSet.EnumItem[] items)
          Constructor from array of enumeration items.
EnumSet(EnumSet base, int start, java.lang.String[] names)
          Constructor from existing enumeration with added names.
EnumSet(int start, java.lang.String[] names)
          Constructor from array of names.
 
Method Summary
private static EnumSet.EnumItem[] buildItems(int start, java.lang.String[] names)
          Generate array of enumeration items from array of names.
 void checkValue(int value)
          Check value with exception.
 java.lang.String getName(int value)
          Get name for value if defined.
 java.lang.String getNameChecked(int value)
          Get name for value.
 int getValue(java.lang.String name)
          Get value for name if defined.
 int getValueChecked(java.lang.String name)
          Get value for name.
 int maxIndex()
          Get maximum index value in enumeration set.
private static EnumSet.EnumItem[] mergeItems(EnumSet base, int start, java.lang.String[] names)
          Generate array of enumeration items from base enumeration and array of names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_LIMIT

public static final int VALUE_LIMIT
Maximum int value supported for enumerations.

See Also:
Constant Field Values

m_items

private final EnumSet.EnumItem[] m_items
Actual item definitions (used for extensions).


m_indexedNames

private final java.lang.String[] m_indexedNames
Enumeration names in index number order.


m_orderedNames

private final java.lang.String[] m_orderedNames
Enumeration names in sort order.


m_orderedIndexes

private final int[] m_orderedIndexes
Index values corresponding to sorted names.

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,
               java.lang.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 name
names - array of names (no null entries allowed)

EnumSet

public EnumSet(EnumSet base,
               int start,
               java.lang.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 extended
start - item value for first added name
names - array of names (no null entries allowed)
Method Detail

buildItems

private static EnumSet.EnumItem[] buildItems(int start,
                                             java.lang.String[] names)
Generate array of enumeration items 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 name
names - array of names (no null entries allowed)

mergeItems

private static EnumSet.EnumItem[] mergeItems(EnumSet base,
                                             int start,
                                             java.lang.String[] names)
Generate array of enumeration items from base enumeration and array of 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 extended
start - item value for first added name
names - array of names (no null entries allowed)

getName

public java.lang.String getName(int value)
Get name for value if defined.

Parameters:
value - enumeration value
Returns:
name for value, or null if not defined

getNameChecked

public java.lang.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(java.lang.String name)
Get value for name if defined.

Parameters:
name - possible enumeration name
Returns:
value for name, or -1 if not found in enumeration

getValueChecked

public int getValueChecked(java.lang.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 -

maxIndex

public int maxIndex()
Get maximum index value in enumeration set.

Returns:
maximum


Project Web Site