Class QueryTokenizer

java.lang.Object
com.graphql_java_generator.client.request.QueryTokenizer

public class QueryTokenizer
extends java.lang.Object
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

    Fields 
    Modifier and Type Field Description
    static java.lang.String EMPTY_DELIMITERS
    The list of character that can separate tokens, and that has no meaning.
    static java.lang.String MEANINGFUL_DELIMITERS  
  • Constructor Summary

    Constructors 
    Constructor Description
    QueryTokenizer​(java.lang.String graphQLRequest)
    Create a tokenizer for the given GraphQL query
  • Method Summary

    Modifier and Type Method Description
    boolean checkNextToken​(java.lang.String expected)
    Checks if the next meaningful token is the expected string that is given.
    boolean checkNextTokenStartsWith​(java.lang.String expectedStart)
    Checks if the next meaningful token starts by the expected string that is given.
    boolean hasMoreTokens()
    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.
    java.lang.String nextToken()
    Returns the next token.
    java.lang.String nextToken​(boolean returnEmptyDelimiters)
    Returns the next token, which may or may not be an empty one, depending on returnEmptyDelimiters
    java.lang.String readNextRealToken​(java.lang.String expected, java.lang.String action)
    Reads the next real token, that is the next token that is not a separator

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • QueryTokenizer

      public QueryTokenizer​(java.lang.String graphQLRequest)
      Create a tokenizer for the given GraphQL query
      Parameters:
      graphQLRequest -
      Throws:
      java.lang.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 the EMPTY_DELIMITERS are not sent.
      Returns:
      true if there are real token or meaningful delimiters left to read
    • nextToken

      public java.lang.String nextToken()
      Returns the next token. The characters that exist in the MEANINGFUL_DELIMITERS are sent one character by one character. The characters that exist in the EMPTY_DELIMITERS are not sent.
      Returns:
    • nextToken

      public java.lang.String nextToken​(boolean returnEmptyDelimiters)
      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 the EMPTY_DELIMITERS are not sent.
      Returns:
    • checkNextToken

      public boolean checkNextToken​(java.lang.String expected)
      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

      public boolean checkNextTokenStartsWith​(java.lang.String expectedStart)
      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 java.lang.String readNextRealToken​(java.lang.String expected, java.lang.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 value
      action - 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