Class StringExpressionVariable
java.lang.Object
com.broadleafcommerce.rulesengine.expression.util.StringExpressionVariable
- All Implemented Interfaces:
- ExpressionVariable
Common, null-safe, string operations
 An instance of this class will usually be accessible as a variable within an expression via
 #strings. This is essentially a wrapper around StringUtils to provide a layer of
 abstraction and because StringUtils employs static methods. Note that not all methods of
 StringUtils have been implemented just those that seemed most relevant for expression
 evaluation.
 
- Author:
- Nathan Moore (nathanmoore).
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionfinal Stringcapitalize(Object o) Null-safe convert to title casefinal StringRemoves one newline from end of the string if presentfinal StringRemove the last character from a stringfinal intNull-safe string compare.final intcompareIgnoreCase(Object o, String str2) Null-safe string compare.final intcompareIgnoreCaseNullIsMore(Object o, String str2) Null-safe string compare.final intcompareNullIsMore(Object o, String str2) Null-safe string compare.final booleancontains(Object o, CharSequence searchChar) Whether the string contains the substringfinal booleancontainsIgnoreCase(Object o, CharSequence searchChar) Whether the string contains the substring.final booleanWhether the string contains whitespace.protected Stringfinal StringDeletes all whitespaces from a String as defined byCharacter.isWhitespace(char).final booleanendsWith(Object o, CharSequence prefix) Whether the text ends with the prefix.final booleanendsWithIgnoreCase(Object o, CharSequence prefix) Whether the text ends with the prefix.final booleanequals(Object o, CharSequence cs2) Null-safe string equals.final booleanequalsIgnoreCase(Object o, CharSequence cs2) Null-safe string equals.final StringgetName()final intindexOf(Object o, CharSequence searchSeq) Returns the index of the given substring with the string starting at the given position.final intindexOfIgnoreCase(Object o, CharSequence searchSeq) Returns the index of the given substring with the string starting at the given position.final booleanWhether the string is null, empty (""), or blank (" ")final booleanWhether the string is null or empty ("")final booleanisNotBlank(Object o) Whether the string is not null, empty(""),or blank (" ")final booleanisNotEmpty(Object o) Whether the string is not null or empty ("")final <T> Stringjoin(T... elements) Joins the elements of the provided array into a single String containing the provided of elementsfinal StringJoins the elements of the provided iterable into a single String containing the provided of elements, placing the given separator between elementsfinal <T> StringJoins the elements of the provided array into a single String containing the provided of elements, placing the given separator between elementsfinal intlastIndexOf(Object o, CharSequence searchChar) Returns the index of the last occurrence of the given substring.final intlastIndexOfIgnoreCase(Object o, CharSequence searchChar) Returns the index of the last occurrence of the given substring.final StringGets a substring from the left-most characters.final intNull-safe get string lengthfinal booleannotContains(Object o, CharSequence searchChar) The inverse ofcontains(Object, CharSequence)final booleannotContainsIgnoreCase(Object o, CharSequence searchChar) The inverse ofnotContainsIgnoreCase(Object, CharSequence).final booleanReturn true if strings are not equal, else false.final booleannotEqualsIgnoreCase(Object o, String str2) Return true if strings are not equal, ignoring case, else falsefinal StringRemoves all occurrences of a substring from within the source string.final StringremoveIgnoreCase(String str, String removeStr) Removes all occurrences of a substring from within the source string.final StringReplaces each substring of the text String that matches the given regular expression with the given replacement up totimesToReplace.final StringreplaceAll(String text, String regex, String replacement) Replaces each substring of the text String that matches the given regular expression with the given replacement.final StringreplaceIgnoreCase(String text, String replaceTxt, String replacement) Replaces each substring of the text String that matches the given regular expression with the given replacement up totimesToReplace.final StringNull-safe string reversefinal StringGets a substring from the right-most characters.final String[]Splits the provided string into an array by the separator string specified.splitToList(Object o, String separator) Splits the provided string into a list instead of an array.final booleanstartsWith(Object o, CharSequence prefix) Whether the text starts with the prefixfinal booleanstartsWithIgnoreCase(Object o, CharSequence prefix) Whether the text starts with the prefix.final StringStrips whitespace from the start and end of a String.final StringstripChars(Object o, String stripChars) Strips the specified characters from the beginning and end of the string.final StringReturns an empty string ("") if the string is null or empty after strippingfinal StringReturns null if the stripped string is empty.final StringGets a substring defined by start and end indices from the specified string safely.final StringNull-safe convert to lowercasefinal StringConverts the target to a string.final StringNull-safe convert to uppercasefinal StringRemoves control characters (char <= 32) from both ends of this String, handlingnullby returningnull.final StringReturns an empty string ("") if the string is null or empty after trimming.final StringtrimToNull(Object o) Returns null if the string is empty after trimmingfinal StringCreates a substring using the specified left-offset and max width.final StringUnwraps a given string from anther string.final StringWraps a string with a string.final StringwrapIfMissing(Object o, String wrapWith) Wraps a string with a string if not already present.
- 
Field Details- 
NAME- See Also:
 
 
- 
- 
Constructor Details- 
StringExpressionVariablepublic StringExpressionVariable()SetslocaletoLocale.ENGLISH
- 
StringExpressionVariable
 
