Package org.brapi.schematools.core.utils
Class StringUtils
java.lang.Object
org.brapi.schematools.core.utils.StringUtils
Utility class for working with Strings
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapitalise(String value) Create a capitalised version of a string value, where the first character is converted to upper casestatic StringPlaces text in a string in the format {key} with a value.static booleanisJSONEqual(String expected, String actual) Compare two JSON strings to if they are the same.static booleanisMultilineEqual(String expected, String actual) Compare two multiline strings to if they are the same.static booleanisNotBlank(String string) Check if a string is not null and not blankstatic StringmakeValidName(String string) Creates a valid name for use in GraphQLstatic StringprettyPrint(Object value) Pretty print an object to a JSON String, with a default indentation of 4 spaces.static StringprettyPrint(Object value, int indent) Pretty print an object to a JSON String.readStringFromPath(Path path) Reads a string from a file pathstatic booleanstartsWithLowerCase(String value) Determines if the string starts with an lower case characterstatic booleanstartsWithUpperCase(String value) Determines if the string starts with an upper case characterstatic StringCreate a label for a propertystatic StringtoLowerCase(String value) Makes the whole string lower casestatic StringtoParameterCase(String value) Makes the first letter in the string lower casestatic StringConverts the noun from its singular form to its plural formstatic StringtoSentenceCase(String value) Makes the first letter in the string upper casestatic StringtoSingular(String value) Converts the noun from its plural form to its singular form
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
capitalise
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
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
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
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
Makes the first letter in the string upper case- Parameters:
value- the string to be converted- Returns:
- the converted string
-
toParameterCase
Makes the first letter in the string lower case- Parameters:
value- the string to be converted- Returns:
- the converted string
-
toLowerCase
Makes the whole string lower case- Parameters:
value- the string to be converted- Returns:
- the converted string
-
startsWithLowerCase
Determines if the string starts with an lower case character- Parameters:
value- the string to be tested- Returns:
trueif the string starts with an lower case character,falseotherwise
-
startsWithUpperCase
Determines if the string starts with an upper case character- Parameters:
value- the string to be tested- Returns:
trueif the string starts with an upper case character,falseotherwise
-
toLabel
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
Reads a string from a file path- Parameters:
path- the path of the file- Returns:
- a string read from a file path
-
isNotBlank
Check if a string is not null and not blank- Parameters:
string- the string to be tested- Returns:
trueif a string is not null and not blank
-
isMultilineEqual
Compare two multiline strings to if they are the same. If the strings are JSON use theisJSONEqual(String, String)method.- Parameters:
expected- the expected stringactual- the actual string- Returns:
trueif 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 theisJSONEqual(String, String)method.- Parameters:
expected- the expected JSON stringactual- the actual JSON string- Returns:
trueif 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 printedindent- 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
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
-