DeduplicatingResultSet extends ResultSet<O> { public DeduplicatingResultSet(Attribute<O, A> uniqueAttribute, ResultSet<O> wrappedResultSet, Query<O> query, QueryOptions queryOptions) { this.uniqueAttribute = uniqueAttribute; this.wrappedResultSet = wrappedResultSet; this.query = query; this.queryOptions = queryOptions; } DeduplicatingResultSet(Attribute<O, A> uniqueAttribute, ResultSet<O> wrappedResultSet, Query<O> query, QueryOptions queryOptions); @Override Iterator<O> iterator(); @Override final boolean contains(O object); @Override boolean matches(O object); @Override int size(); @Override int getRetrievalCost(); @Override int getMergeCost(); @Override void close(); @Override Query<O> getQuery(); @Override QueryOptions getQueryOptions();  }
@Test public void testDeduplicatingResultSet() { Collection<Car> cars = CarFactory.createCollectionOfCars(10); DeduplicatingResultSet<Car, String> deduplicatingResultSet = new DeduplicatingResultSet<Car, String>( Car.MANUFACTURER, new StoredSetBasedResultSet<Car>(new LinkedHashSet<Car>(cars)), QueryFactory.all(Car.class), QueryFactory.noQueryOptions() ); List<Integer> carIdsReturned = new ArrayList<Integer>(); IndexedCollectionFunctionalTest.extractCarIds(deduplicatingResultSet, carIdsReturned); Assert.assertEquals(4, deduplicatingResultSet.size()); Assert.assertEquals(0, deduplicatingResultSet.getRetrievalCost()); Assert.assertEquals(10, deduplicatingResultSet.getMergeCost()); Assert.assertEquals(4, carIdsReturned.size()); Assert.assertEquals(0, carIdsReturned.get(0).intValue()); Assert.assertEquals(3, carIdsReturned.get(1).intValue()); Assert.assertEquals(6, carIdsReturned.get(2).intValue()); Assert.assertEquals(9, carIdsReturned.get(3).intValue()); Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(0))); Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(3))); Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(6))); Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(9))); Assert.assertFalse(deduplicatingResultSet.contains(CarFactory.createCar(1))); deduplicatingResultSet.close(); }