Top Description Fields Constructors Methods
org.eclipse.persistence.jpa.jpql

public final Class ExpressionTools

extends Object
Class Inheritance
Annotations
@SuppressWarnings:nls
Imports
java.util.regex.Pattern

A utility class containing various methods related to the Hermes parser.

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.

Author
Pascal Filion
Since
2.3
Version
2.6

Field Summary

Modifier and TypeField and Description
public static final Pattern
DOUBLE_REGEXP

The Pattern representing the regular expression of a numerical value as a double.

public static final Object[]
EMPTY_ARRAY

The constant of an empty array.

public static final String
EMPTY_STRING

The constant for an empty string.

public static final String[]
EMPTY_STRING_ARRAY

The constant of an empty String array.

public static final Pattern
FLOAT_REGEXP

The Pattern representing the regular expression of a numerical value as a float.

public static final Pattern
INTEGER_REGEXP

The Pattern representing the regular expression of a numerical value as an integer.

public static final Pattern
LONG_REGEXP

The Pattern representing the regular expression of a numerical value as a long.

Constructor Summary

AccessConstructor and Description
private
ExpressionTools()

ExpressionTools cannot be instantiated.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

The new sequence of characters that does not contain any escape character but it's literal representation
escape
(CharSequence
The sequence of characters to convert any escape character
value
,
int[]
This is a one element array that needs to be adjusted when an escape character is converted
position
)

Converts the escape characters contained in the given CharSequence to their literal representation.

public static boolean

Returns:

true if the identifier is followed by '('; false otherwise
isFunctionExpression
(WordParser
The text to parse based on the current position of the cursor
wordParser
,
String
The identifier to verify if it's for an expression or for possibly for a variable name
identifier
)

