Class QueryTokenizer
java.lang.Object
com.graphql_java_generator.client.request.QueryTokenizer
This class is responsible to split the GraphQL query into meaningful tokens: the spaces, EOL (...) are removed and
the (, @, { (...) are sent as token. It also allows to check the comming tokens. For instance, when reading a field
name, it's possible to check if the next token is :, which means that the current token s not the field name, but the
field alias.
- Author:
- etienne-sf
-
Field Summary
-
Constructor Summary
ConstructorDescriptionQueryTokenizer
(String graphQLRequest) Create a tokenizer for the given GraphQL query -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkNextToken
(String expected) Checks if the next meaningful token is the expected string that is given.boolean
checkNextTokenStartsWith
(String expectedStart) Checks if the next meaningful token starts by the expected string that is given.boolean
Indicates if there are next non empty tokens in the list.boolean
hasMoreTokens
(boolean returnEmptyDelimiters) Indicates if there are next non empty tokens in the list.Returns the next token.nextToken
(boolean returnEmptyDelimiters) Returns the next token, which may or may not be an empty one, depending on returnEmptyDelimitersreadNextRealToken
(String expected, String action) Reads the next real token, that is the next token that is not a separator
-
Field Details
-
EMPTY_DELIMITERS
The list of character that can separate tokens, and that has no meaning. By default, these tokens are removed from the result, and won't be visible in the returned tokens.- See Also:
-
MEANINGFUL_DELIMITERS
- See Also:
-
-
Constructor Details
-
QueryTokenizer
Create a tokenizer for the given GraphQL query- Parameters:
graphQLRequest
-- Throws:
NullPointerException
- If graphQLRequest is null
-
-
Method Details
-
hasMoreTokens
public boolean hasMoreTokens()Indicates if there are next non empty tokens in the list.- Returns:
- true if there are real token or meaningful delimiters left to read
-
hasMoreTokens
public boolean hasMoreTokens(boolean returnEmptyDelimiters) Indicates if there are next non empty tokens in the list.- Parameters:
returnEmptyDelimiters
- If true, all token are sent, which means that every character found in the source String are sent as token. Each separator is sent one character per one character.
If false the characters that are in theEMPTY_DELIMITERS
are not sent.- Returns:
- true if there are real token or meaningful delimiters left to read
-
nextToken
Returns the next token. The characters that exist in theMEANINGFUL_DELIMITERS
are sent one character by one character. The characters that exist in theEMPTY_DELIMITERS
are not sent.- Returns:
-
nextToken
Returns the next token, which may or may not be an empty one, depending on returnEmptyDelimiters- Parameters:
returnEmptyDelimiters
- If true, all token are sent, which means that every character found in the source String are sent as token. Each separator is sent one character per one character.
If false the characters that are in theEMPTY_DELIMITERS
are not sent.- Returns:
-
checkNextToken
Checks if the next meaningful token is the expected string that is given. The index is not updated, which means that if this method returns true, the next returned token will be the expected value.- Parameters:
expected
-- Returns:
-
checkNextTokenStartsWith
Checks if the next meaningful token starts by the expected string that is given. The index is not updated, which means that if this method returns true, the next returned token will be the token that begins by the expected string.- Parameters:
expectedStart
-- Returns:
-
readNextRealToken
public String readNextRealToken(String expected, String action) throws GraphQLRequestPreparationException Reads the next real token, that is the next token that is not a separator- Parameters:
expected
- If expected is not null, this method will check that the real token read is equal to this expected valueaction
- The action for which the real token is needed (use to get some context in a the exception message, if any). The exception message will be: "error occurs while " + action- Returns:
- Throws:
GraphQLRequestPreparationException
-