Class StringUtils

java.lang.Object
scriptella.util.StringUtils

public final class StringUtils extends Object
Miscellaneous String/CharSequence utility methods.
Version:
1.0
Author:
Fyodor Kupolov
  • Method Details

    • isEmpty

      public static boolean isEmpty(CharSequence cs)
      Returns true if characters sequence is empty (length=0) or null.
      Parameters:
      cs - characters sequence to test.
      Returns:
      true if characters sequence is empty (length=0) or null.
    • nullsafeTrim

      public static String nullsafeTrim(CharSequence cs)
      Returns a trimmed value for specified charsequence
      Parameters:
      cs - charsequence to trim.
      Returns:
      trimmed value for specified charsequence or empty string if cs=null
    • nullsafeToString

      public static String nullsafeToString(Object o)
      Returns Null safe string representation of specified object.
      Parameters:
      o - object to convert to String.
      Returns:
      o.toString() or "" if o==null.
    • isAsciiWhitespacesOnly

      public static boolean isAsciiWhitespacesOnly(CharSequence cs)
      Checks if specified characters sequence is empty or contains only ascii whitespace characters.
      Parameters:
      cs - characters sequence to check.
      Returns:
      true if characters sequence is empty or contains only ascii whitespace characters.
    • isDecimalInt

      public static boolean isDecimalInt(CharSequence cs)
      Checks if specified characters sequence represents a non negative decimal number.
      Parameters:
      cs - characters sequence to check.
      Returns:
      true if specified characters sequence represents a non negative decimal number.
    • consoleFormat

      public static String consoleFormat(String string)
      Formats specified string for console suitable representation.

      All EOL char sequences are replaced with a single system line.separator, and all other whitespace sequences are replaced with a single space.

      String larger than 10KB are trimmed.

      Parameters:
      string - string to format. Nulls are allowed.
      Returns:
      formatted string.
    • consoleFormat

      public static String consoleFormat(String string, int maxLength)
      Formats specified string for console suitable representation.

      All EOL char sequences are replaced with a single system line.separator, and all other whitespace sequences are replaced with a single space.

      Parameters:
      string - string to format. Nulls are allowed.
      maxLength - maximum number of characters to show or negative if the string cannot be trimmed.
      Returns:
      formatted string.
    • removePrefix

      public static String removePrefix(String string, String prefix)
      Removes a prefix from a string.
      Parameters:
      string - original string. May be null.
      prefix - prefix to to check and remove. May be null.
      Returns:
      string without a prefix, or unchanged string.
    • getMaskedPassword

      public static String getMaskedPassword(String string)
      Masks password displaying to user.
      Parameters:
      string - password.
      Returns:
      masked password or empty string for empty/null password.
    • pad

      public static String pad(String str, boolean left, int width, char padChar)
      Pads a String with a specified character.
      Parameters:
      str - string to pad. Null is treated as empty string.
      left - true if left pad, false if right
      width - with of the padded string
      padChar - character to use for padding
      Returns:
      padded string.