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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier 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
-
StringExpressionVariable
public StringExpressionVariable()SetslocaletoLocale.ENGLISH -
StringExpressionVariable
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceExpressionVariable- Returns:
- Name of the variable, must not be null
-
toString
Converts the target to a string.- Parameters:
target- object to convert- Returns:
- string representation of object
-
isEmpty
Whether the string is null or empty ("") -
isNotEmpty
Whether the string is not null or empty ("") -
isBlank
Whether the string is null, empty (""), or blank (" ") -
isNotBlank
Whether the string is not null, empty(""),or blank (" ") -
trim
Removes control characters (char <= 32) from both ends of this String, handlingnullby returningnull. -
trimToNull
Returns null if the string is empty after trimming -
trimToEmpty
Returns an empty string ("") if the string is null or empty after trimming. -
notEquals
Return true if strings are not equal, else false. -
notEqualsIgnoreCase
Return true if strings are not equal, ignoring case, else false -
truncate
Creates a substring using the specified left-offset and max width. -
strip
Strips whitespace from the start and end of a String. -
stripToNull
Returns null if the stripped string is empty. -
stripToEmpty
Returns an empty string ("") if the string is null or empty after stripping -
stripChars
Strips the specified characters from the beginning and end of the string. -
equals
Null-safe string equals. -
equalsIgnoreCase
Null-safe string equals. Ignores case -
compare
Null-safe string compare. -
compareIgnoreCase
Null-safe string compare. Ignores case -
compareNullIsMore
Null-safe string compare. Where null is greater than not null. -
compareIgnoreCaseNullIsMore
Null-safe string compare. Where null is greater than not null. Ignores case -
indexOf
Returns the index of the given substring with the string starting at the given position. -
indexOfIgnoreCase
Returns the index of the given substring with the string starting at the given position. Ignores case. -
lastIndexOf
Returns the index of the last occurrence of the given substring. -
lastIndexOfIgnoreCase
Returns the index of the last occurrence of the given substring. Ignores case. -
contains
Whether the string contains the substring -
notContains
The inverse ofcontains(Object, CharSequence) -
containsIgnoreCase
Whether the string contains the substring. Ignores case. -
notContainsIgnoreCase
The inverse ofnotContainsIgnoreCase(Object, CharSequence). -
containsWhitespace
Whether the string contains whitespace. -
substring
Gets a substring defined by start and end indices from the specified string safely. -
leftMost
Gets a substring from the left-most characters. -
rightMost
Gets a substring from the right-most characters. -
split
Splits the provided string into an array by the separator string specified.- Parameters:
str- String to splitseparator- Separator to separate on- Returns:
- Split string array
-
splitToList
Splits the provided string into a list instead of an array. -
join
Joins the elements of the provided array into a single String containing the provided of elements -
joinWith
Joins the elements of the provided array into a single String containing the provided of elements, placing the given separator between elements -
joinWith
Joins the elements of the provided iterable into a single String containing the provided of elements, placing the given separator between elements -
deleteWhitespace
Deletes all whitespaces from a String as defined byCharacter.isWhitespace(char). -
remove
Removes all occurrences of a substring from within the source string. -
removeIgnoreCase
Removes 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 inreplaceTxt- text to replacereplacement- 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 inreplaceTxt- text to replacereplacement- what to replace text with- Returns:
- string with replacements
-
chomp
Removes one newline from end of the string if present -
chop
Remove the last character from a string -
length
Null-safe get string length -
toUpper
Null-safe convert to uppercase -
toLower
Null-safe convert to lowercase -
capitalize
Null-safe convert to title case -
reverse
Null-safe string reverse -
startsWith
Whether the text starts with the prefix -
startsWithIgnoreCase
Whether the text starts with the prefix. Ignores case. -
endsWith
Whether the text ends with the prefix. -
endsWithIgnoreCase
Whether the text ends with the prefix. Ignores case. -
wrap
Wraps a string with a string. -
wrapIfMissing
Wraps a string with a string if not already present. -
unwrap
Unwraps a given string from anther string. -
convertObjectToString
-