com.hazelcast.util

## Class StringUtil

- java.lang.Object
- - com.hazelcast.util.StringUtil

-     public final class StringUtil
      extends Object

  Utility class for Strings.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `LINE_SEPARATOR` Points to the System property 'line.separator'.
    `static Locale` | `LOCALE_INTERNAL` LOCALE_INTERNAL is the default locale for string operations and number formatting.
    `static Charset` | `UTF8_CHARSET` UTF-8 Charset
    `static Pattern` | `VERSION_PATTERN` Pattern used to tokenize version strings.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `bytesToString(byte[] bytes)` Creates a UTF8_CHARSET string from a byte array.
    `static String` | `bytesToString(byte[] bytes, int offset, int length)` Creates a UTF8_CHARSET string from a byte array.
    `static boolean` | `equalsIgnoreCase(String str1, String str2)` Returns true if two strings are equals ignoring the letter case in `LOCALE_INTERNAL` locale.
    `static String` | `getterIntoProperty(String getterName)` Convert getter into a property name Example: 'getFoo' is converted into 'foo' It's written defensively, when output is not a getter then it returns the original name.
    `static int` | `indexOf(String input, char ch)` Like a String.indexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
    `static int` | `indexOf(String input, char ch, int offset)` Like a String.indexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
    `static String[]` | `intersection(String[] arr1, String[] arr2)` Returns intersection of given String arrays.
    `static boolean` | `isNullOrEmpty(String s)` Checks if a string is empty or not.
    `static boolean` | `isNullOrEmptyAfterTrim(String s)` Checks if a string is empty or not after trim operation
    `static int` | `lastIndexOf(String input, char ch)` Like a String.lastIndexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
    `static int` | `lastIndexOf(String input, char ch, int offset)` Like a String.lastIndexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
    `static String` | `lowerCaseInternal(String s)` HC specific settings, operands etc.
    `static String[]` | `splitByComma(String input, boolean allowEmpty)` Splits String value with comma "," used as a separator.
    `static byte[]` | `stringToBytes(String s)` Creates a byte array from a string.
    `static String[]` | `subraction(String[] arr1, String[] arr2)` Returns subtraction between given String arrays.
    `static String` | `timeToString(long timeMillis)` Returns a String representation of the time.
    `static String` | `timeToStringFriendly(long timeMillis)` Returns a String representation of the time.
    `static String[]` | `tokenizeVersionString(String version)` Tokenizes a version string and returns the tokens with the following grouping: (1) major version, eg "3" (2) minor version, eg "8" (3) patch version prefixed with ".", if exists, otherwise `null` (eg ".0") (4) patch version, eg "0" (5) 1st -qualifier, if exists (6) -SNAPSHOT qualifier, if exists
    `static String` | `trim(String input)` Trim whitespaces.
    `static String` | `upperCaseInternal(String s)` HC specific settings, operands etc.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### UTF8_CHARSET

          public static final Charset UTF8_CHARSET

      UTF-8 Charset

    - #### LINE_SEPARATOR

          public static final String LINE_SEPARATOR

      Points to the System property 'line.separator'.

    - #### LOCALE_INTERNAL

          public static final Locale LOCALE_INTERNAL

      LOCALE_INTERNAL is the default locale for string operations and number formatting. Initialized to `java.util.Locale.US` (US English).

    - #### VERSION_PATTERN

          public static final Pattern VERSION_PATTERN

      Pattern used to tokenize version strings.

  - ### Method Detail

    - #### bytesToString

          public static String bytesToString(byte[] bytes,
                                             int offset,
                                             int length)

      Creates a UTF8_CHARSET string from a byte array.
      Parameters:
        `bytes` - the byte array.
        `offset` - the index of the first byte to decode
        `length` - the number of bytes to decode
      Returns:
        the string created from the byte array.

    - #### bytesToString

          public static String bytesToString(byte[] bytes)

      Creates a UTF8_CHARSET string from a byte array.
      Parameters:
        `bytes` - the byte array.
      Returns:
        the string created from the byte array.

    - #### stringToBytes

          public static byte[] stringToBytes(String s)

      Creates a byte array from a string.
      Parameters:
        `s` - the string.
      Returns:
        the byte array created from the string.

    - #### isNullOrEmpty

          public static boolean isNullOrEmpty(String s)

      Checks if a string is empty or not.
      Parameters:
        `s` - the string to check.
      Returns:
        true if the string is `null` or empty, false otherwise

    - #### isNullOrEmptyAfterTrim

          public static boolean isNullOrEmptyAfterTrim(String s)

      Checks if a string is empty or not after trim operation
      Parameters:
        `s` - the string to check.
      Returns:
        true if the string is `null` or empty, false otherwise

    - #### upperCaseInternal

          public static String upperCaseInternal(String s)

      HC specific settings, operands etc. use this method. Creates an uppercase string from the given string.
      Parameters:
        `s` - the given string
      Returns:
        an uppercase string, or `null`/empty if the string is `null`/empty

    - #### lowerCaseInternal

          public static String lowerCaseInternal(String s)

      HC specific settings, operands etc. use this method. Creates a lowercase string from the given string.
      Parameters:
        `s` - the given string
      Returns:
        a lowercase string, or `null`/empty if the string is `null`/empty

    - #### timeToString

          public static String timeToString(long timeMillis)

      Returns a String representation of the time.

      This method is not particularly efficient since it generates a ton of litter.

      Parameters:
        `timeMillis` - time in millis
      Returns:
        the String

    - #### timeToStringFriendly

          public static String timeToStringFriendly(long timeMillis)

      Returns a String representation of the time. If time is 0, then 'never' is returned.

      This method is not particularly efficient since it generates a ton of litter.

      Parameters:
        `timeMillis` - time in millis
      Returns:
        the String

    - #### indexOf

          public static int indexOf(String input,
                                    char ch,
                                    int offset)

      Like a String.indexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
      Parameters:
        `input` - to check the indexOf on
        `ch` - character to find the index of
        `offset` - offset to start the reading from
      Returns:
        index of the character, or -1 if not found

    - #### indexOf

          public static int indexOf(String input,
                                    char ch)

      Like a String.indexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
      Parameters:
        `input` - to check the indexOf on
        `ch` - character to find the index of
      Returns:
        index of the character, or -1 if not found

    - #### lastIndexOf

          public static int lastIndexOf(String input,
                                        char ch,
                                        int offset)

      Like a String.lastIndexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
      Parameters:
        `input` - to check the indexOf on
        `ch` - character to find the index of
        `offset` - offset to start the reading from the end
      Returns:
        index of the character, or -1 if not found

    - #### lastIndexOf

          public static int lastIndexOf(String input,
                                        char ch)

      Like a String.lastIndexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling
      Parameters:
        `input` - to check the indexOf on
        `ch` - character to find the index of
      Returns:
        index of the character, or -1 if not found

    - #### tokenizeVersionString

          public static String[] tokenizeVersionString(String version)

      Tokenizes a version string and returns the tokens with the following grouping: (1) major version, eg "3" (2) minor version, eg "8" (3) patch version prefixed with ".", if exists, otherwise `null` (eg ".0") (4) patch version, eg "0" (5) 1st -qualifier, if exists (6) -SNAPSHOT qualifier, if exists
      Parameters:
        `version` -
      Returns:

    - #### getterIntoProperty

          public static String getterIntoProperty(String getterName)

      Convert getter into a property name Example: 'getFoo' is converted into 'foo' It's written defensively, when output is not a getter then it returns the original name. It only converts names starting with a get- prefix. When a getter starts with an is- prefix (=boolean) then it does not convert it.
      Parameters:
        `getterName` -
      Returns:
        property matching the given getter

    - #### trim

          public static String trim(String input)

      Trim whitespaces. This method (compared to `String.trim()`) doesn't limit to space character.
      Parameters:
        `input` - string to trim
      Returns:
        `null` if provided value was `null`, input with removed leading and trailing whitespaces

    - #### splitByComma

          public static String[] splitByComma(String input,
                                              boolean allowEmpty)

      Splits String value with comma "," used as a separator. The whitespaces around values are trimmed.
      Parameters:
        `input` - string to split
      Returns:
        `null` if provided value was `null`, split parts otherwise (trimmed)

    - #### intersection

          public static String[] intersection(String[] arr1,
                                              String[] arr2)

      Returns intersection of given String arrays. If either array is `null`, then `null` is returned.
      Parameters:
        `arr1` - first array
        `arr2` - second array
      Returns:
        arr1 without values which are not present in arr2

    - #### subraction

          public static String[] subraction(String[] arr1,
                                            String[] arr2)

      Returns subtraction between given String arrays.
      Parameters:
        `arr1` - first array
        `arr2` - second array
      Returns:
        arr1 without values which are not present in arr2

    - #### equalsIgnoreCase

          public static boolean equalsIgnoreCase(String str1,
                                                 String str2)

      Returns true if two strings are equals ignoring the letter case in `LOCALE_INTERNAL` locale.
      Parameters:
        `str1` - first string to compare
        `str2` - second string to compare
      Returns:
        true if the strings are equals ignoring the case

Copyright © 2018. All rights reserved.