@Test public void find() { final LocalDhisResourceRepositoryImpl<TrackedEntityInstance> resourceRepository = new LocalDhisResourceRepositoryImpl<>( TrackedEntityInstance.class ); final WritableTrackedEntityType trackedEntityType = new WritableTrackedEntityType(); trackedEntityType.setAttributes( Collections.emptyList() ); final TrackedEntityInstance trackedEntityInstance1 = new TrackedEntityInstance( trackedEntityType, "a1234567890", true ); final TrackedEntityInstance trackedEntityInstance2 = new TrackedEntityInstance( trackedEntityType, "a1234567891", true ); final TrackedEntityInstance trackedEntityInstance3 = new TrackedEntityInstance( trackedEntityType, "a1234567892", true ); resourceRepository.save( trackedEntityInstance1, null ); resourceRepository.save( trackedEntityInstance2, null ); resourceRepository.save( trackedEntityInstance3, null ); final List<TrackedEntityInstance> found = new ArrayList<>( resourceRepository.find( r -> !"a1234567891".equals( r.getId() ) ) ); Assert.assertThat( found, Matchers.containsInAnyOrder( trackedEntityInstance1, trackedEntityInstance3 ) ); }
@Override @Nonnull public Collection<T> find( @Nonnull Predicate<T> filter ) { return resourcesById.values().stream().filter( lr -> !lr.getState().isDeleted() && filter.test( lr.getResource() ) ) .map( LocalDhisResource::getResource ).collect( Collectors.toList() ); }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Collection<T> find( @Nonnull Predicate<T> filter ) { return resourcesById.values().stream().filter( lr -> !lr.getState().isDeleted() && filter.test( lr.getResource() ) ) .map( LocalDhisResource::getResource ).collect( Collectors.toList() ); } }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Collection<T> find( @Nonnull Predicate<T> filter ) { return resourcesById.values().stream().filter( lr -> !lr.getState().isDeleted() && filter.test( lr.getResource() ) ) .map( LocalDhisResource::getResource ).collect( Collectors.toList() ); } LocalDhisResourceRepositoryImpl( @Nonnull Class<T> resourceClass ); }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Collection<T> find( @Nonnull Predicate<T> filter ) { return resourcesById.values().stream().filter( lr -> !lr.getState().isDeleted() && filter.test( lr.getResource() ) ) .map( LocalDhisResource::getResource ).collect( Collectors.toList() ); } LocalDhisResourceRepositoryImpl( @Nonnull Class<T> resourceClass ); @Override @Nonnull T save( @Nonnull T resource, @Nullable Object resourceKey ); @Override boolean deleteById( @Nonnull String id, @Nullable Object resourceKey, @Nonnull Function<String, T> prototypeFunction ); @Override boolean containsCollectionKey( @Nonnull String key ); @Override @Nonnull Collection<T> found( @Nonnull Collection<T> resources, @Nonnull String key ); @Override @Nonnull Optional<T> findOneById( @Nonnull String id ); @Override @Nonnull Collection<T> find( @Nonnull Predicate<T> filter ); @Override @Nonnull Collection<T> find( @Nonnull String trackedEntityInstanceId, @Nonnull Predicate<T> filter ); @Override void applySaves( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback ); @Override void applyDeletes( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback ); }
LocalDhisResourceRepositoryImpl implements LocalDhisResourceRepository<T> { @Override @Nonnull public Collection<T> find( @Nonnull Predicate<T> filter ) { return resourcesById.values().stream().filter( lr -> !lr.getState().isDeleted() && filter.test( lr.getResource() ) ) .map( LocalDhisResource::getResource ).collect( Collectors.toList() ); } LocalDhisResourceRepositoryImpl( @Nonnull Class<T> resourceClass ); @Override @Nonnull T save( @Nonnull T resource, @Nullable Object resourceKey ); @Override boolean deleteById( @Nonnull String id, @Nullable Object resourceKey, @Nonnull Function<String, T> prototypeFunction ); @Override boolean containsCollectionKey( @Nonnull String key ); @Override @Nonnull Collection<T> found( @Nonnull Collection<T> resources, @Nonnull String key ); @Override @Nonnull Optional<T> findOneById( @Nonnull String id ); @Override @Nonnull Collection<T> find( @Nonnull Predicate<T> filter ); @Override @Nonnull Collection<T> find( @Nonnull String trackedEntityInstanceId, @Nonnull Predicate<T> filter ); @Override void applySaves( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback ); @Override void applyDeletes( @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback, @Nonnull LocalDhisRepositoryResultCallback resultCallback );  }