|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.text.AbstractStringToObjectConverter
com.taco.text.MappedStringToObjectConverter
public class MappedStringToObjectConverter
A simple implementation of IStringToObjectConverter
that looks
up strings to be converted in a map, and returns the mapped value. This is
useful when the set of strings to be converted is finite.
Field Summary | |
---|---|
protected java.lang.Object |
_defaultValue
The default value returned when the the string is not found in the map. |
protected java.util.Map |
_map
The string to object map used for conversion. |
protected static java.lang.Object |
_NO_DEFAULT_VALUE
A value for _defaultValue indicating that a
ParseException should be thrown instead of returning a
default value. |
Constructor Summary | |
---|---|
MappedStringToObjectConverter(java.util.Map map)
Construct a new instance using map as a conversion map
between strings and objects. |
|
MappedStringToObjectConverter(java.util.Map map,
java.lang.Object defaultValue)
Construct a new instance using map as a conversion map
between strings and objects. |
|
MappedStringToObjectConverter(java.lang.Object[] mappings)
A convenience constructor that converts mappings into the
conversion map using MapUtilities.arrayToHashMap() ,
wrapping null values. |
|
MappedStringToObjectConverter(java.lang.Object[] mappings,
java.lang.Object defaultValue)
A convenience constructor that converts mappings into the
conversion map using MapUtilities.arrayToHashMap() ,
wrapping null values. |
Method Summary | |
---|---|
java.lang.Object |
toObject(java.lang.String s)
See if the string is mapped to a value. |
Methods inherited from class com.taco.text.AbstractStringToObjectConverter |
---|
map |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.util.Map _map
protected final java.lang.Object _defaultValue
_NO_DEFAULT_VALUE
, a
ParseException
is thrown instead.
protected static final java.lang.Object _NO_DEFAULT_VALUE
_defaultValue
indicating that a
ParseException
should be thrown instead of returning a
default value.
Constructor Detail |
---|
public MappedStringToObjectConverter(java.util.Map map)
map
as a conversion map
between strings and objects. If a string to be converted cannot be
found in the conversion map when toObject()
is called,
throw a ParseException
.
public MappedStringToObjectConverter(java.util.Map map, java.lang.Object defaultValue)
map
as a conversion map
between strings and objects. If a string to be converted cannot be
found in the conversion map, defaultValue
will be returned
instead by toObject()
.
java.lang.NullPointerException
- if map
is null
public MappedStringToObjectConverter(java.lang.Object[] mappings, java.lang.Object defaultValue)
mappings
into the
conversion map using MapUtilities.arrayToHashMap()
,
wrapping null values. If a string to be converted cannot be found in
the conversion map, defaultValue
will be returned instead
by toObject()
.
MapUtilities.arrayToHashMap(java.lang.Object[])
public MappedStringToObjectConverter(java.lang.Object[] mappings)
mappings
into the
conversion map using MapUtilities.arrayToHashMap()
,
wrapping null values. If a string to be converted cannot be
found in the conversion map when toObject()
is called,
throw a ParseException
.
MapUtilities.arrayToHashMap(java.lang.Object[])
Method Detail |
---|
public java.lang.Object toObject(java.lang.String s) throws java.text.ParseException
MapUtilities.NULL_MAP_VALUE
, indicating that the string
is mapped to null
). If the string is not mapped, return
the default value if one was specified during construction. Otherwise,
throw a ParseException
.
toObject
in interface IStringToObjectConverter
java.text.ParseException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |