Class XChars
public final class XChars extends Object
-
Constructor Summary
Constructors Constructor Description XChars()
-
Method Summary
Modifier and Type Method Description static VarString
addSystemString(Object instance, VarString vs)
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 VarString
assembleNewLinedTabbed(VarString vs, CharSequence... elements)
static VarString
assembleSeparated(VarString vs, char separator, CharSequence... elements)
static String
asString(char c)
This method does intentionally not use the pseudo-constructor naming pattern since it does not create new instances ofString
.static String
asString(char... chars)
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[] data, char c)
static boolean
contains(char[] data, int dataOffset, int dataLength, char c)
static boolean
contains(char[] subject, int subjectOffset, int subjectLength, char[] sample, int sampleOffset, int sampleLength)
static boolean
contains(String[] strings, String subject)
static boolean
contains(String s, char c)
static String
convertUnderscoresToCamelCase(String parameterName)
static VarString
convertUnderscoresToCamelCase(VarString vs, String s)
static int
count(char[] input, int startIndex, int boundIndex, char c)
static int
count(char[] data, int dataOffset, int dataCount, char[] subject, int subjectOffset, int subjectCount)
static int
countCharacter(String data, char c)
static int
countCodePoint(String data, int codePoint)
static String
createMedialCapitalsString(String... elements)
static Charset
defaultJvmCharset()
Alias forCharset.defaultCharset()
, which returns sometimes the one thing and sometimes another.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 String
mathRangeExcExc(double lowerBound, double upperBound)
static String
mathRangeExcExc(long lowerBound, long upperBound)
static String
mathRangeExcExc(String lowerBound, String upperBound)
static String
mathRangeExcInc(double lowerBound, double maximum)
static String
mathRangeExcInc(long lowerBound, long maximum)
static String
mathRangeExcInc(String lowerBound, String maximum)
static String
mathRangeIncExc(double minimum, double upperBound)
static String
mathRangeIncExc(long minimum, long upperBound)
static String
mathRangeIncExc(String minimum, String upperBound)
static String
mathRangeIncInc(double minimum, double maximum)
static String
mathRangeIncInc(long minimum, long maximum)
static String
mathRangeIncInc(String minimum, String maximum)
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 char
randomReadable_char()
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 int
shortStringLength()
Arbitrary threshold of 1000 to discrimate "short" strings from "long" strings.
The rationale behind that is that "short" strings usually allow for simpler and faster algorithms, which become inefficient on larger strings.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[]
splitSimple(String s, String separator)
static <C extends Consumer<? super String>>
CsplitSimple(String s, String separator, C collector)
static Charset
standardCharset()
ReturnsStandardCharsets.UTF_8
, because any other one out there is nonsense as a standard.static String
String(boolean value)
static String
String(byte value)
static String
String(byte[] chars)
static String
String(byte[] chars, int offset, int length)
static String
String(byte[] chars, int offset, int length, Charset charset)
static String
String(byte[] chars, Charset charset)
static String
String(char value)
static String
String(char[] chars)
static String
String(char[] chars, int offset, int length)
static String
String(double value)
static String
String(float value)
static String
String(int value)
static String
String(long value)
static String
String(short value)
static String
String(ByteBuffer chars)
static String
String(ByteBuffer chars, int offset, int length)
static String
String(ByteBuffer chars, int offset, int length, Charset charset)
static String
String(ByteBuffer chars, Charset charset)
static StringBuffer
StringBuffer(VarString vs)
static StringBuffer
StringBuffer(VarString vs, int offset, int length)
static StringBuilder
StringBuilder(VarString vs)
static StringBuilder
StringBuilder(VarString vs, int offset, int length)
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
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 Charset
utf8()
It's UTF-8!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.
-
Constructor Details
-
XChars
public XChars()
-
-
Method Details
-
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) -
shortStringLength
public static final int shortStringLength()Arbitrary threshold of 1000 to discrimate "short" strings from "long" strings.
The rationale behind that is that "short" strings usually allow for simpler and faster algorithms, which become inefficient on larger strings. For example a two-pass processing of a splitting algorithm.- Returns:
-
utf8
It's UTF-8!- Returns:
StandardCharsets.UTF_8
-
standardCharset
ReturnsStandardCharsets.UTF_8
, because any other one out there is nonsense as a standard.- Returns:
java.nio.charset.Charset.forName("UTF-8")
.
-
defaultJvmCharset
Alias forCharset.defaultCharset()
, which returns sometimes the one thing and sometimes another. It is strongly advised to use a reliableCharset
querying method, likeutf8()
, which also is the only reasonable choice for thestandardCharset()
.- Returns:
Charset.defaultCharset()
-
validateIndex
public static final void validateIndex(char[] chars, int index) -
validateRange
public static final void validateRange(char[] chars, int offset, int length) -
isEqual
-
equals
-
equals
public static final boolean equals(char[] chars1, int offset1, char[] chars2, int offset2, int length) -
isEqualIgnoreCase
-
toHexadecimal
- 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[] input, int startIndex, int boundIndex, char c) -
count
public static final int count(char[] data, int dataOffset, int dataCount, char[] subject, int subjectOffset, int subjectCount) -
hasContent
-
hasNoContent
-
hasContent
-
hasNoContent
-
asString
This method does intentionally not use the pseudo-constructor naming pattern since it does not create new instances ofString
. Instead, it returns a constant instance of an intrinsic look-up table. -
asString
-
upperCaseFirstChar
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.
-
lowerCaseFirstChar
-
concat
public static final char[] concat(char[]... arrays) -
appendArraySeperated
-
appendArraySeperated
-
toCharArray
-
toCharArray
-
toCharArray
-
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
-
commonSubstringLength
public static final int commonSubstringLength(char[] a, char[] b) -
longestCommonSubstring
-
longestCommonSubstring
public static final char[] longestCommonSubstring(char[] a, char[] b) -
substring
public static final char[] substring(char[] string, int offset, int bound) -
convertUnderscoresToCamelCase
-
convertUnderscoresToCamelCase
-
longestCommonPrefixLength
-
longestCommonSuffixLength
-
longestCommonSuffix
-
longestCommonPrefix
-
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) -
padLeft
-
padRight
-
padLeft
-
padRight
-
padLeft0
-
padRight0
-
parseChar
Parses the char escape sequence Strings "\n" etc. (wihtout the "") to the singel char value represented by those strings.- Parameters:
s
-
-
escapeChar
-
escapeChar
-
createMedialCapitalsString
-
ensureCharAtEnd
-
toSingleLine
-
padSpace
-
concat
-
notEmpty
-
isEmpty
-
iterate
-
iterate
-
iterate
-
iterate
-
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
-
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) -
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
String
-
StringBuilder
-
StringBuilder
-
StringBuffer
-
StringBuffer
-
readChars
-
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)
-
splitSimple
-
splitSimple
-
trimToString
Creates aString
instance with trimmed content directly from a character sequence without unnecessary intermediate instances.- Parameters:
input
-lowerOffset
-length
-
-
trim
CallsString.trim()
on a non-null argument, returnsnull
otherwise. (this is nothing but a staticString.trim()
) -
parseTo_intArray
-
parseToIntegerArray
-
assembleNewLinedTabbed
-
assembleSeparated
public static final VarString assembleSeparated(VarString vs, char separator, 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
-
contains
-
contains
-
contains
public static final boolean contains(char[] subject, int subjectOffset, int subjectLength, char[] sample, int sampleOffset, int sampleLength) -
contains
public static final boolean contains(char[] data, char c) -
contains
public static final boolean contains(char[] data, int dataOffset, int dataLength, char c) -
systemString
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.
-
addSystemString
-
nonNullString
-
valueString
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)
-
trimEmptyToNull
-
assembleCautiously
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
-
applies
-
isDigit
public static boolean isDigit(char c) -
randomReadable_char
public static char randomReadable_char() -
countCharacter
-
countCodePoint
-
mathRangeIncInc
-
mathRangeIncExc
-
mathRangeExcInc
-
mathRangeExcExc
-
mathRangeIncInc
-
mathRangeIncExc
-
mathRangeExcInc
-
mathRangeExcExc
-
mathRangeIncInc
-
mathRangeIncExc
-
mathRangeExcInc
-
mathRangeExcExc
-