private SymmetricExtender(Query.Builder filters) { this.filters = filters; onLeaves(filters, (b) -> { QueryFragment last = b.fragments.isEmpty() ? null : b.fragments.get(b.fragments.size() - 1); if (last != null) { isFilter = last instanceof FilterFragment; queryFragmentSupplier = isFilter ? FilterFragment::from : PathFragment::from; converter = isFilter ? FilterFragment::new : PathFragment::new; } }); }
private void onLeaves(Query.Builder root, Consumer<Query.Builder> leafMutator) { if (root.children.isEmpty()) { leafMutator.accept(root); } else { for (Query.Builder c : root.children) { onLeaves(c, leafMutator); } } } }
/** * Appends the filters as query fragments determined by the last call to {@link #filter()} or {@link #path()}. * * @param filters the filters to append to the leaves of the query tree * @return this instance */ public SymmetricExtender with(Filter... filters) { onLeaves(this.filters, (t) -> t.with(queryFragmentSupplier.apply(filters))); return this; }
/** * Appends the filters as query fragments determined by the last call to {@link #filter()} or {@link #path()}. * * <p>The filters is an array of arrays representing a new set of branches to be created at all the leaves of * the current query tree. * * @param filters the filters to append to the leaves of the query tree * @return this instance */ public SymmetricExtender with(Filter[][] filters) { onLeaves(this.filters, (builder) -> { for (Filter[] fs : filters) { builder.branch().with(queryFragmentSupplier.apply(fs)); } }); return this; }
/** * Appends the provided query to the leaves of the current query tree, leaving the type of its fragments as they * originally were. * * @param other the query to append * @return this instance */ public SymmetricExtender withExact(Query other) { onLeaves(this.filters, (builder) -> builder.with(other)); return this; }
/** * Appends the provided query to the leaves of the current query tree, converting all its fragments to the * current fragment type (determined by the last call to {@link #filter()} or {@link #path()}). * * @param other the query to append * @return this instance */ public SymmetricExtender with(Query other) { onLeaves(this.filters, (builder) -> builder.with(other, converter)); return this; }