Search in sources :

Example 61 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class PredicatesTest method testOr.

@Test
public void testOr() {
    final Predicate or1 = or(equal(ATTRIBUTE, 3), equal(ATTRIBUTE, 4), equal(ATTRIBUTE, 5));
    assertPredicateTrue(or1, 4);
    assertPredicateFalse(or1, 6);
}
Also used : Predicate(com.hazelcast.query.Predicate) IndexAwarePredicate(com.hazelcast.query.IndexAwarePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 62 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class FlatteningVisitorTest method visitNotPredicate_whenContainsNegatablePredicate_thenFlattenIt.

@Test
public void visitNotPredicate_whenContainsNegatablePredicate_thenFlattenIt() {
    // (not(equals(foo, 1)))  -->  (notEquals(foo, 1))
    Predicate negated = mock(Predicate.class);
    NegatablePredicate negatablePredicate = mock(NegatablePredicate.class, withSettings().extraInterfaces(Predicate.class));
    when(negatablePredicate.negate()).thenReturn(negated);
    NotPredicate outerPredicate = (NotPredicate) not((Predicate) negatablePredicate);
    Predicate result = visitor.visit(outerPredicate, mockIndexes);
    assertEquals(negated, result);
}
Also used : Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 63 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class FlatteningVisitorTest method visitAndPredicate_whenHasInnerAndPredicate_thenFlattenIt.

@Test
public void visitAndPredicate_whenHasInnerAndPredicate_thenFlattenIt() {
    // (a1 = 1 and (a2 = 2 and a3 = 3))  -->  (a1 = 1 and a2 = 2 and a3 = 3)
    Predicate a1 = equal("a1", 1);
    Predicate a2 = equal("a2", 2);
    Predicate a3 = equal("a3", 3);
    AndPredicate innerAnd = (AndPredicate) and(a2, a3);
    AndPredicate outerAnd = (AndPredicate) and(a1, innerAnd);
    AndPredicate result = (AndPredicate) visitor.visit(outerAnd, mockIndexes);
    Predicate[] inners = result.predicates;
    assertEquals(3, inners.length);
}
Also used : Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 64 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class NestedPredicateTest method nestedAttributeQuery_predicates.

@Test
public void nestedAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("limb.name").equal("leg");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class NestedPredicateTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Predicate (com.hazelcast.query.Predicate)160 Test (org.junit.Test)125 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)107 TruePredicate (com.hazelcast.query.TruePredicate)41 SqlPredicate (com.hazelcast.query.SqlPredicate)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)23 PredicateBuilder (com.hazelcast.query.PredicateBuilder)19 EntryListener (com.hazelcast.core.EntryListener)16 MapListener (com.hazelcast.map.listener.MapListener)16 EntryObject (com.hazelcast.query.EntryObject)14 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)12 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)10 Value (com.hazelcast.query.SampleObjects.Value)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 ArrayList (java.util.ArrayList)9 EntryEvent (com.hazelcast.core.EntryEvent)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 ValueType (com.hazelcast.query.SampleObjects.ValueType)7