Top Description Fields Constructors Methods
org.jboss.logmanager

public Class PropertyValues

extends Object
Class Inheritance
Annotations
@SuppressWarnings:WeakerAccess
Imports
java.util.Collections, .EnumMap, .Iterator, .LinkedHashMap, .Map

A utility for converting objects into strings and strings into objects for storage in logging configurations.
Author
James R. Perkins

Field Summary

Modifier and TypeField and Description
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
escapeKey(final StringBuilder
the string builder to append the escaped key to
sb
,
final String
the key
key
)

Escapes a maps key value for serialization to a string.

public static void
escapeValue(final StringBuilder
the string builder to append the escaped value to
sb
,
final String
the value
value
)

Escapes a maps value for serialization to a string.

public static <
the type of the key
K
>
String

Returns:

a string value for that map that can be used for configuration properties
mapToString
(final Map<K, String>
the map to convert to a string
map
)

Converts a map into a string that can be parsed by stringToMap(String).

public static <
the type of the key
K extends Enum<K>
>
String

Returns:

a string value for that map that can be used for configuration properties
mapToString
(final EnumMap<K, String>
the map to convert to a string
map
)

Converts a map into a string that can be parsed by stringToMap(String).

public static <E extends Enum<E>> EnumMap<E, String>

Returns:

a map of the key value pairs or an empty map if the string is null or empty
stringToEnumMap
(final Class<E>
the enum type
enumType
,
final String
the string to parse
s
)

Parses a string of key/value pairs into an enum map.

public static <E extends Enum<E>> EnumMap<E, String>

Returns:

a map of the key value pairs or an empty map if the string is null or empty
stringToEnumMap
(final Class<E>
the enum type
enumType
,
final String
the string to parse
s
,
final boolean
true if the each character from the key should be converted to uppercase, otherwise false to keep the case as is
convertKeyCase
)

Parses a string of key/value pairs into an enum map.

public static Map<String, String>

Returns:

a map of the key value pairs or an empty map if the string is null or empty
stringToMap
(final String
the string to parse
s
)

Parses a string of key/value pairs into a map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

KEYback to summary
private static final int KEY
VALUEback to summary
private static final int VALUE

Constructor Detail

PropertyValuesback to summary
public PropertyValues()

Method Detail

escapeKeyback to summary
public static void escapeKey(final StringBuilder sb, final String key)

Escapes a maps key value for serialization to a string. If the key contains a \ or an = it will be escaped by a preceding \. Example: key\= or \\key.

Parameters
sb:StringBuilder

the string builder to append the escaped key to

key:String

the key

escapeValueback to summary
public static void escapeValue(final StringBuilder sb, final String value)

Escapes a maps value for serialization to a string. If a value contains a \ or a , it will be escaped by a preceding \. Example: part1\,part2 or value\\other.

Parameters
sb:StringBuilder

the string builder to append the escaped value to

value:String

the value

mapToStringback to summary
public static <K> String mapToString(final Map<K, String> map)

Converts a map into a string that can be parsed by stringToMap(String). Note that if this is an EnumMap the mapToString(EnumMap) will be used and the key will be the enum name.

Parameters
<K>
the type of the key
map:Map<K, String>

the map to convert to a string

Returns:String

a string value for that map that can be used for configuration properties

Annotations
@SuppressWarnings:unchecked
See Also
escapeKey(StringBuilder, String), escapeValue(StringBuilder, String)
mapToStringback to summary
public static <K extends Enum<K>> String mapToString(final EnumMap<K, String> map)

Converts a map into a string that can be parsed by stringToMap(String). The kwy will be the enum name.

Parameters
<K>
the type of the key
map:EnumMap<K, String>

the map to convert to a string

Returns:String

a string value for that map that can be used for configuration properties

See Also
escapeKey(StringBuilder, String), escapeValue(StringBuilder, String)
stringToEnumMapback to summary
public static <E extends Enum<E>> EnumMap<E, String> stringToEnumMap(final Class<E> enumType, final String s)

Parses a string of key/value pairs into an enum map.

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.

Parameters
enumType:Class<E>

the enum type

s:String

the string to parse

Returns:EnumMap<E, String>

a map of the key value pairs or an empty map if the string is null or empty

stringToEnumMapback to summary
public static <E extends Enum<E>> EnumMap<E, String> stringToEnumMap(final Class<E> enumType, final String s, final boolean convertKeyCase)

Parses a string of key/value pairs into an enum map.

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.

Parameters
enumType:Class<E>

the enum type

s:String

the string to parse

convertKeyCase:boolean

true if the each character from the key should be converted to uppercase, otherwise false to keep the case as is

Returns:EnumMap<E, String>

a map of the key value pairs or an empty map if the string is null or empty

Annotations
@SuppressWarnings:SameParameterValue
stringToMapback to summary
public static Map<String, String> stringToMap(final String s)

Parses a string of key/value pairs into a map.

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.

Parameters
s:String

the string to parse

Returns:Map<String, String>

a map of the key value pairs or an empty map if the string is null or empty