Class StringUtils

java.lang.Object
de.iip_ecosphere.platform.support.StringUtils

public class StringUtils extends Object
String utility functions, partially wrapping org.apache.commons.text.
Author:
Holger Eichelberger, SSE
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    Short prefix style with limited string output.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final org.apache.commons.lang3.builder.ToStringStyle
    Short prefix style with limited string output.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends CharSequence>
    T
    defaultIfBlank(T str, T defaultStr)
    Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null, the value of defaultStr.
    static <T extends CharSequence>
    T
    defaultIfEmpty(T str, T defaultStr)
    Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value of defaultStr.
    static final String
    Escapes the characters in a String using Java String rules.
    static final String
    Escapes the characters in a String using Json String rules.
    static boolean
    Checks if a CharSequence is empty (""), null or whitespace only.
    static boolean
    Checks if a CharSequence is empty ("") or null.
    static boolean
    Checks if a CharSequence is not empty (""), not null and not whitespace only.
    static String
    removeEnd(String str, String remove)
    Removes a substring only if it is at the end of a source string, otherwise returns the source string.
    static String
    removeStart(String str, String remove)
    Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
    static String
    replaceOnce(String text, String searchString, String replacement)
    Replaces a String with another String inside a larger String, once.
    static String
    Turns an object to an readable string, usually using reflection.
    static String
    Turns an object to an readable string, usually using reflection.
    static final String
    Unescapes any Java literals found in the String.
    static final String
    Unescapes any Json literals found in the String.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SHORT_STRING_STYLE

      static final org.apache.commons.lang3.builder.ToStringStyle SHORT_STRING_STYLE
      Short prefix style with limited string output.
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • escapeJava

      public static final String escapeJava(String input)
      Escapes the characters in a String using Java String rules. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
      Parameters:
      input - String to escape values in, may be null
      Returns:
      String with escaped values, null if null string input
    • unescapeJava

      public static final String unescapeJava(String input)
      Unescapes any Java literals found in the String.
      Parameters:
      input - the String to unescape, may be null
      Returns:
      a new unescaped String, null if null string input
    • escapeJson

      public static final String escapeJson(String input)
      Escapes the characters in a String using Json String rules. Escapes any values it finds into their Json String form. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
      Parameters:
      input - String to escape values in, may be null
      Returns:
      String with escaped values, null if null string input
    • unescapeJson

      public static final String unescapeJson(String input)
      Unescapes any Json literals found in the String.
      Parameters:
      input - the String to unescape, may be null
      Returns:
      A new unescaped String, null if null string input
    • defaultIfBlank

      public static <T extends CharSequence> T defaultIfBlank(T str, T defaultStr)
      Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null, the value of defaultStr.
      Type Parameters:
      T - the specific kind of CharSequence
      Parameters:
      str - the CharSequence to check, may be null
      defaultStr - the default CharSequence to return if the input is whitespace, empty ("") or null
      Returns:
      the passed in CharSequence, or the default
    • defaultIfEmpty

      public static <T extends CharSequence> T defaultIfEmpty(T str, T defaultStr)
      Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value of defaultStr.
      Type Parameters:
      T - the specific kind of CharSequence
      Parameters:
      str - the CharSequence to check, may be null
      defaultStr - the default CharSequence to return if the input is empty ("") or null
      Returns:
      the passed in CharSequence, or the default
    • isBlank

      public static boolean isBlank(CharSequence cs)
      Checks if a CharSequence is empty (""), null or whitespace only.
      Parameters:
      cs - the CharSequence to check, may be null
      Returns:
      true if the CharSequence is null, empty or whitespace only
    • isNotBlank

      public static boolean isNotBlank(CharSequence cs)
      Checks if a CharSequence is not empty (""), not null and not whitespace only.
      Parameters:
      cs - the CharSequence to check, may be null
      Returns:
      true if the CharSequence is not empty and not null and not whitespace only
    • replaceOnce

      public static String replaceOnce(String text, String searchString, String replacement)
      Replaces a String with another String inside a larger String, once.
      Parameters:
      text - text to search and replace in, may be null
      searchString - the String to search for, may be null
      replacement - the String to replace with, may be null
      Returns:
      the text with any replacements processed, null if null String input
    • isEmpty

      public static boolean isEmpty(CharSequence cs)
      Checks if a CharSequence is empty ("") or null.
      Parameters:
      cs - the CharSequence to check, may be null
      Returns:
      true if the CharSequence is empty or null
    • toString

      public static String toString(Object obj)
      Turns an object to an readable string, usually using reflection. Uses some default style.
      Parameters:
      obj - the object
      Returns:
      the string representation
    • toStringShortStyle

      public static String toStringShortStyle(Object obj)
      Turns an object to an readable string, usually using reflection. Uses oktoflow short style.
      Parameters:
      obj - the object
      Returns:
      the string representation
    • removeStart

      public static String removeStart(String str, String remove)
      Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
      Parameters:
      str - the source String to search, may be null
      remove - the String to search for and remove, may be null
      Returns:
      the substring with the string removed if found, null if null String input
    • removeEnd

      public static String removeEnd(String str, String remove)
      Removes a substring only if it is at the end of a source string, otherwise returns the source string.
      Parameters:
      str - the source String to search, may be null
      remove - the String to search for and remove, may be null
      Returns:
      the substring with the string removed if found, null if null String input