public class StringUtils extends Object
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
approximatePTransformName(Class<?> clazz)
Returns a name for a PTransform class.
|
static String |
approximateSimpleName(Class<?> clazz)
Returns a simple name for a class.
|
static String |
byteArrayToJsonString(byte[] bytes)
Converts the given array of bytes into a legal JSON string.
|
static int |
getLevenshteinDistance(String s,
String t)
Calculate the Levenshtein distance between two strings.
|
static byte[] |
jsonStringToByteArray(String string)
Converts the given string, encoded using
byteArrayToJsonString(byte[]),
into a byte array. |
public static String byteArrayToJsonString(byte[] bytes)
Uses a simple strategy of converting each byte to a single char, except for non-printable chars, non-ASCII chars, and '%', '\', and '"', which are encoded as three chars in '%xx' format, where 'xx' is the hexadecimal encoding of the byte.
public static byte[] jsonStringToByteArray(String string)
byteArrayToJsonString(byte[]),
into a byte array.IllegalArgumentException - if the argument string is not legalpublic static String approximateSimpleName(Class<?> clazz)
Note: this is non-invertible - the name may be simplified to an extent that it cannot be mapped back to the original class.
This can be used to generate human-readable names. It removes the package and outer classes from the name, and removes common suffixes.
Examples:
some.package.Word.SummaryDoFn -> "Summary"
another.package.PairingFn -> "Pairing"
IllegalArgumentException - if the class is anonymouspublic static String approximatePTransformName(Class<?> clazz)
This can be used to generate human-readable transform names. It removes the package from the name, and removes common suffixes.
It is different than approximateSimpleName:
Examples:
some.package.Word.Summary -> "Word.Summary"
another.package.Pairing.Bound -> "Pairing"
public static int getLevenshteinDistance(String s, String t)
The Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one string into the other.