public final class WordParser
extends java.lang.Object
Expression object to parse its fragment of the query.
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 | Class and Description |
|---|---|
static class |
WordParser.WordType
This enumeration determines the type of word that was scanned.
|
| Constructor and Description |
|---|
WordParser(java.lang.CharSequence text)
Creates a new
WordParser. |
| Modifier and Type | Method and Description |
|---|---|
char |
character()
Retrieves the character at the current cursor position.
|
char |
character(int position)
Retrieves the character at the given cursor position.
|
boolean |
endsWith(int endPosition,
java.lang.String suffix)
Determines whether the query ends with the given suffix and the end position is the end of the
range for testing.
|
boolean |
endsWithIgnoreCase(int endPosition,
java.lang.String suffix)
Determines whether the query ends with the given suffix and the end position is the end of the
range for testing.
|
java.lang.String |
entireWord()
Retrieves a word starting at the current position.
|
java.lang.String |
entireWord(int position)
Retrieves a word starting at the given position.
|
WordParser.WordType |
getWordType()
Returns what the type of word
word() returns. |
boolean |
isArithmeticSymbol(char character)
Determines whether the given character is an arithmetic symbol, which is one of the following:
{ '>', '<', '/', '*', '-', '+', '=', '{'} .
|
boolean |
isDelimiter(char character)
Determines whether the given character is a delimiter.
|
boolean |
isDigit(char character)
Determines whether the given character is a character that can be used in a number.
|
boolean |
isTail()
Determines whether the position of the cursor is at the end of the text.
|
boolean |
isWordSeparator(char character)
Determines whether the given character is not considered to be part of a word (which is
usually comprise of alphanumeric characters).
|
int |
length()
Returns the length of the string value.
|
void |
moveBackward(java.lang.CharSequence word)
Moves the position of the cursor by the length of the given word.
|
void |
moveBackward(int position)
Moves backward the position of the cursor by the given amount.
|
java.lang.String |
moveForward(java.lang.CharSequence word)
Moves the position of the cursor by the length of the given word.
|
java.lang.String |
moveForward(int position)
Moves forward the position of the cursor by the given amount.
|
java.lang.String |
moveForwardIgnoreWhitespace(java.lang.CharSequence word)
Moves the position of the cursor by the length of the given word and ignore any different in
whitespace count.
|
java.lang.String |
numericLiteral()
Retrieves the numeric literal that should be the current word to parse.
|
java.lang.String |
partialWord()
Retrieves a word before the current position of the cursor, which determines when the parsing
stop.
|
java.lang.String |
partialWord(int position)
Retrieves a word before the specified position, which determines when the parsing stop.
|
int |
partialWordStartPosition(int position)
Finds the beginning of the word and the given position is within that word.
|
int |
position()
Returns the current position of the cursor.
|
void |
setPosition(int position)
Manually sets the position of the cursor within the string.
|
int |
skipLeadingWhitespace()
Removes the whitespace that starts the given text.
|
boolean |
startsWith(char possibleCharacter)
Determines whether the text starts with the given character.
|
boolean |
startsWith(java.lang.CharSequence prefix)
Tests whether the query starts with the specified prefix from the current position.
|
boolean |
startsWith(java.lang.CharSequence prefix,
int startIndex)
Tests whether the substring of the query beginning at the specified index starts with the
specified prefix.
|
boolean |
startsWithArithmeticOperator()
Determines whether the character at the current position is one of the arithmetic operators:
{ '+', '-', '*', '/' },
|
java.lang.Boolean |
startsWithDigit()
Determines if the text starts with a digit (
true), an arithmetic term
(false) or anything else (null). |
boolean |
startsWithIdentifier(java.lang.CharSequence identifier)
Determines whether the text at the current position start with the following identifier.
|
boolean |
startsWithIdentifier(java.lang.CharSequence identifier,
int position)
Determines whether the text at the current position start with the following identifier.
|
boolean |
startsWithIgnoreCase(char possibleCharacter)
Determines whether the text starts with the given character.
|
boolean |
startsWithIgnoreCase(java.lang.CharSequence prefix)
Tests if the string starts with the specified prefix.
|
boolean |
startsWithIgnoreCase(java.lang.CharSequence prefix,
int offset)
Tests if the string starts with the specified prefix.
|
java.lang.String |
substring()
Returns a substring that is within the current position of the cursor and the end of the text.
|
java.lang.String |
substring(int startIndex)
Returns a substring that is within the given position and the end of the text.
|
java.lang.String |
substring(int startIndex,
int endIndex)
Returns a substring that is within the given positions.
|
java.lang.String |
toString() |
int |
whitespaceCount()
Calculates the number of whitespace that are in the query.
|
int |
whitespaceCount(int position)
Calculates the number of whitespace that are in the query.
|
java.lang.String |
word()
Retrieves the first word starting at the current position.
|
int |
wordEndPosition()
Returns the position a word would end based on the current cursor position.
|
int |
wordEndPosition(int position)
Returns the position a word would end based on the given start position.
|
public WordParser(java.lang.CharSequence text)
WordParser.text - The string representation of the JPQL querypublic char character()
public char character(int position)
position - The position of the character to returnpublic boolean endsWith(int endPosition,
java.lang.String suffix)
endPosition - The position where the check stopssuffix - The suffix is the text that is used to match it with the substring within the texttrue if the character sequence represented by the argument is a suffix of
the query; false otherwisepublic boolean endsWithIgnoreCase(int endPosition,
java.lang.String suffix)
endPosition - The position where the check stopssuffix - The suffix is the text that is used to match it with the substring within the texttrue if the character sequence represented by the argument is a suffix of
the query; false otherwisepublic java.lang.String entireWord()
For instance, "SELECT AVG(e.age) FROM Employee e":
public java.lang.String entireWord(int position)
For instance, "SELECT AVG(e.age) FROM Employee e":
position - The position where to retrieve the wordpublic WordParser.WordType getWordType()
word() returns.word()public boolean isArithmeticSymbol(char character)
character - The character to test if it's a math symboltrue if the given character is one of the valid math symbols;
false otherwisepublic boolean isDelimiter(char character)
character - The character to testtrue if the given character is a delimiter; false otherwisepublic boolean isDigit(char character)
character - The character to test if it's a digittrue if the given character is a digit; false otherwisepublic boolean isTail()
true if the position of the cursor is at the end of the text;
false otherwisepublic boolean isWordSeparator(char character)
character - The character used to determine if it should be part of a word or nottrue if the character can be part of a word; false if it is
not an alphanumeric character, which usually means is a whitespace, a delimiter or an
arithmetic symbolCharacter.isWhitespace(char),
isArithmeticSymbol(char),
isDelimiter(char)public int length()
public void moveBackward(java.lang.CharSequence word)
word - The word used to determine how much to move the position forwardpublic void moveBackward(int position)
position - The amount to remove from the current positionpublic java.lang.String moveForward(java.lang.CharSequence word)
word - The word used to determine how much to move the position forwardpublic java.lang.String moveForward(int position)
position - The amount to add to the current positionpublic java.lang.String moveForwardIgnoreWhitespace(java.lang.CharSequence word)
word - The word used to determine how much to move the position forwardpublic java.lang.String numericLiteral()
public java.lang.String partialWord()
For instance, "SELECT AVG(e.age) FROM Employee e":
public java.lang.String partialWord(int position)
For instance, "SELECT AVG(e.age) FROM Employee e":
position - The position of the cursorpublic int partialWordStartPosition(int position)
For instance, "SELECT AVG(e.age) FROM Employee e":
position - The position from which the search endspublic int position()
public void setPosition(int position)
position - The new position of the cursorpublic int skipLeadingWhitespace()
public boolean startsWith(char possibleCharacter)
possibleCharacter - The possible character at the current positiontrue if the text starts with the given character at the current position;
false otherwisepublic boolean startsWith(java.lang.CharSequence prefix)
prefix - The prefixtrue if the character sequence represented by the argument is a prefix of
the text; false otherwisepublic boolean startsWith(java.lang.CharSequence prefix,
int startIndex)
prefix - The prefixstartIndex - Where to begin looking in the querytrue if the character sequence represented by the
argument is a prefix of the substring of this object starting at index startIndex;
false otherwisepublic boolean startsWithArithmeticOperator()
true if the character at the current position is an arithmetic operator;
false otherwisepublic java.lang.Boolean startsWithDigit()
true), an arithmetic term
(false) or anything else (null).true if the text starts with a digit (we'll assume it is a digit if the
text starts with a digit or an arithmetic sign followed by a digit), false if it
starts with an arithmetic term (we'll assume it is a digit followed by a non-digit character);
otherwise returns nullpublic boolean startsWithIdentifier(java.lang.CharSequence identifier)
identifier - The JPQL identifier to match with the text at the current positiontrue if the text starts with the given text (case is ignored) and the
cursor is at the end of the text or is following by a word separator character; false
otherwisepublic boolean startsWithIdentifier(java.lang.CharSequence identifier,
int position)
identifier - The JPQL identifier to match with the text at the current positionposition - The position to start matching the characterstrue if the text starts with the given text (case is ignored) and the
cursor is at the end of the text or is following by a word separator character; false
otherwisepublic boolean startsWithIgnoreCase(char possibleCharacter)
possibleCharacter - The possible character at the current positiontrue if the text starts with the given character at the current position;
false otherwisepublic boolean startsWithIgnoreCase(java.lang.CharSequence prefix)
prefix - The prefix to test againsttrue if the character sequence represented by the argument is a prefix of
the character sequence represented by this string; false otherwise. Note also
that true will be returned if the argument is an empty string or is equal to this
String object as determined by the Object.equals(Object) methodpublic boolean startsWithIgnoreCase(java.lang.CharSequence prefix,
int offset)
prefix - The prefix to test againstoffset - Where to begin looking in this stringtrue if the character sequence represented by the argument is a prefix of
the character sequence represented by this string; false otherwisepublic java.lang.String substring()
public java.lang.String substring(int startIndex)
startIndex - The beginning of the substring, inclusivepublic java.lang.String substring(int startIndex,
int endIndex)
startIndex - The beginning of the substring, inclusiveendIndex - The end of the substring, exclusivepublic java.lang.String toString()
toString in class java.lang.Objectpublic int whitespaceCount()
public int whitespaceCount(int position)
position - The position from where the scan startspublic java.lang.String word()
public int wordEndPosition()
getWordType()
can be used to determine the type of word that was scanned.WordParser.word(),
WordParser.WordTypepublic int wordEndPosition(int position)
getWordType()
can be used to determine the type of word that was scanned.position - The position to start scanning the textWordParser.word(),
WordParser.WordType