WrappingPersistence implements Persistence<O, A> { public WrappingPersistence(Collection<O> backingCollection) { this(backingCollection, null); } WrappingPersistence(Collection<O> backingCollection);  WrappingPersistence(Collection<O> backingCollection, SimpleAttribute<O, A> primaryKeyAttribute); @Override boolean supportsIndex(Index<O> index); @Override ObjectStore<O> createObjectStore(); @Override void openRequestScopeResources(QueryOptions queryOptions); @Override void closeRequestScopeResources(QueryOptions queryOptions); @Override SimpleAttribute<O, A> getPrimaryKeyAttribute(); static WrappingPersistence<O, A> aroundCollectionOnPrimaryKey(Collection<O> collection, SimpleAttribute<O, A> primaryKeyAttribute); @SuppressWarnings("unchecked") static WrappingPersistence<O, ? extends Comparable> aroundCollection(Collection<O> collection);  }
@Test public void testWrappingPersistence() { Collection<Car> backingCollection = new LinkedHashSet<Car>(); backingCollection.addAll(CarFactory.createCollectionOfCars(3)); IndexedCollection<Car> indexedCollection = new ConcurrentIndexedCollection<Car>( WrappingPersistence.aroundCollection(backingCollection) ); indexedCollection.addIndex(NavigableIndex.onAttribute(Car.CAR_ID)); ResultSet<Car> results = indexedCollection.retrieve(greaterThan(Car.CAR_ID, 0)); assertNotEquals(Integer.MAX_VALUE, results.getRetrievalCost()); Set<Integer> expectedCarIds, actualCarIds; expectedCarIds = asSet(1, 2); actualCarIds = extractCarIds(results, new HashSet<Integer>()); assertEquals(expectedCarIds, actualCarIds); indexedCollection.add(CarFactory.createCar(3)); expectedCarIds = asSet(0, 1, 2, 3); actualCarIds = extractCarIds(backingCollection, new HashSet<Integer>()); assertEquals(expectedCarIds, actualCarIds); }