Class ExpressionTools
Provisional API: This interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.
- Version:
- 2.6
- Author:
- Pascal Filion
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternThePatternrepresenting the regular expression of a numerical value as a double.static final Object[]The constant of an empty array.static final StringThe constant for an empty string.static final String[]The constant of an empty String array.static final PatternThePatternrepresenting the regular expression of a numerical value as a float.static final PatternThePatternrepresenting the regular expression of a numerical value as an integer.static final PatternThePatternrepresenting the regular expression of a numerical value as a long. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringescape(CharSequence value, int[] position) Converts the escape characters contained in the givenCharSequenceto their literal representation.static booleanisFunctionExpression(WordParser wordParser, String identifier) Determines whether the JPQL fragment is an expression of the form<IDENTIFIER>(.static booleanisJavaEscapedCharacter(char character) Determines whether the given character should be escaped when being part of a string, i.e.static booleanisParameter(char character) Determines whether the given character is the character used to identify an input parameter, either a named parameter or position parameter.static booleanisQuote(char character) Determines whether the given character is the single or double quote.static booleanisWhiteSpace(char character) Determines whether the given character is whitespace.static StringReturns the given string literal by wrapping it with single quotes.static voidreposition(CharSequence query1, int[] positions, CharSequence query2) Adjusts the positions contained by the given array of either one or two elements, which is based on the given query1, by translating those positions to be at the equivalent position within query2.static intrepositionCursor(CharSequence query1, int position1, CharSequence query2) Adjusts the position, which is based on the given query1, by translating it to be at the equivalent position within query2.static voidrepositionJava(CharSequence query, int[] positions) Re-adjusts the given positions, which is based on the non-escaped version of the given query, by making sure it is pointing at the same position within query, which contains references (escape characters).static booleanstartWithIgnoreCase(String string, String prefix) Determines whether the given string starts with the given prefix and ignores the case.static booleanstringIsEmpty(CharSequence text) Determines whether the specified string isnull, empty, or contains only whitespace characters.static booleanstringIsNotEmpty(CharSequence text) Determines whether the specified string is NOTnull, NOT empty, or contains at least one non-whitespace character.static booleanstringsAreDifferentIgnoreCase(CharSequence value1, CharSequence value2) Determines whether the two sequence of characters are different, with the appropriatenullchecks and the case is ignored.static booleanstringsAreEqualIgnoreCase(CharSequence value1, CharSequence value2) Determines whether the two sequence of characters are equal or equivalent, with the appropriatenullchecks and the case is ignored.static Stringunescape(CharSequence value, int[] position) Converts the string representation of the escape characters contained by the givenCharSequenceinto the actual escape characters.static StringReturns the string literal without the single or double quotes.static booleanvaluesAreDifferent(Object value1, Object value2) Determines whether the values are different, with the appropriatenullchecks.static booleanvaluesAreEqual(Object value1, Object value2) Determines whether the values are equal or equivalent, with the appropriatenullchecks.
-
Field Details
-
DOUBLE_REGEXP
ThePatternrepresenting the regular expression of a numerical value as a double. -
EMPTY_ARRAY
The constant of an empty array. -
EMPTY_STRING
The constant for an empty string.- See Also:
-
EMPTY_STRING_ARRAY
The constant of an empty String array. -
FLOAT_REGEXP
ThePatternrepresenting the regular expression of a numerical value as a float. -
INTEGER_REGEXP
ThePatternrepresenting the regular expression of a numerical value as an integer. -
LONG_REGEXP
ThePatternrepresenting the regular expression of a numerical value as a long.
-
-
Method Details
-
escape
Converts the escape characters contained in the givenCharSequenceto their literal representation. For example, '\b' is converted to '\\b'.- Parameters:
value- The sequence of characters to convert any escape characterposition- This is a one element array that needs to be adjusted when an escape character is converted- Returns:
- The new sequence of characters that does not contain any escape character but it's literal representation
-
isFunctionExpression
Determines whether the JPQL fragment is an expression of the form<IDENTIFIER>(.- Parameters:
wordParser- The text to parse based on the current position of the cursoridentifier- The identifier to verify if it's for an expression or for possibly for a variable name- Returns:
trueif the identifier is followed by '(';falseotherwise
-
isJavaEscapedCharacter
public static boolean isJavaEscapedCharacter(char character) Determines whether the given character should be escaped when being part of a string, i.e. '\r' should be "\\r".- Parameters:
character- The character to check if it can directly be used in a string or should be escaped- Returns:
trueif the given character cannot be used directly in a string
-
isParameter
public static boolean isParameter(char character) Determines whether the given character is the character used to identify an input parameter, either a named parameter or position parameter.- Parameters:
character- The character to check if it's a parameter- Returns:
trueif the given character is either : or ?;falseotherwise
-
isQuote
public static boolean isQuote(char character) Determines whether the given character is the single or double quote.- Parameters:
character- The character to check if it's a quote- Returns:
trueif the given character is either ' or ";falseotherwise
-
isWhiteSpace
public static boolean isWhiteSpace(char character) Determines whether the given character is whitespace. Supports non-breaking space characters- Parameters:
character- The character to check if it's whitespace- Returns:
trueif the given character is either whitespace or non-breaking space;falseotherwise
-
quote
Returns the given string literal by wrapping it with single quotes. Any single quote within the string will be escaped with another single quote.- Parameters:
text- The original text to quote- Returns:
- The quoted text
-
reposition
Adjusts the positions contained by the given array of either one or two elements, which is based on the given query1, by translating those positions to be at the equivalent position within query2.Important: The two JPQL queries should contain the same characters but the amount of whitespace can differ. One cannot have the escape characters and the other one has the Unicode characters.
- Parameters:
query1- The query where the positions are pointingpositions- An array of either one or two elements positioned within query1query2- The query for which the positions might need adjustment
-
repositionCursor
Adjusts the position, which is based on the given query1, by translating it to be at the equivalent position within query2.Important: The two JPQL queries should contain the same characters but the amount of whitespace can differ. One cannot have the escape characters and the other one has the Unicode characters.
- Parameters:
query1- The query where the positions are pointingposition1- The position of a cursor within query1query2- The query for which the position might need adjustment- Returns:
- The adjusted position by moving it based on the difference between query1 and query2
- See Also:
-
repositionJava
Re-adjusts the given positions, which is based on the non-escaped version of the given query, by making sure it is pointing at the same position within query, which contains references (escape characters).The escape characters are either \b, \t, \n, \f, \r, \", \' and \0 through \7.
Important: The given query should contain the exact same amount of whitespace than the query used to calculate the given positions.
- Parameters:
query- The query that may contain escape characterspositions- The position within the non-escaped version of the given query, which is either a single element position or two positions that is used as a text range. After execution contains the adjusted positions by moving it based on the difference between the escape and non-escaped versions of the query
-
startWithIgnoreCase
Determines whether the given string starts with the given prefix and ignores the case. If the prefix isnullor an empty string, thentrueis always returned.- Parameters:
string- The string to check if its beginning matches the prefixprefix- The prefix used to test matching the beginning of the sequence of characters- Returns:
trueif the given string begins with the given prefix and ignores the case;falseotherwise
-
stringIsEmpty
Determines whether the specified string isnull, empty, or contains only whitespace characters.- Parameters:
text- The sequence of character to test if it isnullor only contains whitespace- Returns:
trueif the given string isnullor only contains whitespace;falseotherwise
-
stringIsNotEmpty
Determines whether the specified string is NOTnull, NOT empty, or contains at least one non-whitespace character.- Parameters:
text- The sequence of character to test if it is NOTnullor does not only contain whitespace- Returns:
trueif the given string is NOTnullor has at least one non-whitespace character;falseotherwise
-
stringsAreDifferentIgnoreCase
Determines whether the two sequence of characters are different, with the appropriatenullchecks and the case is ignored.- Parameters:
value1- The first value to check for equality and equivalencyvalue2- The second value to check for equality and equivalency- Returns:
trueif both values are different;falseotherwise
-
stringsAreEqualIgnoreCase
Determines whether the two sequence of characters are equal or equivalent, with the appropriatenullchecks and the case is ignored.- Parameters:
value1- The first value to check for equality and equivalencyvalue2- The second value to check for equality and equivalency- Returns:
trueif both values arenull, equal or equivalent;falseotherwise
-
unescape
Converts the string representation of the escape characters contained by the givenCharSequenceinto the actual escape characters. For example, the string '\\b' is converted into the character value '\b'.- Parameters:
value- The sequence of characters to convert to an escaped versionposition- This is a one element array that needs to be adjusted when an escape character is converted- Returns:
- The new sequence of characters that contains escape characters rather than their string representation
-
unquote
Returns the string literal without the single or double quotes. Any two consecutive single quotes will be converted into a single quote.- Parameters:
text- The original text to unquote if it has ' at the beginning and the end- Returns:
- The unquoted text
-
valuesAreDifferent
Determines whether the values are different, with the appropriatenullchecks.- Parameters:
value1- The first value to check for equality and equivalencyvalue2- The second value to check for equality and equivalency- Returns:
trueif both values are different;trueif they are bothnull, equal or equivalent
-
valuesAreEqual
Determines whether the values are equal or equivalent, with the appropriatenullchecks.- Parameters:
value1- The first value to check for equality and equivalencyvalue2- The second value to check for equality and equivalency- Returns:
trueif both values arenull, equal or equivalent;falseotherwise
-