Interface EntityConditionVisitor
public interface EntityConditionVisitor
A visitor of entity conditions in the style of the visitor design pattern.
Classes implementing this interface can extend the dynamically dispatched
behavior associated with EntityCondition
without augmenting its
interface. Those classes are meant be passed to the
accept
method which
calls the corresponding method in the visitor.
Usage Examples: Here is a dummy example that should print EntityExpr\n to the standard output.
EntityExpr expr;
expr.accept(new EntityConditionVisitor() {
public void visit(EntityNotCondition cond) {
system.out.println("EntityNotCondition");
}
public <T extends EntityCondition> void visit(EntityConditionList<T> l) {
system.out.println("EntityConditionList");
}
public void visit(EntityFieldMap m) {
system.out.println("EntityFieldMap");
}
public void visit(EntityDateFilterCondition df) {
system.out.println("EntityDateFilterCondition");
}
public void visit(EntityExpr expr) {
system.out.println("EntityExpr");
}
public void visit(EntityWhereString ws) {
system.out.println("EntityWhereString");
}
});
Here is a more complex example asserting the presence of a raw string condition even when it is embedded inside another one.
class ContainsRawCondition implements EntityConditionVisitor {
public boolean hasRawCondition = false;
public void visit(EntityNotCondition cond) {}
public void visit(EntityFieldMap m) {}
public void visit(EntityDateFilterCondition df) {}
public <T extends EntityCondition> void visit(EntityConditionList<T> l) {
Iterator<T> it = l.getConditionIterator();
while (it.hasNext()) {
it.next().accept(this);
}
}
public void visit(EntityExpr expr) {
Object lhs = expr.getLhs();
Object rhs = expr.getRhs();
if (lhs instanceof EntityCondition) {
((EntityCondition) lhs).accept(this);
}
if (rhs instanceof EntityCondition) {
((EntityCondition) rhs).accept(this);
}
}
public void visit(EntityWhereString ws) {
hasRawCondition = true;
}
}
EntityCondition ec =
EntityCondition.makeCondition(EntityCondition.makeConditionWhere("foo=bar"));
EntityConditionVisitor visitor = new ContainsRawCondition();
ec.accept(visitor);
assert visitor.hasRawCondition;
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T extends EntityCondition>
voidvisit
(EntityConditionList<T> l) Visits a list of entity conditions.void
Visits a date filter condition.void
visit
(EntityExpr expr) Visits an entity expression.void
Visits a map of entity fields.void
visit
(EntityNotCondition cond) Visits an entity NOT expression.void
Visits a raw string condition.
-
Method Details
-
visit
Visits an entity NOT expression.- Parameters:
cond
- the visited class- See Also:
-
visit
Visits a list of entity conditions.- Parameters:
l
- the visited class- See Also:
-
visit
Visits a map of entity fields.- Parameters:
m
- the visited class- See Also:
-
visit
Visits a date filter condition.- Parameters:
df
- the visited class- See Also:
-
visit
Visits an entity expression.- Parameters:
expr
- the visited class- See Also:
-
visit
Visits a raw string condition.- Parameters:
ws
- the visited class- See Also:
-