Class Util

java.lang.Object
org.apache.commons.cli.help.Util

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

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

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static <T extends CharSequence>
    T
    defaultValue(T str, T defaultValue)
    Returns the defaultValue if str is empty.
    (package private) static int
    indexOfNonWhitespace(CharSequence text, int startPos)
    Finds the index of the first non whitespace character.
    (package private) static boolean
    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 String
    Removes the leading whitespace from the specified String.
    (package private) static String
    repeat(int len, char fillChar)
    Constructs a string of specified length filled with the specified char.
    (package private) static String
    repeatSpace(int len)
    Creates a String of padding of length len.
    (package private) static String
    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 Details

    • NOT_FOUND

      private static final int NOT_FOUND
      A special value for index not found.
      See Also:
  • Constructor Details

    • Util

      private Util()
  • Method Details

    • defaultValue

      static <T extends 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(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(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 String ltrim(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 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 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 String rtrim(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.