public class PropertyValues
extends java.lang.Object
Constructor | Description |
---|---|
PropertyValues() |
Modifier and Type | Method | Description |
---|---|---|
static void |
escapeKey(java.lang.StringBuilder sb,
java.lang.String key) |
Escapes a maps key value for serialization to a string.
|
static void |
escapeValue(java.lang.StringBuilder sb,
java.lang.String value) |
Escapes a maps value for serialization to a string.
|
static <K extends java.lang.Enum<K>> |
mapToString(java.util.EnumMap<K,java.lang.String> map) |
Converts a map into a string that can be parsed by
stringToMap(String) . |
static <K> java.lang.String |
mapToString(java.util.Map<K,java.lang.String> map) |
Converts a map into a string that can be parsed by
stringToMap(String) . |
static <E extends java.lang.Enum<E>> |
stringToEnumMap(java.lang.Class<E> enumType,
java.lang.String s) |
Parses a string of key/value pairs into an enum map.
|
static <E extends java.lang.Enum<E>> |
stringToEnumMap(java.lang.Class<E> enumType,
java.lang.String s,
boolean convertKeyCase) |
Parses a string of key/value pairs into an enum map.
|
static java.util.Map<java.lang.String,java.lang.String> |
stringToMap(java.lang.String s) |
Parses a string of key/value pairs into a map.
|
public static java.util.Map<java.lang.String,java.lang.String> stringToMap(java.lang.String s)
The key/value pairs are separated by a comma (,
). The key and value are separated by an equals
(=
).
If a key contains a \
or an =
it must be escaped by a preceding \
. Example:
key\==value,\\key=value
.
If a value contains a \
or a ,
it must be escaped by a preceding \
. Example:
key=part1\,part2,key2=value\\other
.
If the value for a key is empty there is no trailing =
after a key the will be null
.
s
- the string to parsenull
or emptypublic static <E extends java.lang.Enum<E>> java.util.EnumMap<E,java.lang.String> stringToEnumMap(java.lang.Class<E> enumType, java.lang.String s)
The key/value pairs are separated by a comma (,
). The key and value are separated by an equals
(=
). The key must be a valid enum value. For convenience the
case of each character will be converted to uppercase and any dashes (-
) will be converted to
underscores (_
).
If a value contains a \
or a ,
it must be escaped by a preceding \
. Example:
key=part1\,part2,key2=value\\other
.
If the value for a key is empty there is no trailing =
after a key the value will be null
.
enumType
- the enum types
- the string to parsenull
or emptypublic static <E extends java.lang.Enum<E>> java.util.EnumMap<E,java.lang.String> stringToEnumMap(java.lang.Class<E> enumType, java.lang.String s, boolean convertKeyCase)
The key/value pairs are separated by a comma (,
). The key and value are separated by an equals
(=
). The key must be a valid enum value. For convenience any
dashes (-
) will be converted to underscores (_
). If convertKeyCase
is set to
true
the case will also be converted to uppercase for each key character.
If a value contains a \
or a ,
it must be escaped by a preceding \
. Example:
key=part1\,part2,key2=value\\other
.
If the value for a key is empty there is no trailing =
after a key the value will be null
.
enumType
- the enum types
- the string to parseconvertKeyCase
- true
if the each character from the key should be converted to uppercase,
otherwise false
to keep the case as isnull
or emptypublic static <K> java.lang.String mapToString(java.util.Map<K,java.lang.String> map)
stringToMap(String)
. Note that if this is an
EnumMap
the mapToString(EnumMap)
will be used and the key will be the
enum name.K
- the type of the keymap
- the map to convert to a stringescapeKey(StringBuilder, String)
,
escapeValue(StringBuilder, String)
public static <K extends java.lang.Enum<K>> java.lang.String mapToString(java.util.EnumMap<K,java.lang.String> map)
stringToMap(String)
. The kwy will be the
enum name.K
- the type of the keymap
- the map to convert to a stringescapeKey(StringBuilder, String)
,
escapeValue(StringBuilder, String)
public static void escapeKey(java.lang.StringBuilder sb, java.lang.String key)
\
or an =
it will
be escaped by a preceding \
. Example: key\=
or \\key
.sb
- the string builder to append the escaped key tokey
- the keypublic static void escapeValue(java.lang.StringBuilder sb, java.lang.String value)
\
or a ,
it will be
escaped by a preceding \
. Example: part1\,part2
or value\\other
.sb
- the string builder to append the escaped value tovalue
- the valueCopyright © 2018. All rights reserved.