@DefaultKey(value="parser") @InvalidScope(value="session") @SkipSetters public class ValueParser extends FormatConfig implements Map<String,Object>
Utility class for easy parsing of String values held in a Map.
This comes in very handy when parsing parameters.
When subkeys are allowed, getValue("foo") will also search for all keys of the form "foo.bar" and return a ValueParser of the type "bar" -> value for all found values.
TODO: someone doing java configuration ought to be able to put a source Map in the tool properties, allowing this to be used like other toolsModifier and Type | Field and Description |
---|---|
static String |
ALLOWSUBKEYS_KEY
The key used for specifying whether to support subkeys
|
static String |
DEFAULT_STRINGS_DELIMITER |
static String |
READONLY_KEY
The key used for specifying whether to be read-only
|
static String |
STRINGS_DELIMITER_FORMAT_KEY |
DEFAULT_FORMAT, FORMAT_KEY
DEFAULT_LOCALE
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
Constructor and Description |
---|
ValueParser() |
ValueParser(Map<String,Object> source) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
protected void |
configure(ValueParser values)
Does the actual configuration.
|
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,Object>> |
entrySet() |
boolean |
exists(String key)
Convenience method for checking whether a certain parameter exists.
|
Object |
get(Object key) |
Object |
get(String key)
Convenience method for use in Velocity templates.
|
protected boolean |
getAllowSubkeys()
Are subkeys allowed ?
|
Boolean |
getBoolean(String key) |
boolean |
getBoolean(String key,
boolean alternate) |
Boolean |
getBoolean(String key,
Boolean alternate) |
Boolean[] |
getBooleans(String key) |
Double |
getDouble(String key) |
double |
getDouble(String key,
double alternate) |
Double |
getDouble(String key,
Double alternate) |
double[] |
getDoubles(String key) |
int |
getInt(String key,
int alternate) |
Integer |
getInteger(String key) |
Integer |
getInteger(String key,
Integer alternate) |
int[] |
getInts(String key) |
Locale |
getLocale(String key) |
Locale |
getLocale(String key,
Locale alternate) |
Locale[] |
getLocales(String key) |
Number |
getNumber(String key) |
Number |
getNumber(String key,
Number alternate) |
Number[] |
getNumbers(String key) |
protected boolean |
getReadOnly()
Is the Map read-only?
|
protected Map<String,Object> |
getSource() |
protected Map<String,Object> |
getSource(boolean create) |
String |
getString(String key) |
String |
getString(String key,
String alternate) |
String[] |
getStrings(String key) |
protected ValueParser |
getSubkey(String subkey)
subkey getter that returns a map subkey#2 -> value
for every "subkey.subkey2" found entry
|
Set<String> |
getSubkeys()
returns the set of all possible first-level subkeys, including complete keys without dots (or returns keySet() if allowSubKeys is false)
|
Object |
getValue(String key)
Returns the value mapped to the specified key
in the
Map returned by getSource() . |
Object |
getValue(String key,
Object alternate) |
Object[] |
getValues(String key)
Returns an array of values.
|
boolean |
hasSubkeys()
Determines whether there are subkeys available in the source map.
|
boolean |
isEmpty() |
Set<String> |
keySet() |
protected String[] |
parseStringList(String value) |
Object |
put(String key,
Object value) |
void |
putAll(Map<? extends String,? extends Object> m) |
Object |
remove(Object key) |
protected void |
setAllowSubkeys(boolean allow)
allow or disallow subkeys
|
protected void |
setReadOnly(boolean ro)
Set or unset read-only behaviour
|
protected void |
setSource(Map<String,Object> source) |
protected void |
setStringsDelimiter(String stringsDelimiter)
Sets the delimiter used for separating values in a single String value.
|
int |
size() |
String |
toString() |
Collection |
values() |
getFormat, setFormat
getLocale, setLocale, toLocale
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final String STRINGS_DELIMITER_FORMAT_KEY
public static final String DEFAULT_STRINGS_DELIMITER
public static final String ALLOWSUBKEYS_KEY
public static final String READONLY_KEY
protected boolean getAllowSubkeys()
protected void setAllowSubkeys(boolean allow)
allow
- flag valueprotected boolean getReadOnly()
protected void setReadOnly(boolean ro)
ro
- flag valueprotected final void setStringsDelimiter(String stringsDelimiter)
stringsDelimiter
- strings delimitergetValues(String)
protected void configure(ValueParser values)
configure
in class FormatConfig
values
- configuration valuespublic boolean exists(String key)
key
- the parameter's keytrue
if a parameter exists for the specified
key; otherwise, returns false
.public Object get(String key)
key
- the parameter's keynull
if there is no matching
parameterpublic Object getValue(String key)
Map
returned by getSource()
. If there is
no source, then this will always return null
.key
- property keypublic Object getValue(String key, Object alternate)
key
- the desired parameter's keyalternate
- The alternate valuepublic Object[] getValues(String key)
Returns an array of values. If the internal value is a string, it is split using the configured delimitor (',' by default).
If the internal value is not an array or is a string without any delimiter, a singletin array is returned.
key
- the desired parameter's keypublic String getString(String key)
key
- the parameter's keynull
if there is no matching
parameterpublic String getString(String key, String alternate)
key
- the desired parameter's keyalternate
- The alternate valuepublic Boolean getBoolean(String key)
key
- the desired parameter's keyBoolean
object for the specified key or
null
if no matching parameter is foundpublic boolean getBoolean(String key, boolean alternate)
key
- the desired parameter's keyalternate
- The alternate boolean valuepublic Integer getInteger(String key)
key
- the desired parameter's keyInteger
for the specified key or
null
if no matching parameter is foundpublic Integer getInteger(String key, Integer alternate)
key
- the desired parameter's keyalternate
- The alternate Integerpublic Double getDouble(String key)
key
- the desired parameter's keyDouble
for the specified key or
null
if no matching parameter is foundpublic Double getDouble(String key, Double alternate)
key
- the desired parameter's keyalternate
- The alternate Doublepublic Number getNumber(String key)
key
- the desired parameter's keyNumber
for the specified key or
null
if no matching parameter is foundpublic Locale getLocale(String key)
key
- the desired parameter's keyLocale
for the specified key or
null
if no matching parameter is foundpublic Number getNumber(String key, Number alternate)
key
- the desired parameter's keyalternate
- The alternate Numberpublic int getInt(String key, int alternate)
key
- the desired parameter's keyalternate
- The alternate int valuepublic double getDouble(String key, double alternate)
key
- the desired parameter's keyalternate
- The alternate double valuepublic Locale getLocale(String key, Locale alternate)
key
- the desired parameter's keyalternate
- The alternate Localepublic String[] getStrings(String key)
key
- the key for the desired parameternull
if the no values are associated with the given keypublic Boolean[] getBooleans(String key)
key
- the key for the desired parameterpublic Number[] getNumbers(String key)
key
- the key for the desired parameternull
if Numbers are not associated with it.public int[] getInts(String key)
key
- the key for the desired parameternull
if numbers are not associated with it.public double[] getDoubles(String key)
key
- the key for the desired parameternull
if numbers are not associated with it.public Locale[] getLocales(String key)
key
- the key for the desired parameternull
if Locales are not associated with it.public boolean hasSubkeys()
true
if there are subkeys (key names containing a dot)public Set<String> getSubkeys()
protected ValueParser getSubkey(String subkey)
subkey
- subkey to search forpublic boolean containsKey(Object key)
containsKey
in interface Map<String,Object>
public boolean containsValue(Object value)
containsValue
in interface Map<String,Object>
public Collection values()
Copyright © 2002–2018 The Apache Software Foundation. All rights reserved.