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

    • requireNonBlankElse

      public static CharSequence requireNonBlankElse(CharSequence str, CharSequence defaultStr)
      Require a string with default value
      Parameters:
      str - string
      defaultStr - default string
      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(CharSequence 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
    • isDigit

      public static boolean isDigit(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 Punctuation
      Parameters:
      input - punct
      Returns:
      true is punct
    • 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 the regular expression matches on the input, when the expression's syntax is invalid is null
    • getMatcher

      public static Matcher getMatcher(String regex, CharSequence input)
      Compiles the given regular expression the given input against it.
      Parameters:
      regex - The expression to be compiled
      input - The character sequence to be matched
      Returns:
      Matcher object
    • transcoding

      public static String transcoding(CharSequence data, Charset oldEncoding, Charset newEncoding) throws NullPointerException
      Convert string data from old encoding to new encoding
      Parameters:
      data - string data
      oldEncoding - old encoding
      newEncoding - new encoding
      Returns:
      convert result
      Throws:
      NullPointerException - old encode or new decode exception
    • 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
    • toFirstUpperCase

      public static String toFirstUpperCase(String input)
      Capitalize the first letter
      Parameters:
      input - origin string
      Returns:
      new string
    • replaceBetween

      public static String replaceBetween(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
    • convertJoinerString

      public static String convertJoinerString(String delimiter, String... strs)
      convert joiner string with delimiter
      Parameters:
      delimiter - the sequence of characters to be used between each array element
      strs - string element
      Returns:
      the string representation
    • 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) throws NullPointerException
      Delete string Separator and to char array
      Parameters:
      src - Data
      split - Separator
      Returns:
      char array
      Throws:
      NullPointerException - when data or separator is null
    • toFullWidth

      public static String toFullWidth(CharSequence src)
      convert half-width to full-width
      Parameters:
      src - Half-width String
      Returns:
      Full-width String
    • toHalfWidth

      public static String toHalfWidth(CharSequence src)
      convert full-width to half-width
      Parameters:
      src - Full-width String
      Returns:
      Half-width String
    • unicodeDecode

      public static String unicodeDecode(String src)
      Unicode decoding When not found return origin String
      Parameters:
      src - unicode
      Returns:
      String
    • unicodeEncode

      public static String unicodeEncode(String src)
      Unicode encoding
      Parameters:
      src - String
      Returns:
      unicode