Class XChars
- java.lang.Object
-
- one.microstream.chars.XChars
-
public final class XChars extends Object
Static util class with character operation algorithms missing in or significantly superior to those in JDK.
-
-
Constructor Summary
Constructors Constructor Description XChars()
-
Method Summary
Modifier and Type Method Description static char[]
append(char[] string, char c)
static char[]
append(char[] a, char[] b)
static char[]
append(char c, char[] string)
static VarString
appendArraySeperated(VarString vc, char separator, Object... elements)
static VarString
appendArraySeperated(VarString vs, String separator, Object... elements)
static boolean
applies(CharSequence chars, int startIndex, _charPredicate predicate)
static boolean
applies(CharSequence chars, _charPredicate predicate)
static VarString
assembleCautiously(VarString vs, Object object)
Assembles the passed instance "cautiously" in the sense that only types recognizable viaXTypes.isValueType(Object)
get assembled using theirObject.toString()
method, while all others are assembled usingsystemString(Object)
(which behaves identical to the actual implementation ofObject.toString()
).static void
assembleNewLinedTabbed(VarString vs, CharSequence... elements)
static int
commonPrefixLength(char[] a, char[] b)
static int
commonSubstringLength(char[] a, char[] b)
static int
commonSuffixLength(char[] a, char[] b)
static char[]
concat(char[]... arrays)
static String
concat(char separator, Object... parts)
static boolean
contains(char[] subject, int subjectOffset, int subjectLength, char[] sample, int sampleOffset, int sampleLength)
static boolean
contains(String[] strings, String subject)
static String
convertUnderscoresToCamelCase(String parameterName)
static VarString
convertUnderscoresToCamelCase(VarString vs, String s)
static int
count(char[] haystack, int haystackOffset, int haystackCount, char needle)
static int
count(char[] data, int dataOffset, int dataCount, char[] subject, int subjectOffset, int subjectCount)
static String
createMedialCapitalsString(String... elements)
static String
ensureCharAtEnd(String s, char c)
static boolean
equals(char[] chars1, int offset1, char[] chars2, int offset2, int length)
static boolean
equals(String string, char[] chars, int offset)
static String
escapeChar(char c)
static VarString
escapeChar(VarString vc, char c)
static boolean
hasContent(CharSequence s)
static boolean
hasContent(String s)
static int
hashCode(char[] chars, int offset, int length)
This method rebuilds theString
hashing algorithm as the JDK guys forgot as usual to make their stuff professionally modular.static boolean
hasNoContent(CharSequence s)
static boolean
hasNoContent(String s)
static int
indexOf(char[] data, char c)
static int
indexOf(char[] data, int dataLength, char[] subject)
static int
indexOf(char[] source, int sourceCount, char[] target, int targetCount, int fromIndex)
static int
indexOf(char[] data, int offset, int length, char c)
static int
indexOf(char[] data, int dataOffset, int dataLength, char[] chars)
static int
indexOf(char[] source, int sourceOffset, int sourceCount, char[] target, int targetOffset, int targetCount, int fromIndex)
static long
internalParse_longLiteral(char[] input, int offset, int length)
Specialcase higher performance implementation of decimal integer literal parsing.static boolean
intersects(char[] chars1, char[] chars2)
Returnstrue
if the two given character arrays have at least one character in common.static boolean
isDigit(char c)
static boolean
isEmpty(CharSequence cs)
static boolean
isEqual(String s1, String s2)
static boolean
isEqualIgnoreCase(String s1, String s2)
static boolean
isNonWhitespace(char c)
static boolean
isWhitespace(char c)
static void
iterate(char[] chars, int offset, int length, _charProcedure iterator)
static void
iterate(char[] chars, _charProcedure iterator)
static void
iterate(CharSequence chars, _charProcedure iterator)
static void
iterate(String chars, _charProcedure iterator)
static char[]
longestCommonPrefix(char[] a, char[] b)
static String
longestCommonPrefix(String a, String b)
static int
longestCommonPrefixLength(String a, String b)
static char[]
longestCommonSubstring(char[] a, char[] b)
static String
longestCommonSubstring(String a, String b)
static int
longestCommonSubstringLength(String a, String b)
static char[]
longestCommonSuffix(char[] a, char[] b)
static String
longestCommonSuffix(String a, String b)
static int
longestCommonSuffixLength(String a, String b)
static String
lowerCaseFirstChar(String s)
static int
maxCharCount_boolean()
static int
maxCharCount_byte()
static int
maxCharCount_char()
static int
maxCharCount_double()
static int
maxCharCount_float()
static int
maxCharCount_int()
static int
maxCharCount_long()
static int
maxCharCount_short()
static String
nonNullString(Object object)
static <C extends CharSequence>
CnotEmpty(C charSequence)
static String
padLeft(String s, int totalLength)
static String
padLeft(String s, int totalLength, char paddingChar)
static String
padLeft0(String s, int totalLength)
static String
padRight(String s, int totalLength)
static String
padRight(String s, int totalLength, char paddingChar)
static String
padRight0(String s, int totalLength)
static String
padSpace(String s, int chars)
static byte
parse_byteDecimal(char[] input)
static byte
parse_byteDecimal(char[] input, int offset, int length)
static double
parse_double(char[] input, int offset, int length)
static float
parse_float(char[] input, int offset, int length)
static int
parse_intLiteral(char[] input)
static int
parse_intLiteral(char[] input, int offset, int length)
static long
parse_longDecimal(char[] input)
static long
parse_longDecimal(char[] input, int offset, int length)
static short
parse_shortDecimal(char[] input)
static short
parse_shortDecimal(char[] input, int offset, int length)
static char
parseChar(String s)
Parses the char escape sequence Strings "\n" etc.static int[]
parseTo_intArray(String... intStrings)
static Integer[]
parseToIntegerArray(String... intStrings)
static int
put(boolean value, char[] target, int offset)
static int
put(byte value, char[] target, int offset)
static int
put(char[] value, char[] target, int offset)
static int
put(double value, char[] target, int offset)
static int
put(float value, char[] target, int offset)
static int
put(int value, char[] target, int offset)
static int
put(long value, char[] target, int offset)
static int
put(short value, char[] target, int offset)
static int
put(String s, char[] target, int offset)
static int
putFalse(char[] target, int offset)
static int
putHexDec(byte value, char[] target, int offset)
static int
putNull(char[] target, int offset)
static int
putTrue(char[] target, int offset)
static VarByte
readAllBytesFromInputStream(InputStream inputStream)
static VarByte
readAllBytesFromInputStream(VarByte bytes, InputStream inputStream)
static char[]
readChars(String s)
static String
readStringFromInputStream(InputStream inputStream, Charset charset)
static int
replaceFirst(char[] chars, int offset, int length, char sample, char replacement)
static <C extends Consumer<String>>
CsplitAndTrimToStrings(char[] input, char separator, C collector)
High-performance implementation of the very common case to split a character sequence by a single character and trim all elements.static <C extends Consumer<String>>
CsplitAndTrimToStrings(String input, char separator, C collector)
High-performance implementation of the very common case to split a string by a single character and trim all elements.static String
string(char c)
static String
String(char... chars)
static char[]
substring(char[] string, int offset, int bound)
static String
systemString(Object instance)
Utility method that replicates the JVM's intrinsic system string as defined inObject.toString()
.static int
to_int(char digit)
static char[][]
toArrays(XGettingSequence<String> strings)
static char[]
toCharArray(CharSequence c)
static char[]
toCharArray(StringBuffer asb)
static char[]
toCharArray(StringBuilder asb)
static char
toHexadecimal(int b)
static String
toSingleLine(String multiLineString, String lineBreakReplacement)
static String
toString(boolean value)
static String
toString(byte value)
static String
toString(char value)
static String
toString(double value)
static String
toString(float value)
static String
toString(int value)
static String
toString(long value)
static String
toString(short value)
static StringBuffer
toStringBuffer(VarString vs)
static StringBuffer
toStringBuffer(VarString vs, int offset, int length)
static StringBuilder
toStringBuilder(VarString vs)
static StringBuilder
toStringBuilder(VarString vs, int offset, int length)
static String
trim(String s)
CallsString.trim()
on a non-null argument, returnsnull
otherwise.static String
trimEmptyToNull(String s)
static String
trimToString(char[] input, int lowerOffset, int length)
Creates aString
instance with trimmed content directly from a character sequence without unnecessary intermediate instances.static byte
uncheckedParse_byteDecimal(char[] input, int offset, int length)
static int
uncheckedParse_intLiteral(char[] input, int offset, int length)
static long
uncheckedParse_longLiteral(char[] input, int offset, int length)
static short
uncheckedParse_shortDecimal(char[] input, int offset, int length)
static String
upperCaseFirstChar(String s)
Ensures that the first character of the passedString
is in upper case.static void
validateIndex(char[] chars, int index)
static void
validateRange(char[] chars, int offset, int length)
static String
valueString(Object value)
Returnsvalue.toString()
if the passed value is not null, otherwise null.
-
-
-
Method Detail
-
maxCharCount_byte
public static final int maxCharCount_byte()
-
maxCharCount_boolean
public static final int maxCharCount_boolean()
-
maxCharCount_short
public static final int maxCharCount_short()
-
maxCharCount_char
public static final int maxCharCount_char()
-
maxCharCount_int
public static final int maxCharCount_int()
-
maxCharCount_float
public static final int maxCharCount_float()
-
maxCharCount_long
public static final int maxCharCount_long()
-
maxCharCount_double
public static final int maxCharCount_double()
-
isWhitespace
public static final boolean isWhitespace(char c)
-
isNonWhitespace
public static final boolean isNonWhitespace(char c)
-
validateIndex
public static final void validateIndex(char[] chars, int index)
-
validateRange
public static final void validateRange(char[] chars, int offset, int length)
-
equals
public static final boolean equals(String string, char[] chars, int offset)
-
equals
public static final boolean equals(char[] chars1, int offset1, char[] chars2, int offset2, int length)
-
toHexadecimal
public static final char toHexadecimal(int b) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
indexOf
public static final int indexOf(char[] data, char c)
-
indexOf
public static final int indexOf(char[] data, int offset, int length, char c)
-
indexOf
public static final int indexOf(char[] source, int sourceOffset, int sourceCount, char[] target, int targetOffset, int targetCount, int fromIndex)
-
readAllBytesFromInputStream
public static final VarByte readAllBytesFromInputStream(VarByte bytes, InputStream inputStream) throws IOException
- Throws:
IOException
-
readAllBytesFromInputStream
public static final VarByte readAllBytesFromInputStream(InputStream inputStream) throws IOException
- Throws:
IOException
-
readStringFromInputStream
public static final String readStringFromInputStream(InputStream inputStream, Charset charset) throws IOException
- Throws:
IOException
-
indexOf
public static final int indexOf(char[] data, int dataLength, char[] subject)
-
indexOf
public static final int indexOf(char[] data, int dataOffset, int dataLength, char[] chars)
-
indexOf
public static final int indexOf(char[] source, int sourceCount, char[] target, int targetCount, int fromIndex)
-
replaceFirst
public static final int replaceFirst(char[] chars, int offset, int length, char sample, char replacement)
-
count
public static final int count(char[] haystack, int haystackOffset, int haystackCount, char needle)
-
count
public static final int count(char[] data, int dataOffset, int dataCount, char[] subject, int subjectOffset, int subjectCount)
-
hasContent
public static final boolean hasContent(CharSequence s)
-
hasNoContent
public static final boolean hasNoContent(CharSequence s)
-
hasContent
public static final boolean hasContent(String s)
-
hasNoContent
public static final boolean hasNoContent(String s)
-
string
public static final String string(char c)
-
String
public static final String String(char... chars)
-
upperCaseFirstChar
public static final String upperCaseFirstChar(String s)
Ensures that the first character of the passedString
is in upper case.If the passed
String
isnull
, has a length of 0 or already has an upper case first character, it is returned. Otherwise, the first character of the passedString
is transformed to upper case and concatenated with the rest of the passedString
into a newString
instance.- Parameters:
s
- theString
for which the first character shall be ensured to be upper case.- Returns:
- a string equalling s with its first character being guaranteed to be upper case.
-
concat
public static final char[] concat(char[]... arrays)
-
appendArraySeperated
public static final VarString appendArraySeperated(VarString vs, String separator, Object... elements)
-
appendArraySeperated
public static final VarString appendArraySeperated(VarString vc, char separator, Object... elements)
-
toCharArray
public static final char[] toCharArray(CharSequence c)
-
toCharArray
public static final char[] toCharArray(StringBuilder asb)
-
toCharArray
public static final char[] toCharArray(StringBuffer asb)
-
intersects
public static final boolean intersects(char[] chars1, char[] chars2)
Returnstrue
if the two given character arrays have at least one character in common.- Parameters:
chars1
-chars2
-- Returns:
true
if the two given character arrays intersect each other.
-
append
public static final char[] append(char c, char[] string)
-
append
public static final char[] append(char[] string, char c)
-
append
public static final char[] append(char[] a, char[] b)
-
longestCommonSubstringLength
public static final int longestCommonSubstringLength(String a, String b)
-
commonSubstringLength
public static final int commonSubstringLength(char[] a, char[] b)
-
longestCommonSubstring
public static final char[] longestCommonSubstring(char[] a, char[] b)
-
substring
public static final char[] substring(char[] string, int offset, int bound)
-
convertUnderscoresToCamelCase
public static final String convertUnderscoresToCamelCase(String parameterName)
-
convertUnderscoresToCamelCase
public static final VarString convertUnderscoresToCamelCase(VarString vs, String s)
-
commonPrefixLength
public static final int commonPrefixLength(char[] a, char[] b)
-
commonSuffixLength
public static final int commonSuffixLength(char[] a, char[] b)
-
longestCommonSuffix
public static final char[] longestCommonSuffix(char[] a, char[] b)
-
longestCommonPrefix
public static final char[] longestCommonPrefix(char[] a, char[] b)
-
parseChar
public static final char parseChar(String s)
Parses the char escape sequence Strings "\n" etc. (wihtout the "") to the singel char value represented by those strings.- Parameters:
s
-
-
escapeChar
public static final String escapeChar(char c)
-
createMedialCapitalsString
public static final String createMedialCapitalsString(String... elements)
-
toSingleLine
public static final String toSingleLine(String multiLineString, String lineBreakReplacement)
-
notEmpty
public static final <C extends CharSequence> C notEmpty(C charSequence)
-
isEmpty
public static final boolean isEmpty(CharSequence cs)
-
iterate
public static final void iterate(CharSequence chars, _charProcedure iterator)
-
iterate
public static final void iterate(String chars, _charProcedure iterator)
-
iterate
public static final void iterate(char[] chars, _charProcedure iterator)
-
iterate
public static final void iterate(char[] chars, int offset, int length, _charProcedure iterator)
-
put
public static final int put(byte value, char[] target, int offset)
-
putHexDec
public static final int putHexDec(byte value, char[] target, int offset)
-
put
public static final int put(boolean value, char[] target, int offset)
-
put
public static final int put(short value, char[] target, int offset)
-
put
public static final int put(int value, char[] target, int offset)
-
put
public static final int put(float value, char[] target, int offset)
-
put
public static final int put(long value, char[] target, int offset)
-
put
public static final int put(double value, char[] target, int offset)
-
put
public static final int put(String s, char[] target, int offset)
-
put
public static final int put(char[] value, char[] target, int offset)
-
putNull
public static final int putNull(char[] target, int offset)
-
putTrue
public static final int putTrue(char[] target, int offset)
-
putFalse
public static final int putFalse(char[] target, int offset)
-
toString
public static final String toString(byte value)
-
toString
public static final String toString(boolean value)
-
toString
public static final String toString(short value)
-
toString
public static final String toString(char value)
-
toString
public static final String toString(int value)
-
toString
public static final String toString(float value)
-
toString
public static final String toString(long value)
-
toString
public static final String toString(double value)
-
toStringBuilder
public static final StringBuilder toStringBuilder(VarString vs)
-
toStringBuilder
public static final StringBuilder toStringBuilder(VarString vs, int offset, int length)
-
toStringBuffer
public static final StringBuffer toStringBuffer(VarString vs)
-
toStringBuffer
public static final StringBuffer toStringBuffer(VarString vs, int offset, int length)
-
readChars
public static final char[] readChars(String s)
-
hashCode
public static final int hashCode(char[] chars, int offset, int length)
This method rebuilds theString
hashing algorithm as the JDK guys forgot as usual to make their stuff professionally modular.Returns a hash code for the passed character range. The hash code is computed as
usings[0]*31^(n - 1) + s[1]*31^(n-2) + ... + s[n - 1]
int
arithmetic, wheres[i]
is the ith character counted from the given offset,n
is the length and^
indicates exponentiation. The hash value of an empty range is zero.- Returns:
- a hash code value for this object.
- See Also:
String.hashCode()
-
splitAndTrimToStrings
public static final <C extends Consumer<String>> C splitAndTrimToStrings(String input, char separator, C collector)
High-performance implementation of the very common case to split a string by a single character and trim all elements.- Parameters:
input
-separator
-- See Also:
trimToString(char[],int,int)
-
splitAndTrimToStrings
public static final <C extends Consumer<String>> C splitAndTrimToStrings(char[] input, char separator, C collector)
High-performance implementation of the very common case to split a character sequence by a single character and trim all elements.- Parameters:
input
-separator
-- See Also:
trimToString(char[],int,int)
-
trimToString
public static final String trimToString(char[] input, int lowerOffset, int length)
Creates aString
instance with trimmed content directly from a character sequence without unnecessary intermediate instances.- Parameters:
input
-lowerOffset
-length
-
-
trim
public static String trim(String s)
CallsString.trim()
on a non-null argument, returnsnull
otherwise. (this is nothing but a staticString.trim()
)
-
parseTo_intArray
public static final int[] parseTo_intArray(String... intStrings)
-
assembleNewLinedTabbed
public static final void assembleNewLinedTabbed(VarString vs, CharSequence... elements)
-
parse_byteDecimal
public static final byte parse_byteDecimal(char[] input)
-
parse_shortDecimal
public static final short parse_shortDecimal(char[] input)
-
parse_intLiteral
public static final int parse_intLiteral(char[] input)
-
parse_longDecimal
public static final long parse_longDecimal(char[] input)
-
parse_byteDecimal
public static final byte parse_byteDecimal(char[] input, int offset, int length)
-
parse_shortDecimal
public static final short parse_shortDecimal(char[] input, int offset, int length)
-
parse_intLiteral
public static final int parse_intLiteral(char[] input, int offset, int length)
-
parse_longDecimal
public static final long parse_longDecimal(char[] input, int offset, int length)
-
parse_float
public static final float parse_float(char[] input, int offset, int length)
-
parse_double
public static final double parse_double(char[] input, int offset, int length)
-
uncheckedParse_byteDecimal
public static final byte uncheckedParse_byteDecimal(char[] input, int offset, int length)
-
uncheckedParse_shortDecimal
public static final short uncheckedParse_shortDecimal(char[] input, int offset, int length)
-
uncheckedParse_intLiteral
public static final int uncheckedParse_intLiteral(char[] input, int offset, int length)
-
uncheckedParse_longLiteral
public static final long uncheckedParse_longLiteral(char[] input, int offset, int length)
-
internalParse_longLiteral
public static final long internalParse_longLiteral(char[] input, int offset, int length)
Specialcase higher performance implementation of decimal integer literal parsing. Because as usual, the JDK implementation strategies are not acceptable when dealing with non-trivial amounts of data. Properly executed performance tests (large loop sizes, averages, nanosecond precision, etc.) showed that this algorithms is more than twice as fast as the one used in JDK (average of ~33µs vs ~75µs for long literals on same machine with measuring overhead of ~1.5µs)- Parameters:
input
-offset
-length
-
-
to_int
public static final int to_int(char digit)
-
toArrays
public static final char[][] toArrays(XGettingSequence<String> strings)
-
contains
public static final boolean contains(char[] subject, int subjectOffset, int subjectLength, char[] sample, int sampleOffset, int sampleLength)
-
systemString
public static String systemString(Object instance)
Utility method that replicates the JVM's intrinsic system string as defined inObject.toString()
. (It's funny how much functionality is missing in the JDK API).- Parameters:
instance
- the instance whose system string shall be generated.- Returns:
- the system string for the passed instance.
-
valueString
public static String valueString(Object value)
Returnsvalue.toString()
if the passed value is not null, otherwise null.Note that this is a different behavior than
String.valueOf(Object)
has, as the latter returns the string"null"
for a passed null reference. The latter is merely an output helper method, albeit clumsily named and placed as if it were a general utility method. THIS method here is the far more useful general utility method.The behavior of this method is needed for example for converting values in a generic data structure (e.g. a Object[] array) to string values but have the actual values, including null(information about a missing value), maintained.
- Parameters:
value
- the value to be projected to its string representation if not null.- Returns:
- a string representation of an actual passed value or a transient null.
- See Also:
Object.toString()
,String.valueOf(Object)
-
assembleCautiously
public static final VarString assembleCautiously(VarString vs, Object object)
Assembles the passed instance "cautiously" in the sense that only types recognizable viaXTypes.isValueType(Object)
get assembled using theirObject.toString()
method, while all others are assembled usingsystemString(Object)
(which behaves identical to the actual implementation ofObject.toString()
).- Parameters:
vs
- theVarString
instance to hold the assembled string.object
- the instance to be assembled "cautiously" as described above.- Returns:
- the passed vs instance (method-chaining viable).
- See Also:
VarString.add(Object,java.util.function.BiConsumer)
,XTypes.isValueType(Object)
,Object.toString()
,systemString(Object)
-
applies
public static final boolean applies(CharSequence chars, _charPredicate predicate)
-
applies
public static final boolean applies(CharSequence chars, int startIndex, _charPredicate predicate)
-
isDigit
public static boolean isDigit(char c)
-
-