org.terracotta.context.query
Class QueryBuilder

java.lang.Object
  extended by org.terracotta.context.query.QueryBuilder

public class QueryBuilder
extends Object

A QueryBuilder allows for modular assembly of context graph queries.

Query assembly is performed by chaining a sequence of graph traversal and filtering operations together in order to select a particular set of the input node set's descendants.


Method Summary
 Query build()
          Returns a query that represents the currently assembled transformation.
 QueryBuilder chain(Query query)
          Applies the given query on the currently selected node set.
 QueryBuilder children()
          Selects the union of the current node sets child nodes.
 QueryBuilder descendants()
          Selects the merged descendant set of the current node set.
 QueryBuilder empty()
          Selects an empty node set.
 QueryBuilder ensureUnique()
          Asserts that the current node set is a singleton.
 QueryBuilder filter(Matcher<? super TreeNode> filter)
          Filters the current node set using the supplied Matcher.
 QueryBuilder parent()
          Selects the parent of the current node.
static QueryBuilder queryBuilder()
          Creates a new query builder instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

queryBuilder

public static QueryBuilder queryBuilder()
Creates a new query builder instance.

A newly constructed query builder represents the identity query. It simply returns the input node set as the output node set.

Returns:
a new query builder

filter

public QueryBuilder filter(Matcher<? super TreeNode> filter)
Filters the current node set using the supplied Matcher.

Nodes in the current node set that are not selected by the supplied matcher are removed.

Parameters:
filter - matcher to apply
Returns:
this query builder

children

public QueryBuilder children()
Selects the union of the current node sets child nodes.

Returns:
this query builder

parent

public QueryBuilder parent()
Selects the parent of the current node.

Returns:
this query builder

descendants

public QueryBuilder descendants()
Selects the merged descendant set of the current node set.

More precisely this recursively merges the children of each member of the node-set in to the output node set until the set ceases to grow.

Returns:
this query builder

chain

public QueryBuilder chain(Query query)
Applies the given query on the currently selected node set.

Parameters:
query - query to apply
Returns:
this query builder

ensureUnique

public QueryBuilder ensureUnique()
Asserts that the current node set is a singleton.

If the current node set is not of size 1 then the query will terminate with an IllegalStateException.

Returns:
this query builder

empty

public QueryBuilder empty()
Selects an empty node set.

Returns:
this query builder

build

public Query build()
Returns a query that represents the currently assembled transformation.

Returns:
a newly constructed query


Copyright © 2015. All Rights Reserved.