O'Reilly logo

Building Parsers with Java™ by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required