Class StringUtils

java.lang.Object
org.brapi.schematools.core.utils.StringUtils

public class StringUtils extends Object
Utility class for working with Strings
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • capitalise

      public static String capitalise(String value)
      Create a capitalised version of a string value, where the first character is converted to upper case
      Parameters:
      value - the string value to be capitalised
      Returns:
      a capitalised version of a string value, where the first character is converted to upper case
    • toSingular

      public static String toSingular(String value)
      Converts the noun from its plural form to its singular form
      Parameters:
      value - a noun to be converted
      Returns:
      singular form of a plural noun
    • toPlural

      public static String toPlural(String value)
      Converts the noun from its singular form to its plural form
      Parameters:
      value - a noun to be converted
      Returns:
      plural form of a singular noun
    • makeValidName

      public static String makeValidName(String string)
      Creates a valid name for use in GraphQL
      Parameters:
      string - a string which might contain invalid characters for a valid GraphQL name
      Returns:
      a valid GraphQL name based on the input string
    • toSentenceCase

      public static String toSentenceCase(String value)
      Makes the first letter in the string upper case
      Parameters:
      value - the string to be converted
      Returns:
      the converted string
    • toParameterCase

      public static String toParameterCase(String value)
      Makes the first letter in the string lower case
      Parameters:
      value - the string to be converted
      Returns:
      the converted string
    • toLowerCase

      public static String toLowerCase(String value)
      Makes the whole string lower case
      Parameters:
      value - the string to be converted
      Returns:
      the converted string
    • startsWithLowerCase

      public static boolean startsWithLowerCase(String value)
      Determines if the string starts with an lower case character
      Parameters:
      value - the string to be tested
      Returns:
      true if the string starts with an lower case character, false otherwise
    • startsWithUpperCase

      public static boolean startsWithUpperCase(String value)
      Determines if the string starts with an upper case character
      Parameters:
      value - the string to be tested
      Returns:
      true if the string starts with an upper case character, false otherwise
    • toLabel

      public static String toLabel(String propertyName)
      Create a label for a property
      Parameters:
      propertyName - the property name in lower camel case
      Returns:
      a label for the property in sentence case
    • readStringFromPath

      public static Response<String> readStringFromPath(Path path)
      Reads a string from a file path
      Parameters:
      path - the path of the file
      Returns:
      a string read from a file path
    • isNotBlank

      public static boolean isNotBlank(String string)
      Check if a string is not null and not blank
      Parameters:
      string - the string to be tested
      Returns:
      true if a string is not null and not blank
    • isMultilineEqual

      public static boolean isMultilineEqual(String expected, String actual)
      Compare two multiline strings to if they are the same. If the strings are JSON use the isJSONEqual(String, String) method.
      Parameters:
      expected - the expected string
      actual - the actual string
      Returns:
      true if actual string is equal to the expected string
    • isJSONEqual

      public static boolean isJSONEqual(String expected, String actual) throws com.fasterxml.jackson.core.JsonProcessingException
      Compare two JSON strings to if they are the same. If the strings are not JSON use the isJSONEqual(String, String) method.
      Parameters:
      expected - the expected JSON string
      actual - the actual JSON string
      Returns:
      true if actual string is equal to the expected string
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the strings cannot be converted to JSON nodes.
    • prettyPrint

      public static String prettyPrint(Object value) throws com.fasterxml.jackson.core.JsonProcessingException
      Pretty print an object to a JSON String, with a default indentation of 4 spaces.
      Parameters:
      value - the object to be Pretty printed
      Returns:
      Pretty print JSON String version of the object
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be converted to JSON.
    • prettyPrint

      public static String prettyPrint(Object value, int indent) throws com.fasterxml.jackson.core.JsonProcessingException
      Pretty print an object to a JSON String.
      Parameters:
      value - the object to be Pretty printed
      indent - the number of spaces to indent
      Returns:
      Pretty print JSON String version of the object
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the object cannot be converted to JSON.
    • format

      public static String format(String format, Map<String,Object> parameters)
      Places text in a string in the format {key} with a value. The
      Parameters:
      format - the format string that contains the keys to substitute.
      parameters - A map of key value pairs
      Returns:
      the formatted string