public final class ExpressionTools
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
DOUBLE_REGEXP
The
Pattern representing the regular expression of a numerical value as a double. |
static java.lang.Object[] |
EMPTY_ARRAY
The constant of an empty array.
|
static java.lang.String |
EMPTY_STRING
The constant for an empty string.
|
static java.lang.String[] |
EMPTY_STRING_ARRAY
The constant of an empty String array.
|
static java.util.regex.Pattern |
FLOAT_REGEXP
The
Pattern representing the regular expression of a numerical value as a float. |
static java.util.regex.Pattern |
INTEGER_REGEXP
The
Pattern representing the regular expression of a numerical value as an integer. |
static java.util.regex.Pattern |
LONG_REGEXP
The
Pattern representing the regular expression of a numerical value as a long. |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escape(java.lang.CharSequence value,
int[] position)
Converts the escape characters contained in the given
CharSequence to their literal
representation. |
static boolean |
isFunctionExpression(WordParser wordParser,
java.lang.String identifier)
Determines whether the JPQL fragment is an expression of the form
<IDENTIFIER>( . |
static boolean |
isJavaEscapedCharacter(char character)
Determines whether the given character should be escaped when being part of a string, i.e.
|
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.
|
static boolean |
isQuote(char character)
Determines whether the given character is the single or double quote.
|
static java.lang.String |
quote(java.lang.String text)
Returns the given string literal by wrapping it with single quotes.
|
static void |
reposition(java.lang.CharSequence query1,
int[] positions,
java.lang.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 int |
repositionCursor(java.lang.CharSequence query1,
int position1,
java.lang.CharSequence query2)
Adjusts the position, which is based on the given query1, by translating it to be at
the equivalent position within query2.
|
static void |
repositionJava(java.lang.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 boolean |
startWithIgnoreCase(java.lang.String string,
java.lang.String prefix)
Determines whether the given string starts with the given prefix and ignores the case.
|
static boolean |
stringIsEmpty(java.lang.CharSequence text)
Determines whether the specified string is
null , empty, or contains only
whitespace characters. |
static boolean |
stringIsNotEmpty(java.lang.CharSequence text)
Determines whether the specified string is NOT
null , NOT empty, or contains at
least one non-whitespace character. |
static boolean |
stringsAreDifferentIgnoreCase(java.lang.CharSequence value1,
java.lang.CharSequence value2)
Determines whether the two sequence of characters are different, with the appropriate
null checks and the case is ignored. |
static boolean |
stringsAreEqualIgnoreCase(java.lang.CharSequence value1,
java.lang.CharSequence value2)
Determines whether the two sequence of characters are equal or equivalent, with the
appropriate
null checks and the case is ignored. |
static java.lang.String |
unescape(java.lang.CharSequence value,
int[] position)
Converts the string representation of the escape characters contained by the given
CharSequence into the actual escape characters. |
static java.lang.String |
unquote(java.lang.String text)
Returns the string literal without the single or double quotes.
|
static boolean |
valuesAreDifferent(java.lang.Object value1,
java.lang.Object value2)
Determines whether the values are different, with the appropriate
null checks. |
static boolean |
valuesAreEqual(java.lang.Object value1,
java.lang.Object value2)
Determines whether the values are equal or equivalent, with the appropriate
null
checks. |
public static java.util.regex.Pattern DOUBLE_REGEXP
Pattern
representing the regular expression of a numerical value as a double.public static final java.lang.Object[] EMPTY_ARRAY
public static final java.lang.String EMPTY_STRING
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static java.util.regex.Pattern FLOAT_REGEXP
Pattern
representing the regular expression of a numerical value as a float.public static java.util.regex.Pattern INTEGER_REGEXP
Pattern
representing the regular expression of a numerical value as an integer.public static java.util.regex.Pattern LONG_REGEXP
Pattern
representing the regular expression of a numerical value as a long.public static java.lang.String escape(java.lang.CharSequence value, int[] position)
CharSequence
to their literal
representation. For example, '\b' is converted to '\\b'.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 convertedpublic static boolean isFunctionExpression(WordParser wordParser, java.lang.String identifier)
<IDENTIFIER>(
.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 nametrue
if the identifier is followed by '('; false
otherwisepublic static boolean isJavaEscapedCharacter(char character)
character
- The character to check if it can directly be used in a string or should be escapedtrue
if the given character cannot be used directly in a stringpublic static boolean isParameter(char character)
character
- The character to check if it's a parametertrue
if the given character is either : or ?; false
otherwisepublic static boolean isQuote(char character)
character
- The character to check if it's a quotetrue
if the given character is either ' or "; false
otherwisepublic static java.lang.String quote(java.lang.String text)
text
- The original text to quotepublic static void reposition(java.lang.CharSequence query1, int[] positions, java.lang.CharSequence 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.
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 adjustmentpublic static int repositionCursor(java.lang.CharSequence query1, int position1, java.lang.CharSequence 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.
query1
- The query where the positions are pointingposition
- The position of a cursor within query1query2
- The query for which the position might need adjustmentreposition(CharSequence, int[], CharSequence)
public static void repositionJava(java.lang.CharSequence query, int[] positions)
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.
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 rangepublic static boolean startWithIgnoreCase(java.lang.String string, java.lang.String prefix)
null
or an empty string, then true
is always returned.string
- The string to check if its beginning matches the prefixprefix
- The prefix used to test matching the beginning of the sequence of characterstrue
if the given string begins with the given prefix and ignores the
case; false
otherwisepublic static boolean stringIsEmpty(java.lang.CharSequence text)
null
, empty, or contains only
whitespace characters.text
- The sequence of character to test if it is null
or only contains
whitespacetrue
if the given string is null
or only contains whitespace;
false
otherwisepublic static boolean stringIsNotEmpty(java.lang.CharSequence text)
null
, NOT empty, or contains at
least one non-whitespace character.text
- The sequence of character to test if it is NOT null
or does not only
contain whitespacetrue
if the given string is NOT null
or has at least one
non-whitespace character; false
otherwisepublic static boolean stringsAreDifferentIgnoreCase(java.lang.CharSequence value1, java.lang.CharSequence value2)
null
checks and the case is ignored.value1
- The first value to check for equality and equivalencyvalue2
- The second value to check for equality and equivalencytrue
if both values are different; false
otherwisepublic static boolean stringsAreEqualIgnoreCase(java.lang.CharSequence value1, java.lang.CharSequence value2)
null
checks and the case is ignored.value1
- The first value to check for equality and equivalencyvalue2
- The second value to check for equality and equivalencytrue
if both values are null
, equal or equivalent;
false
otherwisepublic static java.lang.String unescape(java.lang.CharSequence value, int[] position)
CharSequence
into the actual escape characters. For example, the string '\\b' is converted
into the character value '\b'.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 convertedpublic static java.lang.String unquote(java.lang.String text)
text
- The original text to unquote if it has ' at the beginning and the endpublic static boolean valuesAreDifferent(java.lang.Object value1, java.lang.Object value2)
null
checks.value1
- The first value to check for equality and equivalencyvalue2
- The second value to check for equality and equivalencytrue
if both values are different; true
if they are both
null
, equal or equivalentpublic static boolean valuesAreEqual(java.lang.Object value1, java.lang.Object value2)
null
checks.value1
- The first value to check for equality and equivalencyvalue2
- The second value to check for equality and equivalencytrue
if both values are null
, equal or equivalent;
false
otherwise