Class StringUtil

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

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

    • requireNonBlankElse

      public static CharSequence requireNonBlankElse(CharSequence value, CharSequence defaultValue)
      Require a CharSequence with default value.
      Parameters:
      value - CharSequence instance.
      defaultValue - default CharSequence instance.
      Returns:
      CharSequence without null.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(CharSequence value)
      Test CharSequence is empty or contains only whitespace codepoints
      Parameters:
      value - CharSequence instance.
      Returns:
      true is yes.
    • hasLength

      public static boolean hasLength(CharSequence str)
      Test CharSequence has any char
      Parameters:
      str - CharSequence instance.
      Returns:
      true is yes.
    • hasText

      public static boolean hasText(CharSequence str)
      Test CharSequence has any char without non-blank character
      Parameters:
      str - CharSequence instance.
      Returns:
      true is not null and without whitespace, false is otherwise.
    • nonText

      public static boolean nonText(CharSequence str)
      Test CharSequence is not null and empty or has non-blank character
      Parameters:
      str - CharSequence instance.
      Returns:
      true is not null and empty, false is otherwise.
    • isNumeric

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

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

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

      public static boolean isPunctuation(CharSequence input)
      Test CharSequence is punctuation
      Parameters:
      input - punctuation CharSequence.
      Returns:
      true is punctuation.
    • 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 syntax is invalid is null.
    • find

      public static String find(String regex, CharSequence input)
      Returns the input subsequence captured by the given index during match operation.
      Parameters:
      regex - The expression to be compiled.
      input - The character sequence to be matched.
      Returns:
      The (possibly empty) subsequence captured by the index during match, or empty if the group failed to match part of the input.
    • 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 instance, if the expression's syntax is invalid return null.
    • transcoding

      public static String transcoding(CharSequence data, Charset oldEncoding, Charset newEncoding) throws NullPointerException
      Convert string data from old encoding to new encoding
      Parameters:
      data - CharSequence data.
      oldEncoding - old encoding.
      newEncoding - new encoding.
      Returns:
      new encoding CharSequence.
      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 array.
      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 - string.
      split - separator.
      Returns:
      char array.
      Throws:
      NullPointerException - when data or separator is null.
    • toFullWidth

      public static String toFullWidth(CharSequence src)
      Convert half-width string ('\u0021' through '\u007E') to full-width string ('\uFF01' through '\uFF5E')
      Parameters:
      src - Half-width string.
      Returns:
      Full-width string.
    • toHalfWidth

      public static String toHalfWidth(CharSequence src)
      Convert full-width string ('\uFF01' through '\uFF5E') to half-width string ('\u0021' through '\u007E')
      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