public static final boolean containsType(Condition<?> condition, Condition.Type type) { if (condition.getType()==type) return true; else if (condition.numChildren()>0) { for (Condition child : condition.getChildren()) { if (containsType(child,type)) return true; } } return false; }
@Override public boolean evaluate(E element) { if (!hasChildren()) return true; for (Condition<E> condition : this) { if (condition.evaluate(element)) return true; } return false; }
public static final<E extends TitanElement> void traversal(Condition<E> condition, Predicate<Condition<E>> evaluator) { if (!evaluator.apply(condition)) return; //Abort if the evaluator returns false if (condition.getType()== Condition.Type.LITERAL) { return; } else if (condition instanceof Not) { traversal(((Not) condition).getChild(), evaluator); } else if (condition instanceof MultiCondition) { for (Condition<E> child : condition.getChildren()) traversal(child, evaluator); } else throw new IllegalArgumentException("Unexpected condition type: " + condition); }
private static final boolean isQNFLiteral(Condition<?> condition) { if (condition.getType() != Condition.Type.LITERAL) return false; if (condition instanceof PredicateCondition) { return ((PredicateCondition) condition).getPredicate().isQNF(); } else return true; }
public static boolean isEmpty(Condition<?> condition) { return condition.getType() != Condition.Type.LITERAL && condition.numChildren() == 0; }
@Override public And<E> clone() { return new And<E>(this); }
public static <K, E extends TitanElement> PredicateCondition<K, E> of(K key, TitanPredicate titanPredicate, Object condition) { return new PredicateCondition<K, E>(key, titanPredicate, condition); }
@Override public boolean evaluate(E element) { for (Condition<E> condition : this) { if (!condition.evaluate(element)) return false; } return true; }
@Override public Or<E> clone() { return new Or<E>(this); }
public static final<E extends TitanElement> Condition<E> literalTransformation(Condition<E> condition, final Function<Condition<E>,Condition<E>> transformation) { return transformation(condition,new Function<Condition<E>, Condition<E>>() { @Nullable @Override public Condition<E> apply(@Nullable Condition<E> cond) { if (cond.getType()== Condition.Type.LITERAL) return transformation.apply(cond); else return null; } }); }
@Override public String toString() { return "!("+ condition.toString()+")"; }
@Override public String toString() { return "dir["+getDirection()+"]"; } }
public static <E extends TitanElement> Not<E> of(Condition<E> element) { return new Not<E>(element); }
public static <E extends TitanElement> And<E> of(Condition<E>... elements) { return new And<E>(elements); }
@Override public boolean evaluate(E element) { return !condition.evaluate(element); }
public static <E extends TitanElement> Or<E> of(Condition<E>... elements) { return new Or<E>(elements); }
public boolean matches(TitanRelation relation) { return condition.evaluate(relation); }
@Override public boolean matches(TitanElement element) { return condition.evaluate(element); }