use of com.hazelcast.query.VisitablePredicate in project hazelcast by hazelcast.
the class NotPredicate method accept.
@Override
public Predicate accept(Visitor visitor, Indexes indexes) {
Predicate target = predicate;
if (predicate instanceof VisitablePredicate) {
target = ((VisitablePredicate) predicate).accept(visitor, indexes);
}
if (target == predicate) {
// visitor didn't change the inner predicate
return visitor.visit(this, indexes);
}
// visitor returned a different copy of the inner predicate.
// We have to create our copy with the new inner predicate to maintained immutability
NotPredicate copy = new NotPredicate(target);
return visitor.visit(copy, indexes);
}
use of com.hazelcast.query.VisitablePredicate in project hazelcast by hazelcast.
the class VisitorUtils method acceptVisitor.
/**
* Accept visitor by all predicates. It treats the input array as immutable.
*
* It's Copy-On-Write: If at least one predicate returns a different instance
* then this method returns a copy of the passed arrays.
*
* @param predicates
* @param visitor
* @return
*/
public static Predicate[] acceptVisitor(Predicate[] predicates, Visitor visitor, Indexes indexes) {
Predicate[] target = predicates;
boolean copyCreated = false;
for (int i = 0; i < predicates.length; i++) {
Predicate predicate = predicates[i];
if (predicate instanceof VisitablePredicate) {
Predicate transformed = ((VisitablePredicate) predicate).accept(visitor, indexes);
if (transformed != predicate) {
if (!copyCreated) {
copyCreated = true;
target = createCopy(target);
}
target[i] = transformed;
}
}
}
return target;
}
use of com.hazelcast.query.VisitablePredicate in project hazelcast by hazelcast.
the class PredicateTestUtils method createMockVisitablePredicate.
static Predicate createMockVisitablePredicate() {
VisitablePredicate visitablePredicate = mock(VisitablePredicate.class, withSettings().extraInterfaces(Predicate.class));
when(visitablePredicate.accept((Visitor) anyObject(), (Indexes) anyObject())).thenReturn((Predicate) visitablePredicate);
return (Predicate) visitablePredicate;
}
use of com.hazelcast.query.VisitablePredicate in project hazelcast by hazelcast.
the class PredicateTestUtils method createMockVisitablePredicate.
static Predicate createMockVisitablePredicate(Predicate transformed) {
VisitablePredicate visitablePredicate = mock(VisitablePredicate.class, withSettings().extraInterfaces(Predicate.class));
when(visitablePredicate.accept((Visitor) anyObject(), (Indexes) anyObject())).thenReturn(transformed);
return (Predicate) visitablePredicate;
}
Aggregations