use of com.servoy.j2db.util.visitor.IVisitor.VisitorResult in project servoy-client by Servoy.
the class AbstractBaseQuery method acceptVisitor.
public static <T> T acceptVisitor(T o, IVisitor visitor) {
if (o == null) {
return null;
}
Object v = visitor.visit(o);
T o2;
if (v instanceof VisitorResult) {
o2 = (T) ((VisitorResult) v).object;
if (!((VisitorResult) v).continueTraversal) {
return o2;
}
} else {
o2 = (T) v;
if (o2 != o) {
// the visitor returned something else then the input, visting stops.
return o2;
}
}
if (o2 instanceof List) {
for (int i = 0; i < ((List) o2).size(); i++) {
((List<Object>) o2).set(i, acceptVisitor(((List) o2).get(i), visitor));
}
} else if (o2 instanceof Map) {
Iterator<Map.Entry> it = ((Map) o2).entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = it.next();
entry.setValue(acceptVisitor(entry.getValue(), visitor));
}
} else if (o2 instanceof Object[]) {
for (int i = 0; i < ((Object[]) o2).length; i++) {
((Object[]) o2)[i] = acceptVisitor(((Object[]) o2)[i], visitor);
}
} else if (o2 instanceof Pair) {
Pair pair = (Pair) o2;
pair.setLeft(acceptVisitor(pair.getLeft(), visitor));
pair.setRight(acceptVisitor(pair.getRight(), visitor));
} else if (o2 instanceof IVisitable) {
((IVisitable) o2).acceptVisitor(visitor);
}
return o2;
}
Aggregations