15.6. A Query Builder
As a parser parses a user's query, the parser sees select terms, class names, and where clause comparisons. After all these pieces are parsed, you can build a Query object that is a translation of the user's input.
The builder pattern applies when “the algorithm for creating a complex object should be independent of the parts that make up the object and how they are assembled” [Gamma et al.]. You use a builder to collect the various aspects of a query and then ask the builder for a query after parsing all the input text. Figure 15.13 shows the QueryBuilder class.
Figure 15.13. The QueryBuilder class. A QueryBuilder object collects information about a desired query and then builds the query on demand.
The constructor for ...
Get Building Parsers with Java™ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.