org.xins.common.types
Class EnumType

java.lang.Object
  extended byorg.xins.common.types.Type
      extended byorg.xins.common.types.EnumType

public abstract class EnumType
extends Type

Abstract base class for enumeration types. An enumeration type only accepts a defined set of values.

Since:
XINS 1.0.0
Version:
$Revision: 1.17 $ $Date: 2006/08/28 09:12:34 $
Author:
Ernst de Haan
See Also:
EnumItem

Field Summary
protected  List _items
          List of the EnumItem.
protected  Map _namesToItems
          Map that links symbolic names to enumeration item objects.
protected  Map _namesToValues
          Map that links symbolic names to enumeration values.
protected  Map _valuesToItems
          Map that links enumeration values to enumeration item objects.
protected  Map _valuesToNames
          Map that links enumeration values to their symbolic names.
 
Constructor Summary
EnumType(String name, EnumItem[] items)
          Creates a new EnumType instance.
 
Method Summary
 List getEnumItems()
          Get the list of the EnumItem included in this EnumType.
 String getNameByValue(String value)
          Gets the name matching the specified value.
 String getValueByName(String name)
          Gets the value matching the specified name.
protected  boolean isValidValueImpl(String value)
          Actually checks if the specified value is valid for this type.
 String toString(EnumItem value)
          Converts the specified EnumItem to a string.
 String toString(Object value)
          Generates a string representation of the specified value for this type.
 
Methods inherited from class org.xins.common.types.Type
checkValue, fromString, fromStringImpl, getName, getValueClass, isValidValue, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_namesToValues

protected final Map _namesToValues
Map that links symbolic names to enumeration values. This map is unmodifiable.


_valuesToNames

protected final Map _valuesToNames
Map that links enumeration values to their symbolic names. This map is unmodifiable.


_namesToItems

protected final Map _namesToItems
Map that links symbolic names to enumeration item objects. This map is unmodifiable.


_valuesToItems

protected final Map _valuesToItems
Map that links enumeration values to enumeration item objects. This map is unmodifiable.


_items

protected final List _items
List of the EnumItem. This list is unmodifiable.

Constructor Detail

EnumType

public EnumType(String name,
                EnumItem[] items)
         throws IllegalArgumentException
Creates a new EnumType instance. The name of the type needs to be specified. The value class (see Type.getValueClass()) is set to String.class.

The items this type accepts should be passed. If items == null, then this type will contain no items. This is the same as passing a zero-size EnumItem array.

Note that the items array may contain null values. These will be ignored.

Parameters:
name - the name of the type, not null.
items - the items for the type, or null.
Throws:
IllegalArgumentException - if name == null.
Method Detail

isValidValueImpl

protected final boolean isValidValueImpl(String value)
Actually checks if the specified value is valid for this type. This method is called from Type.isValidValue(String). It is guaranteed that the argument is not null.

Overrides:
isValidValueImpl in class Type
Parameters:
value - the value that should be checked for validity, never null.
Returns:
true if and only if the specified value is valid, false otherwise.

toString

public String toString(EnumItem value)
Converts the specified EnumItem to a string.

Parameters:
value - the value to convert, can be null.
Returns:
the textual representation of the value, or null if and only if value == null.

toString

public final String toString(Object value)
                      throws IllegalArgumentException,
                             ClassCastException,
                             TypeValueException
Generates a string representation of the specified value for this type. The specified value must be an instance of the value class for this type (see Type.getValueClass()). Also, it has to fall within the range of valid values.

Overrides:
toString in class Type
Parameters:
value - the value, cannot be null.
Returns:
the string representation of the specified value for this type, cannot be null.
Throws:
IllegalArgumentException - if value == null.
ClassCastException - if getValueClass().isInstance(value) == false.
TypeValueException - if the specified value is not in the allowed range.

getValueByName

public final String getValueByName(String name)
                            throws IllegalArgumentException
Gets the value matching the specified name.

Parameters:
name - the name to match a corresponding value by, cannot be null.
Returns:
the corresponding value, or null if there is none.
Throws:
IllegalArgumentException - if name == null.

getNameByValue

public final String getNameByValue(String value)
                            throws IllegalArgumentException
Gets the name matching the specified value.

Parameters:
value - the value to match a corresponding name by, cannot be null.
Returns:
the corresponding name, or null if there is none.
Throws:
IllegalArgumentException - if value == null.

getEnumItems

public final List getEnumItems()
Get the list of the EnumItem included in this EnumType.

Returns:
the list of EnumItem included in this EnumType.


See http://www.xins.org/.