In extends SimpleQuery<O, A> { public In(Attribute<O, A> attribute, boolean disjoint, Set<A> values) { super(attribute); if (values == null || values.size() == 0){ throw new IllegalArgumentException("The IN query must have at least one value."); } this.values = values; this.disjoint = disjoint; } In(Attribute<O, A> attribute, boolean disjoint, Set<A> values); Set<A> getValues(); boolean isDisjoint(); @Override boolean equals(Object o); @Override String toString();  }
@Test public void testInMany() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); Attribute<Car, String> NAME = new SimpleNullableAttribute<Car, String>("name") { public String getValue(Car car, QueryOptions queryOptions) { return car.name; } }; cars.addIndex(NavigableIndex.onAttribute(NAME)); cars.add(new Car(1, "ford", null, null)); cars.add(new Car(2, "honda", null, null)); cars.add(new Car(3, "toyota", null, null)); Assert.assertEquals(cars.retrieve(in(NAME, "ford", "honda")).size(), 2); Assert.assertEquals(cars.retrieve(in(NAME, Arrays.asList("ford", "honda"))).size(), 2); }
@Test public void testInOne() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); Attribute<Car, String> NAME = new SimpleNullableAttribute<Car, String>("name") { public String getValue(Car car, QueryOptions queryOptions) { return car.name; } }; cars.addIndex(NavigableIndex.onAttribute(NAME)); cars.add(new Car(1, "ford", null, null)); cars.add(new Car(2, "honda", null, null)); cars.add(new Car(3, "toyota", null, null)); Assert.assertEquals(cars.retrieve(in(NAME, "ford")).size(), 1); Assert.assertEquals(cars.retrieve(in(NAME, Collections.singletonList("ford"))).size(), 1); }
@Test public void testInNone() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); Attribute<Car, String> NAME = new SimpleNullableAttribute<Car, String>("name") { public String getValue(Car car, QueryOptions queryOptions) { return car.name; } }; cars.addIndex(NavigableIndex.onAttribute(NAME)); cars.add(new Car(1, "ford", null, null)); cars.add(new Car(2, "honda", null, null)); cars.add(new Car(3, "toyota", null, null)); Assert.assertEquals(cars.retrieve(in(NAME)).size(), 0); Assert.assertEquals(cars.retrieve(in(NAME, new ArrayList<String>())).size(), 0); }
@Test(expected = NullPointerException.class) public void testInNull() { Attribute<Car, String> NAME = new SimpleNullableAttribute<Car, String>("name") { public String getValue(Car car, QueryOptions queryOptions) { return car.name; } }; in(NAME, (Collection<String>) null); }