/** * Filters a relationship collection in memory for scenarios where the data store transaction cannot do it. * * @param <T> the type parameter * @param collection the collection to filter * @param filterExpression the filter expression * @return the filtered collection */ protected <T> Collection<T> filterInMemory(Collection<T> collection, Optional<FilterExpression> filterExpression) { if (! filterExpression.isPresent()) { return collection; } InMemoryFilterVisitor inMemoryFilterVisitor = new InMemoryFilterVisitor(requestScope); @SuppressWarnings("unchecked") Predicate<T> inMemoryFilterFn = filterExpression.get().accept(inMemoryFilterVisitor); // NOTE: We can safely _skip_ tests on NEWLY created objects. // We assume a user can READ their object they are allowed to create. return collection.stream() .filter(e -> requestScope.isNewResource(e) || inMemoryFilterFn.test(e)) .collect(Collectors.toList()); }
/** * Filters a relationship collection in memory for scenarios where the data store transaction cannot do it. * * @param <T> the type parameter * @param collection the collection to filter * @param filterExpression the filter expression * @return the filtered collection */ protected <T> Collection<T> filterInMemory(Collection<T> collection, Optional<FilterExpression> filterExpression) { if (! filterExpression.isPresent()) { return collection; } InMemoryFilterVisitor inMemoryFilterVisitor = new InMemoryFilterVisitor(requestScope); @SuppressWarnings("unchecked") Predicate<T> inMemoryFilterFn = filterExpression.get().accept(inMemoryFilterVisitor); // NOTE: We can safely _skip_ tests on NEWLY created objects. // We assume a user can READ their object they are allowed to create. return collection.stream() .filter(e -> requestScope.isNewResource(e) || inMemoryFilterFn.test(e)) .collect(Collectors.toList()); }
Predicate predicate = fe.accept(new InMemoryFilterVisitor(scope)); return data.values().stream().filter(predicate::test).collect(Collectors.toList()); })
Predicate predicate = fe.accept(new InMemoryFilterVisitor(scope)); return data.values().stream().filter(predicate::test).collect(Collectors.toList()); })