Class QueryBuilder<T,Q extends QueryBuilder<T,Q>>
- java.lang.Object
- 
- com.google.gerrit.index.query.QueryBuilder<T,Q>
 
- 
- Type Parameters:
- T- type of object the predicates can evaluate in memory.
 - Direct Known Subclasses:
- AccountQueryBuilder,- ChangeQueryBuilder,- GroupQueryBuilder,- ProjectQueryBuilder
 
 public abstract class QueryBuilder<T,Q extends QueryBuilder<T,Q>> extends Object Base class to support writing parsers for query languages.Subclasses may document their supported query operators by declaring public methods that perform the query conversion into a Predicate. For example, to support "is:starred", "is:unread", and nothing else, a subclass may write:@Operator public Predicate is(String value) { if ("starred".equals(value)) { return new StarredPredicate(); } if ("unread".equals(value)) { return new UnreadPredicate(); } throw new IllegalArgumentException(); }The available operator methods are discovered at runtime via reflection. Method names (after being converted to lowercase), correspond to operators in the query language, method string values correspond to the operator argument. Methods must be declared public, returningPredicate, accepting oneString, and annotated with theQueryBuilder.Operatorannotation.Subclasses may also declare a handler for values which appear without operator by overriding defaultField(String).Instances are non-singletons and should only be used once, in order to rescan the DynamicMapof plugin-provided operators on each query invocation.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classQueryBuilder.Definition<T,Q extends QueryBuilder<T,Q>>Defines the operators known by a QueryBuilder.protected static interfaceQueryBuilder.OperatorDenotes a method which is a query operator.static interfaceQueryBuilder.OperatorFactory<T,Q extends QueryBuilder<T,Q>>Converts a value string passed to an operator into aPredicate.
 - 
Field SummaryFields Modifier and Type Field Description protected QueryBuilder.Definition<T,Q>builderDefprotected Map<String,String>opAliases
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedQueryBuilder(QueryBuilder.Definition<T,Q> def, DynamicMap<? extends QueryBuilder.OperatorFactory<T,Q>> dynamicOpFactories)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Predicate<T>defaultField(String value)Handle a value present outside of an operator.protected static QueryParseExceptionerror(String msg)protected static QueryParseExceptionerror(String msg, Throwable why)static <T,P extends Predicate<T>>
 Pfind(Predicate<T> p, Class<P> clazz)Locate a predicate in the predicate tree.static <T,P extends OperatorPredicate<T>>
 Pfind(Predicate<T> p, Class<P> clazz, String name)Locate a predicate in the predicate tree.Predicate<T>parse(String query)Parse a user-supplied query string into a predicate.List<Predicate<T>>parse(List<String> queries)Parse multiple user-supplied query strings into a list of predicates.voidsetOperatorAliases(Map<String,String> opAliases)
 
- 
- 
- 
Field Detail- 
builderDefprotected final QueryBuilder.Definition<T,Q extends QueryBuilder<T,Q>> builderDef 
 
- 
 - 
Constructor Detail- 
QueryBuilderprotected QueryBuilder(QueryBuilder.Definition<T,Q> def, DynamicMap<? extends QueryBuilder.OperatorFactory<T,Q>> dynamicOpFactories) 
 
- 
 - 
Method Detail- 
findpublic static <T,P extends Predicate<T>> P find(Predicate<T> p, Class<P> clazz) Locate a predicate in the predicate tree.- Parameters:
- p- the predicate to find.
- clazz- type of the predicate instance.
- Returns:
- the predicate, null if not found.
 
 - 
findpublic static <T,P extends OperatorPredicate<T>> P find(Predicate<T> p, Class<P> clazz, String name) Locate a predicate in the predicate tree.- Parameters:
- p- the predicate to find.
- clazz- type of the predicate instance.
- name- name of the operator.
- Returns:
- the first instance of a predicate having the given type, as found by a depth-first search.
 
 - 
parsepublic Predicate<T> parse(String query) throws QueryParseException Parse a user-supplied query string into a predicate.- Parameters:
- query- the query string.
- Returns:
- predicate representing the user query.
- Throws:
- QueryParseException- the query string is invalid and cannot be parsed by this parser. This may be due to a syntax error, may be due to an operator not being supported, or due to an invalid value being passed to a recognized operator.
 
 - 
parsepublic List<Predicate<T>> parse(List<String> queries) throws QueryParseException Parse multiple user-supplied query strings into a list of predicates.- Parameters:
- queries- the query strings.
- Returns:
- predicates representing the user query, in the same order as the input.
- Throws:
- QueryParseException- one of the query strings is invalid and cannot be parsed by this parser. This may be due to a syntax error, may be due to an operator not being supported, or due to an invalid value being passed to a recognized operator.
 
 - 
defaultFieldprotected Predicate<T> defaultField(String value) throws QueryParseException Handle a value present outside of an operator.This default implementation always throws an "Unsupported query: " message containing the input text. Subclasses may override this method to perform do-what-i-mean guesses based on the input string. - Parameters:
- value- the value supplied by itself in the query.
- Returns:
- predicate representing this value.
- Throws:
- QueryParseException- the parser does not recognize this value.
 
 - 
errorprotected static QueryParseException error(String msg) 
 - 
errorprotected static QueryParseException error(String msg, Throwable why) 
 
- 
 
-