|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xins.common.types.Type org.xins.common.types.EnumType
Abstract base class for enumeration types. An enumeration type only accepts a defined set of values.
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 |
protected final Map _namesToValues
protected final Map _valuesToNames
protected final Map _namesToItems
protected final Map _valuesToItems
protected final List _items
EnumItem
. This list is unmodifiable.
Constructor Detail |
public EnumType(String name, EnumItem[] items) throws IllegalArgumentException
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.
name
- the name of the type, not null
.items
- the items for the type, or null
.
IllegalArgumentException
- if name == null
.Method Detail |
protected final boolean isValidValueImpl(String value)
Type.isValidValue(String)
. It is guaranteed that
the argument is not null
.
isValidValueImpl
in class Type
value
- the value that should be checked for validity, never
null
.
true
if and only if the specified value is valid,
false
otherwise.public String toString(EnumItem value)
EnumItem
to a string.
value
- the value to convert, can be null
.
null
if and
only if value == null
.public final String toString(Object value) throws IllegalArgumentException, ClassCastException, TypeValueException
Type.getValueClass()
). Also, it has to fall within the range of
valid values.
toString
in class Type
value
- the value, cannot be null
.
null
.
IllegalArgumentException
- if value == null
.
ClassCastException
- if getValueClass().isInstance(value) == false
.
TypeValueException
- if the specified value is not in the allowed range.public final String getValueByName(String name) throws IllegalArgumentException
name
- the name to match a corresponding value by, cannot be
null
.
null
if there is none.
IllegalArgumentException
- if name == null
.public final String getNameByValue(String value) throws IllegalArgumentException
value
- the value to match a corresponding name by, cannot be
null
.
null
if there is none.
IllegalArgumentException
- if value == null
.public final List getEnumItems()
EnumType
.
EnumItem
included in this EnumType
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |