Package io.pravega.common.util
Class ToStringUtils
- java.lang.Object
-
- io.pravega.common.util.ToStringUtils
-
public class ToStringUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ToStringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcompressToBase64(java.lang.String string)Convert the given string to its compressed base64 representation.static java.lang.StringdecompressFromBase64(java.lang.String base64CompressedString)Get the original string from its compressed base64 representation.static <V> java.lang.StringlistToString(java.util.List<V> list)Transforms a list into a string of the from: "V1,V2,V3" Where the string versions of the key and value are derived from their toString() function.static <K,V>
java.lang.StringmapToString(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 <V> java.util.List<V>stringToList(java.lang.String serialized, java.util.function.Function<java.lang.String,V> valueMaker)Performs the reverse oflistToString(List).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 ofmapToString(Map).
-
-
-
Method Detail
-
mapToString
public 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.- Type Parameters:
K- The type of the keys of the map.V- The type of the values of the map.- Parameters:
map- The map to be serialized to a string- Returns:
- A string representation of the map.
-
stringToMap
public 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 ofmapToString(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.- Type Parameters:
K- The type of the keys of the map.V- The type of the values of the map.- Parameters:
serialized- The serialized form of the map.keyMaker- The constructor for the key objectsvalueMaker- The constructor for the value objects- Returns:
- A map the corresponds to the serialized string.
-
listToString
public static <V> java.lang.String listToString(java.util.List<V> list)
Transforms a list into a string of the from: "V1,V2,V3" Where the string versions of the key and value are derived from their toString() function.- Type Parameters:
V- The type of the values of the list.- Parameters:
list- The list to be serialized to a string- Returns:
- A string representation of the list.
-
stringToList
public static <V> java.util.List<V> stringToList(java.lang.String serialized, java.util.function.Function<java.lang.String,V> valueMaker)Performs the reverse oflistToString(List). It parses a list written in a string form back into a Java list. Note that in order to parse properly, it is important that none of the values that were serialized contain ',' character as this prevents parsing. For this reason it should be noted that this simple format does not support nesting.- Type Parameters:
V- The type of the values of the list.- Parameters:
serialized- The serialized form of the list.valueMaker- The constructor for the value objects- Returns:
- A list that corresponds to the serialized string.
-
compressToBase64
public static java.lang.String compressToBase64(java.lang.String string)
Convert the given string to its compressed base64 representation.- Parameters:
string- String to be compressed to base64.- Returns:
- String Compressed Base64 representation of the input string.
- Throws:
java.lang.NullPointerException- If string is null.
-
decompressFromBase64
public static java.lang.String decompressFromBase64(java.lang.String base64CompressedString)
Get the original string from its compressed base64 representation.- Parameters:
base64CompressedString- Compressed Base64 representation of the string.- Returns:
- The original string.
- Throws:
java.lang.NullPointerException- If base64CompressedString is null.java.lang.IllegalArgumentException- If base64CompressedString is not null, but has a length of zero or if the input is invalid.
-
-