public abstract class EnumType extends Type
EnumItem
Modifier and Type | Field and Description |
---|---|
protected Map<String,EnumItem> |
_namesToItems
Map that links symbolic names to enumeration item objects.
|
protected Map<String,EnumItem> |
_valuesToItems
Map that links enumeration values to enumeration item objects.
|
Constructor and Description |
---|
EnumType(String name,
EnumItem[] items)
Creates a new
EnumType instance. |
Modifier and Type | Method and Description |
---|---|
List<EnumItem> |
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.
|
checkValue, fromString, fromStringImpl, getDescription, getName, getValueClass, isValidValue, toString
protected final Map<String,EnumItem> _namesToItems
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
.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
.See http://www.xins.org/.