@Nonnull @Override public Iterable<E> getAll() { final Function<K, Option<E>> getAllAsOptionsF = new Function<K, Option<E>>() { @Override public Option<E> apply(K key) { return get(key); } }; final Function<Option<E>, E> getAllF = new Function<Option<E>, E>() { @Override public E apply(Option<E> input) { return input.get(); } }; return ImmutableList.copyOf(transform(Options.filterNone(transform(getKeys(), getAllAsOptionsF)), getAllF)); }
private String renderCommentFields(final DescriptorToHtmlFunction descriptorToHtmlFunction, final CommentHelper commentHelper) { Iterable<CommentFieldRendererModuleDescriptor> descriptors = pluginAccessor.getEnabledModuleDescriptorsByClass(CommentFieldRendererModuleDescriptor.class); List<CommentFieldRendererModuleDescriptor> descriptorsOrderedByWeight = commentFieldRendererModuleDescriptorOrdering.sortedCopy(descriptors); // Complicated? Not really. We get all renders for which want to be displayed (according to the condition). // Then, transform all this to optional html (there might be no definition of field-view-resource, when we would get none). // Finally, pick the first non empty html. final Option<String> commentFieldToRender = getFirst(Options.filterNone(transform(filter(descriptorsOrderedByWeight, SafePluginPointAccess.safe(new Predicate<CommentFieldRendererModuleDescriptor>() { @Override public boolean apply(final CommentFieldRendererModuleDescriptor moduleDescriptor) { return moduleDescriptor.getCondition() == null || moduleDescriptor.getCondition().shouldDisplay(commentHelper.getContextParams()); } })), SafePluginPointAccess.safe(descriptorToHtmlFunction))), Option.<String>none()); return commentFieldToRender.getOrError(new Supplier<String>() { @Override public String get() { throw new IllegalStateException("There should be at least one comment field renderer, which can render the comments"); } }); }