Class QueryParser<T extends Storable>

java.lang.Object
com.codingchili.core.storage.QueryParser<T>
All Implemented Interfaces:
StringQueryParser<T>

public class QueryParser<T extends Storable> extends Object implements StringQueryParser<T>
parses a query in string format.

Implementation is pluggable.

  • Constructor Details

    • QueryParser

      public QueryParser(Supplier<QueryBuilder<T>> builders)
      Parameters:
      builders - a query builder to use.
  • Method Details

    • nextComparable

      public static Comparable nextComparable(Matcher matcher)
      Parameters:
      matcher - the matcher to get the next comparable. from/
      Returns:
      a typed comparable.
    • toComparable

      public static Comparable toComparable(String string)
      Converts the given input string into a comparable depending on its content.
      Parameters:
      string - a string that may either represent an integer, double, boolean or a string.
      Returns:
      the parsed data type.
    • nextComparableArray

      public static Comparable[] nextComparableArray(Matcher matcher)
      Parameters:
      matcher - the matcher to retrieve comparables from.
      Returns:
      an array of comparables, parsed from an input list "one,two,three" and separated by comma.
    • parse

      public QueryBuilder<T> parse(String expression)
      Description copied from interface: StringQueryParser
      Parses a string into a builder.
      Specified by:
      parse in interface StringQueryParser<T extends Storable>
      Parameters:
      expression - the expression to parse.
      Returns:
      the constructed query
    • next

      public static void next(Matcher matcher)
      Moves the matcher onto the next matching token, throwing an error if there is no next token.
      Parameters:
      matcher - the matcher to move.
    • nextValue

      public static String nextValue(Matcher matcher)
      Move the parser and then extract the value of the token.
      Parameters:
      matcher - the matcher to extract the value from.
      Returns:
      the unquoted value or the function value. example: remove(id = 5) calls the 'remove' function, this method returns id = 5.
    • value

      public static String value(Matcher matcher)
      Extract the value of the token.
      Parameters:
      matcher - the matcher to extract the value from.
      Returns:
      the unquoted value or the function value. example: remove(id = 5) calls the 'remove' function, this method returns id = 5.
    • defaults

      public static Map<String,​BiConsumer<QueryBuilder<?>,​Matcher>> defaults()
      Allow injection of custom operations for all QueryParser instances.
      Returns:
      a map of defaults operations.
    • customize

      public Map<String,​BiConsumer<QueryBuilder<?>,​Matcher>> customize()
      Allows injection of custom defaults into the current instance.
      Returns:
      a map of custom operations which may be modified.