public class BinaryStringUtil extends Object
BinaryString
.Modifier and Type | Field and Description |
---|---|
static BinaryString[] |
EMPTY_STRING_ARRAY |
Constructor and Description |
---|
BinaryStringUtil() |
Modifier and Type | Method and Description |
---|---|
static BinaryString |
concat(BinaryString... inputs)
Concatenates input strings together into a single string.
|
static BinaryString |
concat(Iterable<BinaryString> inputs) |
static BinaryString |
concatWs(BinaryString separator,
BinaryString... inputs)
Concatenates input strings together into a single string using the separator.
|
static BinaryString |
concatWs(BinaryString separator,
Iterable<BinaryString> inputs) |
static BinaryString |
hash(BinaryString str,
MessageDigest md)
Calculate the hash value of a given string use
MessageDigest . |
static BinaryString |
hash(BinaryString str,
String algorithm) |
static boolean |
isSpaceString(BinaryString str) |
static BinaryString |
keyValue(BinaryString str,
byte split1,
byte split2,
BinaryString keyName)
Parse target string as key-value string and
return the value matches key name.
|
static BinaryString |
reverse(BinaryString str)
Reverse each character in current string.
|
static String |
safeToString(BinaryString str) |
static BinaryString[] |
splitByWholeSeparatorPreserveAllTokens(BinaryString str,
BinaryString separator)
Splits the provided text into an array, separator string specified.
|
static BinaryString |
substringSQL(BinaryString str,
int pos) |
static BinaryString |
substringSQL(BinaryString str,
int pos,
int length) |
static Boolean |
toBooleanSQL(BinaryString str)
Decide boolean representation of a string.
|
static Byte |
toByte(BinaryString str) |
static Decimal |
toDecimal(BinaryString str,
int precision,
int scale)
Parses this BinaryString to Decimal.
|
static Double |
toDouble(BinaryString str) |
static Float |
toFloat(BinaryString str) |
static Integer |
toInt(BinaryString str)
Parses this BinaryString to Int.
|
static Long |
toLong(BinaryString str)
Parses this BinaryString to Long.
|
static Short |
toShort(BinaryString str) |
static BinaryString |
trim(BinaryString str,
BinaryString trimStr)
Walk each character of current string from both ends, remove the character if it
is in trim string.
|
static BinaryString |
trim(BinaryString str,
boolean leading,
boolean trailing,
BinaryString seek) |
static BinaryString |
trimLeft(BinaryString str) |
static BinaryString |
trimLeft(BinaryString str,
BinaryString trimStr)
Walk each character of current string from left end, remove the character if it
is in trim string.
|
static BinaryString |
trimRight(BinaryString str) |
static BinaryString |
trimRight(BinaryString str,
BinaryString trimStr)
Walk each character of current string from right end, remove the character if it
is in trim string.
|
public static final BinaryString[] EMPTY_STRING_ARRAY
public static BinaryString[] splitByWholeSeparatorPreserveAllTokens(BinaryString str, BinaryString separator)
Splits the provided text into an array, separator string specified.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens.
A null
separator splits on whitespace.
"".splitByWholeSeparatorPreserveAllTokens(*) = [] "ab de fg".splitByWholeSeparatorPreserveAllTokens(null) = ["ab", "de", "fg"] "ab de fg".splitByWholeSeparatorPreserveAllTokens(null) = ["ab", "", "", "de", "fg"] "ab:cd:ef".splitByWholeSeparatorPreserveAllTokens(":") = ["ab", "cd", "ef"] "ab-!-cd-!-ef".splitByWholeSeparatorPreserveAllTokens("-!-") = ["ab", "cd", "ef"]
Note: returned binary strings reuse memory segments from the input str.
separator
- String containing the String to be used as a delimiter,
null
splits on whitespacenull
if null String was inputpublic static Boolean toBooleanSQL(BinaryString str)
public static BinaryString hash(BinaryString str, MessageDigest md)
MessageDigest
.public static BinaryString hash(BinaryString str, String algorithm) throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static Decimal toDecimal(BinaryString str, int precision, int scale)
NumberFormatException
- if the parsing failed.public static Long toLong(BinaryString str)
Note that, in this method we accumulate the result in negative format, and convert it to positive format at the end, if this string is not started with '-'. This is because min value is bigger than max value in digits, e.g. Long.MAX_VALUE is '9223372036854775807' and Long.MIN_VALUE is '-9223372036854775808'.
This code is mostly copied from LazyLong.parseLong in Hive.
public static Integer toInt(BinaryString str)
Note that, in this method we accumulate the result in negative format, and convert it to positive format at the end, if this string is not started with '-'. This is because min value is bigger than max value in digits, e.g. Integer.MAX_VALUE is '2147483647' and Integer.MIN_VALUE is '-2147483648'.
This code is mostly copied from LazyInt.parseInt in Hive.
Note that, this method is almost same as `toLong`, but we leave it duplicated for performance reasons, like Hive does.
public static Short toShort(BinaryString str)
public static Byte toByte(BinaryString str)
public static Double toDouble(BinaryString str)
public static Float toFloat(BinaryString str)
public static BinaryString keyValue(BinaryString str, byte split1, byte split2, BinaryString keyName)
split1
- separator between key-value tuple.split2
- separator between key and value.keyName
- name of the key whose value you want return.public static BinaryString substringSQL(BinaryString str, int pos)
public static BinaryString substringSQL(BinaryString str, int pos, int length)
public static BinaryString concat(BinaryString... inputs)
public static BinaryString concat(Iterable<BinaryString> inputs)
public static BinaryString concatWs(BinaryString separator, BinaryString... inputs)
Concatenates input strings together into a single string using the separator. Returns NULL If the separator is NULL.
Note: CONCAT_WS() does not skip any empty strings, however it does skip any NULL values after the separator. For example, concat_ws(",", "a", null, "c") would yield "a,c".
public static BinaryString concatWs(BinaryString separator, Iterable<BinaryString> inputs)
public static BinaryString reverse(BinaryString str)
public static BinaryString trim(BinaryString str, BinaryString trimStr)
trimStr
- the trim stringpublic static BinaryString trimLeft(BinaryString str)
public static boolean isSpaceString(BinaryString str)
public static BinaryString trimLeft(BinaryString str, BinaryString trimStr)
trimStr
- the trim stringpublic static BinaryString trimRight(BinaryString str)
public static BinaryString trimRight(BinaryString str, BinaryString trimStr)
trimStr
- the trim stringpublic static BinaryString trim(BinaryString str, boolean leading, boolean trailing, BinaryString seek)
public static String safeToString(BinaryString str)
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.