- 
- 
Method Details- 
getName- Specified by:
- getNamein interface- ExpressionVariable
- Returns:
- Name of the variable, must not be null
 
- 
toStringConverts the target to a string.- Parameters:
- target- object to convert
- Returns:
- string representation of object
 
- 
isEmptyWhether the string is null or empty ("")
- 
isNotEmptyWhether the string is not null or empty ("")
- 
isBlankWhether the string is null, empty (""), or blank (" ")
- 
isNotBlankWhether the string is not null, empty(""),or blank (" ")
- 
trimRemoves control characters (char <= 32) from both ends of this String, handlingnullby returningnull.
- 
trimToNullReturns null if the string is empty after trimming
- 
trimToEmptyReturns an empty string ("") if the string is null or empty after trimming.
- 
notEqualsReturn true if strings are not equal, else false.
- 
notEqualsIgnoreCaseReturn true if strings are not equal, ignoring case, else false
- 
truncateCreates a substring using the specified left-offset and max width.
- 
stripStrips whitespace from the start and end of a String.
- 
stripToNullReturns null if the stripped string is empty.
- 
stripToEmptyReturns an empty string ("") if the string is null or empty after stripping
- 
stripCharsStrips the specified characters from the beginning and end of the string.
- 
equalsNull-safe string equals.
- 
equalsIgnoreCaseNull-safe string equals. Ignores case
- 
compareNull-safe string compare.
- 
compareIgnoreCaseNull-safe string compare. Ignores case
- 
compareNullIsMoreNull-safe string compare. Where null is greater than not null.
- 
compareIgnoreCaseNullIsMoreNull-safe string compare. Where null is greater than not null. Ignores case
- 
indexOfReturns the index of the given substring with the string starting at the given position.
- 
indexOfIgnoreCaseReturns the index of the given substring with the string starting at the given position. Ignores case.
- 
lastIndexOfReturns the index of the last occurrence of the given substring.
- 
lastIndexOfIgnoreCaseReturns the index of the last occurrence of the given substring. Ignores case.
- 
containsWhether the string contains the substring
- 
notContainsThe inverse ofcontains(Object, CharSequence)
- 
containsIgnoreCaseWhether the string contains the substring. Ignores case.
- 
notContainsIgnoreCaseThe inverse ofnotContainsIgnoreCase(Object, CharSequence).
- 
containsWhitespaceWhether the string contains whitespace.
- 
substringGets a substring defined by start and end indices from the specified string safely.
- 
leftMostGets a substring from the left-most characters.
- 
rightMostGets a substring from the right-most characters.
- 
splitSplits the provided string into an array by the separator string specified.- Parameters:
- str- String to split
- separator- Separator to separate on
- Returns:
- Split string array
 
- 
splitToListSplits the provided string into a list instead of an array.
- 
joinJoins the elements of the provided array into a single String containing the provided of elements
- 
joinWithJoins the elements of the provided array into a single String containing the provided of elements, placing the given separator between elements
- 
joinWithJoins the elements of the provided iterable into a single String containing the provided of elements, placing the given separator between elements
- 
deleteWhitespaceDeletes all whitespaces from a String as defined byCharacter.isWhitespace(char).
- 
removeRemoves all occurrences of a substring from within the source string.
- 
removeIgnoreCaseRemoves all occurrences of a substring from within the source string. Ignores case
- 
replaceAll@Nullable public final String replaceAll(@Nullable String text, @Nullable String regex, @Nullable String replacement) Replaces each substring of the text String that matches the given regular expression with the given replacement. This method is a nullsafe equivalent to:- text.replaceAll(regex, replacement)
- Pattern.compile(regex).matcher(text).replaceAll(replacement)
 
- 
replace@Nullable public final String replace(@Nullable String text, @Nullable String replaceTxt, @Nullable String replacement) Replaces each substring of the text String that matches the given regular expression with the given replacement up totimesToReplace.- Parameters:
- text- text to search and replace in
- replaceTxt- text to replace
- replacement- what to replace text with
- Returns:
- string with replacements
 
- 
replaceIgnoreCase@Nullable public final String replaceIgnoreCase(@Nullable String text, @Nullable String replaceTxt, @Nullable String replacement) Replaces each substring of the text String that matches the given regular expression with the given replacement up totimesToReplace. Ignores case.- Parameters:
- text- text to search and replace in
- replaceTxt- text to replace
- replacement- what to replace text with
- Returns:
- string with replacements
 
- 
chompRemoves one newline from end of the string if present
- 
chopRemove the last character from a string
- 
lengthNull-safe get string length
- 
toUpperNull-safe convert to uppercase
- 
toLowerNull-safe convert to lowercase
- 
capitalizeNull-safe convert to title case
- 
reverseNull-safe string reverse
- 
startsWithWhether the text starts with the prefix
- 
startsWithIgnoreCaseWhether the text starts with the prefix. Ignores case.
- 
endsWithWhether the text ends with the prefix.
- 
endsWithIgnoreCaseWhether the text ends with the prefix. Ignores case.
- 
wrapWraps a string with a string.
- 
wrapIfMissingWraps a string with a string if not already present.
- 
unwrapUnwraps a given string from anther string.
- 
convertObjectToString
 
-