/** * Create an {@link EnclosedIterable} from the supplied Collection. Does not copy the collection * so you should only use this if you are about to lose the reference or the collection is immutable. * @param <T> the collection type * @param collection * @return */ public static <T> EnclosedIterable<T> from(final Collection<? extends T> collection) { return new CollectionEnclosedIterable<T>(collection); }
public EnclosedIterable<T> asEnclosedIterable() { return CollectionEnclosedIterable.copy(elements); }
@Override public EnclosedIterable<Attachment> getAttachmentOfIssue(final @Nonnull Issue issue) { return CollectionEnclosedIterable.from(issue.getAttachments()); }
@Override public EnclosedIterable<SearchRequest> getSearchRequests(final ApplicationUser user, final RetrievalDescriptor descriptor) { return CollectionEnclosedIterable.from( toList(searchRequestStore.get(descriptor)) .stream() .map(createPermissionSanitisingResolver(user)) .filter(sr -> isSharedWith(sr, user)).collect(Collectors.toList())); }
@Override public EnclosedIterable<SearchRequest> get(final RetrievalDescriptor descriptor) { // get SearchRequests that haven't been loaded to the cache yet and populate the cache final DefaultSharedEntitySearcher.Ids searchRequestsFromDb = new DefaultSharedEntitySearcher.Ids( descriptor.getIds().stream().filter(id -> !cacheById.containsKey(id)) .collect(toImmutableListWithSizeOf(descriptor.getIds())), false); delegateStore.get(searchRequestsFromDb).foreach(searchRequest -> cacheById.put(searchRequest.getId(), CacheObject.wrap(searchRequest))); // read all from the cache return CollectionEnclosedIterable.from(descriptor.getIds().stream().filter(cacheById::containsKey).map(cacheById::get).filter(CacheObject::hasValue) .map(CacheObject::getValue).collect(toImmutableListWithSizeOf(descriptor.getIds()))); }
public static <T> EnclosedIterable<T> copy(final Collection<? extends T> collection) { return new CollectionEnclosedIterable<T>(new ArrayList<T>(collection)); }
return CollectionEnclosedIterable.from(Collections.emptyList());