public class ToStringUtils
extends java.lang.Object
| Constructor and Description |
|---|
ToStringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <K,V> java.lang.String |
mapToString(java.util.Map<K,V> map)
Transforms a map into a string of the from:
"K1=V1, K2=V2, K3=V3"
Where the string versions of the key and value are derived from their toString() function.
|
static <K,V> java.util.Map<K,V> |
stringToMap(java.lang.String serialized,
java.util.function.Function<java.lang.String,K> keyMaker,
java.util.function.Function<java.lang.String,V> valueMaker)
Performs the reverse of
mapToString(Map). |
public static <K,V> java.lang.String mapToString(java.util.Map<K,V> map)
K - The type of the keys of the map.V - The type of the values of the map.map - The map to be serialized to a stringpublic static <K,V> java.util.Map<K,V> stringToMap(java.lang.String serialized,
java.util.function.Function<java.lang.String,K> keyMaker,
java.util.function.Function<java.lang.String,V> valueMaker)
mapToString(Map). It parses a map written in a string form
back into a Java map.
Note that in order to parse properly, it is important that none the keys or values that
were serialized contain '=' or ',' characters as this prevents parsing. For this reason it
should be noted that this simple format does not support nesting.K - The type of the keys of the map.V - The type of the values of the map.serialized - The serialized form of the map.keyMaker - The constructor for the key objectsvalueMaker - The constructor for the value objects