Class StringUtil

java.lang.Object
org.seppiko.commons.utils.StringUtil

public class StringUtil extends Object
String Util
Author:
Leonard Woo
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • safeNull

      public static String safeNull(String src, String defaultValue)
      Get a string object with default value
      Parameters:
      src - string object
      defaultValue - default string object
      Returns:
      result
    • isEmpty

      public static boolean isEmpty(CharSequence str)
      test string is empty or contains only whitespace codepoints
      Parameters:
      str - string object
      Returns:
      true is yes
    • hasLength

      public static boolean hasLength(String str)
      test string has any char
      Parameters:
      str - string object
      Returns:
      true is yes
    • hasText

      public static boolean hasText(CharSequence str)
      test char sequence has any char without non-blank character
      Parameters:
      str - char sequence object
      Returns:
      true is not null and without whitespace
    • nonText

      public static boolean nonText(CharSequence str)
      test char sequence is not null and empty or has non-blank character
      Parameters:
      str - char sequence object
      Returns:
      true is not null and empty
    • isNumeric

      public static boolean isNumeric(CharSequence input)
      Test CharSequence is numeric
      Parameters:
      input - numeric
      Returns:
      true is numeric
    • isInteger

      public static boolean isInteger(CharSequence input)
      Test CharSequence is integer
      Parameters:
      input - numeric
      Returns:
      true is integer
    • isDecimal

      public static boolean isDecimal(CharSequence input)
      Test CharSequence is decimal
      Parameters:
      input - numeric
      Returns:
      true is decimal
    • isPunct

      public static boolean isPunct(CharSequence input)
      Test CharSequence is punct
      Parameters:
      input - punct
      Returns:
      true is punct
    • isSymbol

      public static boolean isSymbol(CharSequence input)
      Test CharSequence is symbol
      Parameters:
      input - symbol
      Returns:
      true is symbol
    • matches

      public static Boolean matches(String regex, CharSequence input)
      Compiles the given regular expression and attempts to match the given input against it.
      Parameters:
      regex - The expression to be compiled
      input - The character sequence to be matched
      Returns:
      whether or not the regular expression matches on the input, when the expression's syntax is invalid is null
    • transcoding

      public static String transcoding(String data, Charset oldEncoding, Charset newEncoding)
      Convert string data from old encoding to new encoding
      Parameters:
      data - string data
      oldEncoding - old encoding
      newEncoding - new encoding
      Returns:
      convert result
    • fixedLength

      public static String fixedLength(String str, int length, char preChar)
      Return fixed length string object
      Parameters:
      str - string object
      length - count length
      preChar - pre-padded character
      Returns:
      fixed length string object
    • initialsUpperCase

      public static String initialsUpperCase(String str)
      Capitalize the first letter
      Parameters:
      str - origin string
      Returns:
      new string
    • replaceIndex

      public static String replaceIndex(CharSequence data, int start, int end, CharSequence replacement)
      Replace CharSequence between start and end
      Parameters:
      data - origin data
      start - replace start index
      end - replace end index
      replacement - replace data
      Returns:
      new string
    • convertToString

      public static String convertToString(char[] src, int splitNum, String split)
      Convert char array to String with separate
      Parameters:
      src - Raw data
      splitNum - Separation interval
      split - Separator
      Returns:
      encoded string
    • convertToCharArray

      public static char[] convertToCharArray(String src, String split)
      Delete string Separator and to char array
      Parameters:
      src - Data
      split - Separator
      Returns:
      char array
    • charsetDecode

      public static CharBuffer charsetDecode(Charset charset, byte[] data)
      Charset decode
      Parameters:
      charset - charset, e.g. StandardCharsets.UTF_8
      data - byte array
      Returns:
      character buffer object
      See Also:
    • charsetEncode

      public static byte[] charsetEncode(Charset charset, CharBuffer data)
      Charset encode
      Parameters:
      charset - charset, e.g. StandardCharsets.UTF_8
      data - character buffer
      Returns:
      byte array
      See Also: