Class Util


  • final class Util
    extends java.lang.Object
    Contains useful helper methods for classes within this package.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int NOT_FOUND
      A special value for index not found.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static <T extends java.lang.CharSequence>
      T
      defaultValue​(T str, T defaultValue)
      Returns the defaultValue if str is empty.
      (package private) static int indexOfNonWhitespace​(java.lang.CharSequence text, int startPos)
      Finds the index of the first non whitespace character.
      (package private) static boolean isEmpty​(java.lang.CharSequence str)
      Tests whether the given string is null or empty.
      (package private) static boolean isWhitespace​(char c)
      Works around https://bugs.java.com/bugdatabase/view_bug?bug_id=8341522 Affected Version: 8, 11, 17, 21, 24.
      (package private) static java.lang.String ltrim​(java.lang.String s)
      Removes the leading whitespace from the specified String.
      (package private) static java.lang.String repeat​(int len, char fillChar)
      Constructs a string of specified length filled with the specified char.
      (package private) static java.lang.String repeatSpace​(int len)
      Creates a String of padding of length len.
      (package private) static java.lang.String rtrim​(java.lang.String s)
      Removes the trailing whitespace from the specified String.
      • Methods inherited from class java.lang.Object

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

      • NOT_FOUND

        private static final int NOT_FOUND
        A special value for index not found.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Util

        private Util()
    • Method Detail

      • defaultValue

        static <T extends java.lang.CharSequence> T defaultValue​(T str,
                                                                 T defaultValue)
        Returns the defaultValue if str is empty.
        Type Parameters:
        T - The type of arguments.
        Parameters:
        str - The string to check.
        defaultValue - the default value if the string is empty.
        Returns:
        the defaultValue if str is empty,
      • indexOfNonWhitespace

        static int indexOfNonWhitespace​(java.lang.CharSequence text,
                                        int startPos)
        Finds the index of the first non whitespace character.
        Parameters:
        text - the text to search in.
        startPos - the starting position to search from.
        Returns:
        the index of the first non whitespace character or -1 if non found.
      • isEmpty

        static boolean isEmpty​(java.lang.CharSequence str)
        Tests whether the given string is null or empty.
        Parameters:
        str - The string to test.
        Returns:
        Whether the given string is null or empty.
      • isWhitespace

        static boolean isWhitespace​(char c)
        Works around https://bugs.java.com/bugdatabase/view_bug?bug_id=8341522 Affected Version: 8, 11, 17, 21, 24.
      • ltrim

        static java.lang.String ltrim​(java.lang.String s)
        Removes the leading whitespace from the specified String.
        Parameters:
        s - The String to remove the leading padding from.
        Returns:
        The String of without the leading padding.
      • repeat

        static java.lang.String repeat​(int len,
                                       char fillChar)
        Constructs a string of specified length filled with the specified char.
        Parameters:
        len - the length of the final string.
        fillChar - the character to file it will.
        Returns:
        A string of specified length filled with the specified char.
      • repeatSpace

        static java.lang.String repeatSpace​(int len)
        Creates a String of padding of length len.
        Parameters:
        len - The length of the String of padding to create.
        Returns:
        The String of padding.
      • rtrim

        static java.lang.String rtrim​(java.lang.String s)
        Removes the trailing whitespace from the specified String.
        Parameters:
        s - The String to remove the trailing padding from.
        Returns:
        The String of without the trailing padding.