Class StringUtils

java.lang.Object
org.kordamp.jarviz.util.StringUtils

public class StringUtils extends Object
Since:
0.1.0
  • Field Details

    • PROPERTY_SET_PREFIX

      private static final String PROPERTY_SET_PREFIX
      See Also:
    • PROPERTY_GET_PREFIX

      private static final String PROPERTY_GET_PREFIX
      See Also:
    • GETTER_PATTERN_1

      private static final Pattern GETTER_PATTERN_1
    • GETTER_PATTERN_2

      private static final Pattern GETTER_PATTERN_2
    • SETTER_PATTERN

      private static final Pattern SETTER_PATTERN
    • ERROR_METHOD_NULL

      private static final String ERROR_METHOD_NULL
      See Also:
    • REGEX_CHARS

      private static final Pattern REGEX_CHARS
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • capitalize

      public static String capitalize(String str)
      Capitalizes a String (makes the first char uppercase) taking care of blank strings and single character strings.
      Parameters:
      str - The String to be capitalized
      Returns:
      Capitalized version of the target string if it is not blank
    • getFilenameExtension

      public static String getFilenameExtension(String path)
    • getFilename

      public static String getFilename(String path)
    • getFilename

      public static String getFilename(String path, Collection<String> extensions)
    • getSetterName

      public static String getSetterName(String propertyName)
      Retrieves the name of a setter for the specified property name
      Parameters:
      propertyName - The property name
      Returns:
      The setter equivalent
    • getGetterName

      public static String getGetterName(String propertyName)
      Calculate the name for a getter method to retrieve the specified property
      Parameters:
      propertyName - The property name
      Returns:
      The name for the getter method for this property, if it were to exist, i.e. getConstraints
    • getClassName

      public static String getClassName(String logicalName, String trailingName)
      Returns the class name for the given logical name and trailing name. For example "person" and "Controller" would evaluate to "PersonController"
      Parameters:
      logicalName - The logical name
      trailingName - The trailing name
      Returns:
      The class name
    • getClassNameRepresentation

      public static String getClassNameRepresentation(String name)
      Returns the class name representation of the given name
      Parameters:
      name - The name to convert
      Returns:
      The property name representation
    • getClassNameForLowerCaseHyphenSeparatedName

      public static String getClassNameForLowerCaseHyphenSeparatedName(String name)
      Converts foo-bar into FooBar. Empty and null strings are returned as-is.
      Parameters:
      name - The lower case hyphen separated name
      Returns:
      The class name equivalent.
    • getCapitalizedName

      public static String getCapitalizedName(String name)
      Converts foo-bar into Foo Bar. Empty and null strings are returned as-is.
      Parameters:
      name - The lower case hyphen separated name
      Returns:
      The capitalized name equivalent.
    • getLogicalName

      public static String getLogicalName(Class<?> clazz, String trailingName)
      Retrieves the logical class name of a Griffon artifact given the Griffon class and a specified trailing name
      Parameters:
      clazz - The class
      trailingName - The trailing name such as "Controller" or "TagLib"
      Returns:
      The logical class name
    • getLogicalName

      public static String getLogicalName(String name, String trailingName)
      Retrieves the logical name of the class without the trailing name
      Parameters:
      name - The name of the class
      trailingName - The trailing name
      Returns:
      The logical name
    • getLogicalPropertyName

      public static String getLogicalPropertyName(String className, String trailingName)
    • getPropertyName

      public static String getPropertyName(String name)
      Shorter version of getPropertyNameRepresentation
      Parameters:
      name - The name to convert
      Returns:
      The property name version
    • getPropertyName

      public static String getPropertyName(Class<?> clazz)
      Shorter version of getPropertyNameRepresentation
      Parameters:
      clazz - The clazz to convert
      Returns:
      The property name version
    • getPropertyName

      public static String getPropertyName(Method method)
      Returns the property name representation of the given Method
      Parameters:
      method - The method to inspect
      Returns:
      The property name representation
      Since:
      3.0.0
    • getPropertyNameRepresentation

      public static String getPropertyNameRepresentation(Class<?> targetClass)
      Returns the property name equivalent for the specified class
      Parameters:
      targetClass - The class to get the property name for
      Returns:
      A property name representation of the class name (eg. MyClass becomes myClass)
    • getPropertyNameRepresentation

      public static String getPropertyNameRepresentation(String name)
      Returns the property name representation of the given name
      Parameters:
      name - The name to convert
      Returns:
      The property name representation
    • getPropertyNameForLowerCaseHyphenSeparatedName

      public static String getPropertyNameForLowerCaseHyphenSeparatedName(String name)
      Converts foo-bar into fooBar
      Parameters:
      name - The lower case hyphen separated name
      Returns:
      The property name equivalent
    • getShortName

      public static String getShortName(Class<?> targetClass)
      Returns the class name without the package prefix
      Parameters:
      targetClass - The class to get a short name for
      Returns:
      The short name of the class
    • getShortName

      public static String getShortName(String className)
      Returns the class name without the package prefix
      Parameters:
      className - The class name to get a short name for
      Returns:
      The short name of the class
    • getNaturalName

      public static String getNaturalName(String name)
      Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')
      Parameters:
      name - The property name to convert
      Returns:
      The converted property name
    • isBlank

      public static boolean isBlank(String str)

      Determines whether a given string is null, empty, or only contains whitespace. If it contains anything other than whitespace then the string is not considered to be blank and the method returns false.

      Parameters:
      str - The string to test.
      Returns:
      true if the string is null, or blank.
    • isNotBlank

      public static boolean isNotBlank(String str)

      Determines whether a given string is not null, empty, or only contains whitespace. If it contains anything other than whitespace then the string is not considered to be blank and the method returns true.

      Parameters:
      str - The string to test.
      Returns:
      true if the string is not null, nor blank.
    • requireNonBlank

      public static String requireNonBlank(String str)
      Checks that the specified String is not blank. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
        Foo(String str) {*     this.str = GriffonNameUtils.requireNonBlank(str)
       }* 
      Parameters:
      str - the String to check for blank
      Returns:
      str if not blank
      Throws:
      IllegalArgumentException - if str is blank
    • requireNonBlank

      public static String requireNonBlank(String str, String message)
      Checks that the specified String is not blank and throws a customized IllegalArgumentException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:
        Foo(String str) {*     this.str = GriffonNameUtils.requireNonBlank(str, "str must not be null")
       }* 
      Parameters:
      str - the String to check for blank
      message - detail message to be used in the event that a IllegalArgumentException is thrown
      Returns:
      str if not blank
      Throws:
      IllegalArgumentException - if str is blank
    • getHyphenatedName

      public static String getHyphenatedName(Class<?> clazz)
      Retrieves the hyphenated name representation of the supplied class. For example MyFunkyGriffonThingy would be my-funky-griffon-thingy.
      Parameters:
      clazz - The class to convert
      Returns:
      The hyphenated name representation
    • getHyphenatedName

      public static String getHyphenatedName(String name)
      Retrieves the hyphenated name representation of the given class name. For example MyFunkyGriffonThingy would be my-funky-griffon-thingy.
      Parameters:
      name - The class name to convert.
      Returns:
      The hyphenated name representation.
    • uncapitalize

      public static String uncapitalize(String str)
      Uncapitalizes a String (makes the first char lowercase) taking care of blank strings and single character strings.
      Parameters:
      str - The String to be uncapitalized
      Returns:
      Uncapitalized version of the target string if it is not blank
    • splitValue

      public static Object splitValue(String value)
    • escape

      private static String escape(char character)
    • padLeft

      public static String padLeft(String str, int numChars)
    • padLeft

      public static String padLeft(String str, int numChars, String padding)
    • padRight

      public static String padRight(String str, int numChars)
    • padRight

      public static String padRight(String str, int numChars, String padding)
    • getPadding

      private static String getPadding(String padding, int length)
    • times

      public static String times(String str, int num)
    • stripMargin

      public static String stripMargin(String str)
    • escapeRegexChars

      public static String escapeRegexChars(String str)
    • toSafeRegexPattern

      public static String toSafeRegexPattern(String str)
    • normalizeRegexPattern

      public static String normalizeRegexPattern(String str)
    • toSafePattern

      public static Pattern toSafePattern(String str)
    • isTrue

      public static boolean isTrue(Object o)
    • isFalse

      public static boolean isFalse(Object o)
    • quote

      public static String quote(String str)
      Applies single or double quotes to a string if it contains whitespace characters
      Parameters:
      str - the String to be surrounded by quotes
      Returns:
      a copy of the original String, surrounded by quotes
    • unquote

      public static String unquote(String str)
      Removes single or double quotes from a String
      Parameters:
      str - the String from which quotes will be removed
      Returns:
      the unquoted String
    • applyQuotes

      private static String applyQuotes(String string)