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.
  • 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 discriminate "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:
      1000
    • utf8

      public static final Charset utf8()
      It's UTF-8!
      Returns:
      StandardCharsets.UTF_8
    • standardCharset

      public static final Charset standardCharset()
      Returns:
      java.nio.charset.Charset.forName("UTF-8").
    • defaultJvmCharset

      public static final Charset defaultJvmCharset()
      Alias for Charset.defaultCharset(), which returns sometimes the one thing and sometimes another. It is strongly advised to use a reliable Charset querying method, like UTF-8, which also is the only reasonable choice for the standard charset.
      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

      public static final boolean isEqual​(String s1, String s2)
    • 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)
    • isEqualIgnoreCase

      public static final boolean isEqualIgnoreCase​(String s1, String s2)
    • 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[] 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

      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)
    • asString

      public static final String asString​(char c)
      This method does intentionally not use the pseudo-constructor naming pattern since it does not create new instances of String. Instead, it returns a constant instance of an intrinsic look-up table.
      Parameters:
      c - the character value to be represented as a String.
      Returns:
      a String containing the passed character value.
    • asString

      public static final String asString​(char... chars)
    • upperCaseFirstChar

      public static final String upperCaseFirstChar​(String s)
      Ensures that the first character of the passed String is in upper case.

      If the passed String is null, has a length of 0 or already has an upper case first character, it is returned. Otherwise, the first character of the passed String is transformed to upper case and concatenated with the rest of the passed String into a new String instance.

      Parameters:
      s - the String 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

      public static final String lowerCaseFirstChar​(String s)
    • 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)
      Returns true if the two given character arrays have at least one character in common.
      Parameters:
      chars1 - first char array
      chars2 - second char array
      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 String longestCommonSubstring​(String a, String 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)
    • longestCommonPrefixLength

      public static final int longestCommonPrefixLength​(String a, String b)
    • longestCommonSuffixLength

      public static final int longestCommonSuffixLength​(String a, String b)
    • longestCommonSuffix

      public static final String longestCommonSuffix​(String a, String b)
    • longestCommonPrefix

      public static final String longestCommonPrefix​(String a, String b)
    • 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

      public static final String padLeft​(String s, int totalLength, char paddingChar)
    • padRight

      public static final String padRight​(String s, int totalLength, char paddingChar)
    • padLeft

      public static final String padLeft​(String s, int totalLength)
    • padRight

      public static final String padRight​(String s, int totalLength)
    • padLeft0

      public static final String padLeft0​(String s, int totalLength)
    • padRight0

      public static final String padRight0​(String s, int totalLength)
    • parseChar

      public static final char parseChar​(String s)
      Parses the char escape sequence Strings "\n" etc. (without the "") to the single char value represented by those strings.
      Parameters:
      s - the char escape sequence
      Returns:
      the resulting char
    • escapeChar

      public static final VarString escapeChar​(VarString vc, char c)
    • escapeChar

      public static final String escapeChar​(char c)
    • createMedialCapitalsString

      public static final String createMedialCapitalsString​(String... elements)
    • ensureCharAtEnd

      public static final String ensureCharAtEnd​(String s, char c)
    • toSingleLine

      public static final String toSingleLine​(String multiLineString, String lineBreakReplacement)
    • padSpace

      public static final String padSpace​(String s, int chars)
    • concat

      public static final String concat​(char separator, Object... parts)
    • 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)
    • String

      public static final String String​(byte value)
    • String

      public static final String String​(boolean value)
    • String

      public static final String String​(short value)
    • String

      public static final String String​(char value)
    • String

      public static final String String​(int value)
    • String

      public static final String String​(float value)
    • String

      public static final String String​(long value)
    • String

      public static final String String​(double value)
    • String

      public static final String String​(char[] chars)
    • String

      public static final String String​(char[] chars, int offset, int length)
    • String

      public static final String String​(byte[] chars)
    • String

      public static final String String​(byte[] chars, Charset charset)
    • String

      public static final String String​(byte[] chars, int offset, int length)
    • String

      public static final String String​(byte[] chars, int offset, int length, Charset charset)
    • String

      public static final String String​(ByteBuffer chars)
    • String

      public static final String String​(ByteBuffer chars, Charset charset)
    • String

      public static final String String​(ByteBuffer chars, int offset, int length)
    • String

      public static final String String​(ByteBuffer chars, int offset, int length, Charset charset)
    • StringBuilder

      public static final StringBuilder StringBuilder​(VarString vs)
    • StringBuilder

      public static final StringBuilder StringBuilder​(VarString vs, int offset, int length)
    • StringBuffer

      public static final StringBuffer StringBuffer​(VarString vs)
    • StringBuffer

      public static final StringBuffer StringBuffer​(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 the String hashing algorithm.

      Returns a hash code for the passed character range. The hash code is computed as

       s[0]*31^(n - 1) + s[1]*31^(n-2) + ... + s[n - 1]
       
      using int arithmetic, where s[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.
      Parameters:
      chars - the character array
      offset - the start offset
      length - the length
      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.
      Type Parameters:
      C - the collector type
      Parameters:
      input - the String to split
      separator - the separator char to split on
      collector - the result collector
      Returns:
      the collector
      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.
      Type Parameters:
      C - the collector type
      Parameters:
      input - the char array to split
      separator - the separator char to split on
      collector - the result collector
      Returns:
      the collector
      See Also:
      trimToString(char[], int, int)
    • splitSimple

      public static String[] splitSimple​(String s, String separator)
    • splitSimple

      public static <C extends Consumer<? super String>> C splitSimple​(String s, String separator, C collector)
    • trimToString

      public static final String trimToString​(char[] input, int lowerOffset, int length)
      Creates a String instance with trimmed content directly from a character sequence without unnecessary intermediate instances.
      Parameters:
      input - the source char array to trim
      lowerOffset - the start offset
      length - the length
      Returns:
      the trimmed String
    • trim

      public static String trim​(String s)
      Calls String.trim() on a non-null argument, returns null otherwise. (this is nothing but a static String.trim())
      Parameters:
      s - the String instance to be trimmed, potentially null.
      Returns:
      a potentially null trimmed String instance.
    • parseTo_intArray

      public static final int[] parseTo_intArray​(String... intStrings)
    • parseToIntegerArray

      public static final Integer[] parseToIntegerArray​(String... intStrings)
    • assembleNewLinedTabbed

      public static final VarString assembleNewLinedTabbed​(VarString vs, CharSequence... elements)
    • 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)
      Special case 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 - the source char array
      offset - the start offset
      length - the length
      Returns:
      the parsed long value
    • 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​(String[] strings, String subject)
    • contains

      public static final boolean contains​(String s, char c)
    • 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

      public static String systemString​(Object instance)
      Utility method that replicates the JVM's intrinsic system string as defined in Object.toString()
      Parameters:
      instance - the instance whose system string shall be generated.
      Returns:
      the system string for the passed instance.
    • addSystemString

      public static VarString addSystemString​(Object instance, VarString vs)
    • nonNullString

      public static String nonNullString​(Object object)
    • valueString

      public static String valueString​(Object value)
      Returns value.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 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

      public static String trimEmptyToNull​(String s)
    • assembleCautiously

      public static final VarString assembleCautiously​(VarString vs, Object object)
      Assembles the passed instance "cautiously" in the sense that only types recognizable via XTypes.isValueType(Object) get assembled using their Object.toString() method, while all others are assembled using systemString(Object) (which behaves identical to the actual implementation of Object.toString()).
      Parameters:
      vs - the VarString 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)
    • randomReadable_char

      public static char randomReadable_char()
    • countCharacter

      public static int countCharacter​(String data, char c)
    • countCodePoint

      public static int countCodePoint​(String data, int codePoint)
    • mathRangeIncInc

      public static String mathRangeIncInc​(long minimum, long maximum)
    • mathRangeIncExc

      public static String mathRangeIncExc​(long minimum, long upperBound)
    • mathRangeExcInc

      public static String mathRangeExcInc​(long lowerBound, long maximum)
    • mathRangeExcExc

      public static String mathRangeExcExc​(long lowerBound, long upperBound)
    • mathRangeIncInc

      public static String mathRangeIncInc​(double minimum, double maximum)
    • mathRangeIncExc

      public static String mathRangeIncExc​(double minimum, double upperBound)
    • mathRangeExcInc

      public static String mathRangeExcInc​(double lowerBound, double maximum)
    • mathRangeExcExc

      public static String mathRangeExcExc​(double lowerBound, double upperBound)
    • mathRangeIncInc

      public static String mathRangeIncInc​(String minimum, String maximum)
    • mathRangeIncExc

      public static String mathRangeIncExc​(String minimum, String upperBound)
    • mathRangeExcInc

      public static String mathRangeExcInc​(String lowerBound, String maximum)
    • mathRangeExcExc

      public static String mathRangeExcExc​(String lowerBound, String upperBound)
    • decapitalize

      public static String decapitalize​(String name)