Determines whether the JPQL fragment is an expression of the form <IDENTIFIER>(.

public static boolean

Returns:

true if the given character cannot be used directly in a string
isJavaEscapedCharacter
(char
The character to check if it can directly be used in a string or should be escaped
character
)

Determines whether the given character should be escaped when being part of a string, i.e. '\r' should be "\\r".

public static boolean

Returns:

true if the given character is either : or ?; false otherwise
isParameter
(char
The character to check if it's a parameter
character
)

Determines whether the given character is the character used to identify an input parameter, either a named parameter or position parameter.

public static boolean

Returns:

true if the given character is either ' or "; false otherwise
isQuote
(char
The character to check if it's a quote
character
)

Determines whether the given character is the single or double quote.

public static boolean

Returns:

true if the given character is either whitespace or non-breaking space; false otherwise
isWhiteSpace
(char
The character to check if it's whitespace
character
)

Determines whether the given character is whitespace.

public static String

Returns:

The quoted text
quote
(String
The original text to quote
text
)

Returns the given string literal by wrapping it with single quotes.

public static void
reposition(CharSequence
The query where the positions are pointing
query1
,
int[]
An array of either one or two elements positioned within query1
positions
,
CharSequence
The query for which the positions might need adjustment
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.

public static int

Returns:

The adjusted position by moving it based on the difference between query1 and query2
repositionCursor
(CharSequence
The query where the positions are pointing
query1
,
int
The position of a cursor within query1
position1
,
CharSequence
The query for which the position might need adjustment
query2
)

Adjusts the position, which is based on the given query1, by translating it to be at the equivalent position within query2.

public static void
repositionJava(CharSequence
The query that may contain escape characters
query
,
int[]
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
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).

public static boolean

Returns:

true if the given string begins with the given prefix and ignores the case; false otherwise
startWithIgnoreCase
(String
The string to check if its beginning matches the prefix
string
,
String
The prefix used to test matching the beginning of the sequence of characters
prefix
)

Determines whether the given string starts with the given prefix and ignores the case.

public static boolean

Returns:

true if the given string is null or only contains whitespace; false otherwise
stringIsEmpty
(CharSequence
The sequence of character to test if it is null or only contains whitespace
text
)

Determines whether the specified string is null, empty, or contains only whitespace characters.

public static boolean

Returns:

true if the given string is NOT null or has at least one non-whitespace character; false otherwise
stringIsNotEmpty
(CharSequence
The sequence of character to test if it is NOT null or does not only contain whitespace
text
)

Determines whether the specified string is NOT null, NOT empty, or contains at least one non-whitespace character.

public static boolean

Returns:

true if both values are different; false otherwise
stringsAreDifferentIgnoreCase
(CharSequence
The first value to check for equality and equivalency
value1
,
CharSequence
The second value to check for equality and equivalency
value2
)

Determines whether the two sequence of characters are different, with the appropriate null checks and the case is ignored.

public static boolean

Returns:

true if both values are null, equal or equivalent; false otherwise
stringsAreEqualIgnoreCase
(CharSequence
The first value to check for equality and equivalency
value1
,
CharSequence
The second value to check for equality and equivalency
value2
)

Determines whether the two sequence of characters are equal or equivalent, with the appropriate null checks and the case is ignored.

public static String

Returns:

The new sequence of characters that contains escape characters rather than their string representation
unescape
(CharSequence
The sequence of characters to convert to an escaped version
value
,
int[]
This is a one element array that needs to be adjusted when an escape character is converted
position
)

Converts the string representation of the escape characters contained by the given CharSequence into the actual escape characters.

public static String

Returns:

The unquoted text
unquote
(String
The original text to unquote if it has ' at the beginning and the end
text
)

Returns the string literal without the single or double quotes.

public static boolean

Returns:

true if both values are different; true if they are both null, equal or equivalent
valuesAreDifferent
(Object
The first value to check for equality and equivalency
value1
,
Object
The second value to check for equality and equivalency
value2
)

Determines whether the values are different, with the appropriate null checks.

public static boolean

Returns:

true if both values are null, equal or equivalent; false otherwise
valuesAreEqual
(Object
The first value to check for equality and equivalency
value1
,
Object
The second value to check for equality and equivalency
value2
)

Determines whether the values are equal or equivalent, with the appropriate null checks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DOUBLE_REGEXPback to summary
public static final Pattern DOUBLE_REGEXP

The Pattern representing the regular expression of a numerical value as a double.

EMPTY_ARRAYback to summary
public static final Object[] EMPTY_ARRAY

The constant of an empty array.

EMPTY_STRINGback to summary
public static final String EMPTY_STRING

The constant for an empty string.

EMPTY_STRING_ARRAYback to summary
public static final String[] EMPTY_STRING_ARRAY

The constant of an empty String array.

FLOAT_REGEXPback to summary
public static final Pattern FLOAT_REGEXP

The Pattern representing the regular expression of a numerical value as a float.

INTEGER_REGEXPback to summary
public static final Pattern INTEGER_REGEXP

The Pattern representing the regular expression of a numerical value as an integer.

LONG_REGEXPback to summary
public static final Pattern LONG_REGEXP

The Pattern representing the regular expression of a numerical value as a long.

Constructor Detail

ExpressionToolsback to summary
private ExpressionTools()

ExpressionTools cannot be instantiated.

Method Detail

escapeback to summary
public static String escape(CharSequence value, int[] position)

Converts the escape characters contained in the given CharSequence to their literal representation. For example, '\b' is converted to '\\b'.

Parameters
value:CharSequence

The sequence of characters to convert any escape character

position:int[]

This is a one element array that needs to be adjusted when an escape character is converted

Returns:String

The new sequence of characters that does not contain any escape character but it's literal representation

isFunctionExpressionback to summary
public static boolean isFunctionExpression(WordParser wordParser, String identifier)

Determines whether the JPQL fragment is an expression of the form <IDENTIFIER>(.

Parameters
wordParser:WordParser

The text to parse based on the current position of the cursor

identifier:String

The identifier to verify if it's for an expression or for possibly for a variable name

Returns:boolean

true if the identifier is followed by '('; false otherwise

isJavaEscapedCharacterback to summary
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:char

The character to check if it can directly be used in a string or should be escaped

Returns:boolean

true if the given character cannot be used directly in a string

Since
2.5
isParameterback to summary
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:char

The character to check if it's a parameter

Returns:boolean

true if the given character is either : or ?; false otherwise

isQuoteback to summary
public static boolean isQuote(char character)

Determines whether the given character is the single or double quote.

Parameters
character:char

The character to check if it's a quote

Returns:boolean

true if the given character is either ' or "; false otherwise

isWhiteSpaceback to summary
public static boolean isWhiteSpace(char character)

Determines whether the given character is whitespace. Supports non-breaking space characters

Parameters
character:char

The character to check if it's whitespace

Returns:boolean

true if the given character is either whitespace or non-breaking space; false otherwise

quoteback to summary
public static String quote(String text)

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:String

The original text to quote

Returns:String

The quoted text

Since
2.4
repositionback to summary
public static void reposition(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.

Important Note

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:CharSequence

The query where the positions are pointing

positions:int[]

An array of either one or two elements positioned within query1

query2:CharSequence

The query for which the positions might need adjustment

Since
2.5
repositionCursorback to summary
public static int repositionCursor(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.

Important Note

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:CharSequence

The query where the positions are pointing

position1:int

The position of a cursor within query1

query2:CharSequence

The query for which the position might need adjustment

Returns:int

The adjusted position by moving it based on the difference between query1 and query2

See Also
reposition(CharSequence, int[], CharSequence)
repositionJavaback to summary
public static void repositionJava(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).

The escape characters are either \b, \t, \n, \f, \r, \", \' and \0 through \7.

Important Note

The given query should contain the exact same amount of whitespace than the query used to calculate the given positions.

Parameters
query:CharSequence

The query that may contain escape characters

positions:int[]

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

Since
2.5
startWithIgnoreCaseback to summary
public static boolean startWithIgnoreCase(String string, String prefix)

Determines whether the given string starts with the given prefix and ignores the case. If the prefix is null or an empty string, then true is always returned.

Parameters
string:String

The string to check if its beginning matches the prefix

prefix:String

The prefix used to test matching the beginning of the sequence of characters

Returns:boolean

true if the given string begins with the given prefix and ignores the case; false otherwise

Since
2.5
stringIsEmptyback to summary
public static boolean stringIsEmpty(CharSequence text)

Determines whether the specified string is null, empty, or contains only whitespace characters.

Parameters
text:CharSequence

The sequence of character to test if it is null or only contains whitespace

Returns:boolean

true if the given string is null or only contains whitespace; false otherwise

stringIsNotEmptyback to summary
public static boolean stringIsNotEmpty(CharSequence text)

Determines whether the specified string is NOT null, NOT empty, or contains at least one non-whitespace character.

Parameters
text:CharSequence

The sequence of character to test if it is NOT null or does not only contain whitespace

Returns:boolean

true if the given string is NOT null or has at least one non-whitespace character; false otherwise

stringsAreDifferentIgnoreCaseback to summary
public static boolean stringsAreDifferentIgnoreCase(CharSequence value1, CharSequence value2)

Determines whether the two sequence of characters are different, with the appropriate null checks and the case is ignored.

Parameters
value1:CharSequence

The first value to check for equality and equivalency

value2:CharSequence

The second value to check for equality and equivalency

Returns:boolean

true if both values are different; false otherwise

stringsAreEqualIgnoreCaseback to summary
public static boolean stringsAreEqualIgnoreCase(CharSequence value1, CharSequence value2)

Determines whether the two sequence of characters are equal or equivalent, with the appropriate null checks and the case is ignored.

Parameters
value1:CharSequence

The first value to check for equality and equivalency

value2:CharSequence

The second value to check for equality and equivalency

Returns:boolean

true if both values are null, equal or equivalent; false otherwise

unescapeback to summary
public static String unescape(CharSequence value, int[] position)

Converts the string representation of the escape characters contained by the given CharSequence into the actual escape characters. For example, the string '\\b' is converted into the character value '\b'.

Parameters
value:CharSequence

The sequence of characters to convert to an escaped version

position:int[]

This is a one element array that needs to be adjusted when an escape character is converted

Returns:String

The new sequence of characters that contains escape characters rather than their string representation

unquoteback to summary
public static String unquote(String text)

Returns the string literal without the single or double quotes. Any two consecutive single quotes will be converted into a single quote.

Parameters
text:String

The original text to unquote if it has ' at the beginning and the end

Returns:String

The unquoted text

valuesAreDifferentback to summary
public static boolean valuesAreDifferent(Object value1, Object value2)

Determines whether the values are different, with the appropriate null checks.

Parameters
value1:Object

The first value to check for equality and equivalency

value2:Object

The second value to check for equality and equivalency

Returns:boolean

true if both values are different; true if they are both null, equal or equivalent

valuesAreEqualback to summary
public static boolean valuesAreEqual(Object value1, Object value2)

Determines whether the values are equal or equivalent, with the appropriate null checks.

Parameters
value1:Object

The first value to check for equality and equivalency

value2:Object

The second value to check for equality and equivalency

Returns:boolean

true if both values are null, equal or equivalent; false otherwise