|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.univocity.api.common.ParameterizedString
public class ParameterizedString
Utility class for handling Strings with parameters. Use set(String, Object) to set a parameter value,
and applyParameterValues() to obtain a result String with the values of all known parameters replaced.
Parameters without values provided will not be replaced, therefore the string "zero/{one}/{two}/{one}", with parameter
"one" set to 27 will evaluate to "zero/27/{two}/27"
| Constructor Summary | |
|---|---|
ParameterizedString(String string)
Creates a new parameterized string with parameter names enclosed within { and } |
|
ParameterizedString(String string,
String openBracket,
String closeBracket)
Creates a new parameterized string with custom open and closing brackets |
|
| Method Summary | |
|---|---|
String |
applyParameterValues()
Applies the parameter values provided using set(String, Object) and returns the resulting String
Unless a default value is provided via getDefaultValue(), parameters without values provided will not
be replaced. |
void |
applyParameterValues(StringBuilder out)
Applies the parameter values provided using set(String, Object) and appends the resulting String
to a given StringBuilder
Unless a default value is provided via getDefaultValue(), parameters without values provided will not
be replaced. |
void |
clearValues()
Clears the values of all parameters. |
ParameterizedString |
clone()
Clones this parameterzied string object. |
boolean |
contains(String parameterName)
Tests whether a given parameter name exists in this parameterized string. |
boolean |
equals(Object o)
|
Object |
get(String parameter)
Returns the value of a given parameter. |
String |
getContentAfterLastParameter()
Returns the content after the last parameter in this parameterized string. |
String |
getContentBeforeFirstParameter()
Returns the content before the first parameter in this parameterized string. |
boolean |
getConvertDefaultValueToNull()
Flag indicating that values parsed from this ParameterizedString will be converted to null, when
equal to the String representation of the value returned by getDefaultValue(). |
Object |
getDefaultValue()
Returns the default value to be used for parameters that have no value associated. |
String |
getFormat(String parameterName)
Returns the format associated with a given parameter |
int |
getIndexAfterLastParameter()
Returns the index after the last parameter in this parameterized string. |
int |
getIndexBeforeFirstParameter()
Returns the index before the first parameter in this parameterized string. |
Set<String> |
getParameters()
Returns a set of all parameter names found in the input string given in the constructor of this class. |
Map<String,Object> |
getParameterValues()
Returns the current parameter names and their values. |
int |
hashCode()
|
Map<String,Object> |
parse(String input)
Parses the String input and extracts the parameter values storing them as regular parameters. |
void |
set(Map<String,?> parametersAndValues)
Sets multiple parameter values |
void |
set(String parameter,
Object value)
Sets a parameter value |
void |
setConvertDefaultValueToNull(boolean convertDefaultValueToNull)
Defines whether values parsed from this ParameterizedString should be converted to null, when
equal to the String representation of the value returned by getDefaultValue(). |
void |
setDefaultValue(Object defaultValue)
Defines a default value to be used for parameters that have no value associated. |
String |
toString()
Returns the original String provided in the constructor of this class, no parameters are replaced |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ParameterizedString(String string,
String openBracket,
String closeBracket)
string - the string with parametersopenBracket - the open bracket (before a parameter name)closeBracket - the close bracket (after a paramter name)public ParameterizedString(String string)
string - the string with parameters| Method Detail |
|---|
public final void set(Map<String,?> parametersAndValues)
throws IllegalArgumentException
parametersAndValues - map of parameter names and thier corresponding values.
IllegalArgumentException - if a parameter name in found in the given map does not exist
public final void set(String parameter,
Object value)
throws IllegalArgumentException
parameter - the parameter namevalue - the parameter value
IllegalArgumentException - if the parameter name does not exist
public final Object get(String parameter)
throws IllegalArgumentException
parameter - the parameter name
IllegalArgumentException - if the parameter name does not existpublic final Map<String,Object> parse(String input)
Parses the String input and extracts the parameter values storing them as regular parameters.
The Map of parameters is returned as a convenience, but parameter values can also be retrieved using:
get(String) - for individual parametersgetParameterValues() - for all of them
input - the input String to be parsed
Map of parameters to their assigned valuespublic final String toString()
String provided in the constructor of this class, no parameters are replaced
toString in class ObjectString with parameterspublic final String applyParameterValues()
set(String, Object) and returns the resulting String
Unless a default value is provided via getDefaultValue(), parameters without values provided will not
be replaced. Therefore the String "zero/{one}/{two}/{one}", with parameter "one" set to 27 will
evaluate to "zero/27/{two}/27"
String with all parameters replaced by their values.public final void applyParameterValues(StringBuilder out)
set(String, Object) and appends the resulting String
to a given StringBuilder
Unless a default value is provided via getDefaultValue(), parameters without values provided will not
be replaced. Therefore the String "zero/{one}/{two}/{one}", with parameter "one" set to 27 will
evaluate to "zero/27/{two}/27"
out - the StringBuilder that will be appended with the result of all parameters replaced by their values.public final Set<String> getParameters()
public final void clearValues()
public final boolean contains(String parameterName)
parameterName - the name of the parameter
true if the parameter name exists in this parameterized string, otherwise false
public final String getFormat(String parameterName)
throws IllegalArgumentException
parameterName - the name of the parameter
String. Returns null if the parameter does not exist or format was not set.
IllegalArgumentException - if the parameter name does not existpublic final ParameterizedString clone()
clone in class Objectpublic final Map<String,Object> getParameterValues()
public final void setDefaultValue(Object defaultValue)
null, in which case the original parameter will appear in the result of
applyParameterValues().
defaultValue - the default value to be used when one or more parameters have no value associated.public final Object getDefaultValue()
null, in which case the original parameter will appear in the result of
applyParameterValues().
public final int getIndexBeforeFirstParameter()
-1 if no parameters exist.public final int getIndexAfterLastParameter()
-1 if no parameters exist.public final String getContentBeforeFirstParameter()
String if no parameters exist.public final String getContentAfterLastParameter()
String if no parameters exist.public final boolean equals(Object o)
equals in class Objectpublic final int hashCode()
hashCode in class Objectpublic final boolean getConvertDefaultValueToNull()
ParameterizedString will be converted to null, when
equal to the String representation of the value returned by getDefaultValue().
true all methods that return values associated with a parameter will return null instead of the specified default value.false all methods that return values associated with a parameter will default value returned by getDefaultValue().
true if default values should be converted to null when reading parameter values, otherwise falsepublic final void setConvertDefaultValueToNull(boolean convertDefaultValueToNull)
ParameterizedString should be converted to null, when
equal to the String representation of the value returned by getDefaultValue().
true all methods that return values associated with a parameter will return null instead of the specified default value.false all methods that return values associated with a parameter will default value returned by getDefaultValue().
convertDefaultValueToNull - flag indicating whether default values should be converted to null when reading parameter values
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||