Class StringUtil

java.lang.Object
nl.siegmann.epublib.util.StringUtil

public class StringUtil extends Object
Various String utility functions. Most of the functions herein are re-implementations of the ones in apache commons StringUtils. The reason for re-implementing this is that the functions are fairly simple and using my own implementation saves the inclusion of a 200Kb jar file.
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • collapsePathDots

      public static String collapsePathDots(String path)
      Changes a path containing '..', '.' and empty dirs into a path that doesn't. X/foo/../Y is changed into 'X/Y', etc. Does not handle invalid paths like "../".
      Parameters:
      path -
      Returns:
      the normalized path
    • isNotBlank

      public static boolean isNotBlank(String text)
      Whether the String is not null, not zero-length and does not contain of only whitespace.
      Parameters:
      text -
      Returns:
      Whether the String is not null, not zero-length and does not contain of
    • isBlank

      public static boolean isBlank(String text)
      Whether the String is null, zero-length and does contain only whitespace.
      Returns:
      Whether the String is null, zero-length and does contain only whitespace.
    • isEmpty

      public static boolean isEmpty(String text)
      Whether the given string is null or zero-length.
      Parameters:
      text - the input for this method
      Returns:
      Whether the given string is null or zero-length.
    • endsWithIgnoreCase

      public static boolean endsWithIgnoreCase(String source, String suffix)
      Whether the given source string ends with the given suffix, ignoring case.
      Parameters:
      source -
      suffix -
      Returns:
      Whether the given source string ends with the given suffix, ignoring case.
    • defaultIfNull

      public static String defaultIfNull(String text)
      If the given text is null return "", the original text otherwise.
      Parameters:
      text -
      Returns:
      If the given text is null "", the original text otherwise.
    • defaultIfNull

      public static String defaultIfNull(String text, String defaultValue)
      If the given text is null return "", the given defaultValue otherwise.
      Parameters:
      text -
      defaultValue -
      Returns:
      If the given text is null "", the given defaultValue otherwise.
    • equals

      public static boolean equals(String text1, String text2)
      Null-safe string comparator
      Parameters:
      text1 -
      text2 -
      Returns:
      whether the two strings are equal
    • toString

      public static String toString(Object... keyValues)
      Pretty toString printer.
      Parameters:
      keyValues -
      Returns:
      a string representation of the input values
    • hashCode

      public static int hashCode(String... values)
    • substringBefore

      public static String substringBefore(String text, char separator)
      Gives the substring of the given text before the given separator. If the text does not contain the given separator then the given text is returned.
      Parameters:
      text -
      separator -
      Returns:
      the substring of the given text before the given separator.
    • substringBeforeLast

      public static String substringBeforeLast(String text, char separator)
      Gives the substring of the given text before the last occurrence of the given separator. If the text does not contain the given separator then the given text is returned.
      Parameters:
      text -
      separator -
      Returns:
      the substring of the given text before the last occurrence of the given separator.
    • substringAfterLast

      public static String substringAfterLast(String text, char separator)
      Gives the substring of the given text after the last occurrence of the given separator. If the text does not contain the given separator then "" is returned.
      Parameters:
      text -
      separator -
      Returns:
      the substring of the given text after the last occurrence of the given separator.
    • substringAfter

      public static String substringAfter(String text, char c)
      Gives the substring of the given text after the given separator. If the text does not contain the given separator then "" is returned.
      Parameters:
      text - the input text
      c - the separator char
      Returns:
      the substring of the given text after the given separator.