/** * Returns true if all objects were added. If the bound has already been reached, any elements greater than * the greatest will not be added. */ @Override public boolean addAll(Collection<? extends T> os) { return foldl(ImmutableList.<T>copyOf(os), true, new Function2<T, Boolean, Boolean>() { public Boolean apply(T t, Boolean allSuccess) { return add(t) && allSuccess; } }); }
/** * Extracts all the values from the {@code filters} for a particular {@code Operation}. * * @param op operation to extract all the values for * @param filters filters to extract values from * @return all the values from the {@code filters} for a particular {@code Operation} */ public static Iterable<String> getAllValues(Operator op, Collection<Pair<Operator, Iterable<String>>> filters) { return foldl(filters, ImmutableList.<String>builder(), new BuildAllValuesWithOp(op)).build(); }
/** * Unused by Streams, but implemented to ensure that anything removed is also removed from the session. */ @Override public boolean removeAll(Collection<?> os) { return foldl(ImmutableList.<Object>copyOf(os), false, (o, anyRemoved) -> remove(o) || anyRemoved); }
/** * Creates a {@code Predicate} from the {@link IS} and {@link NOT} operators in the list of filters. The returned * {@code Predicate} uses the {@link Function}s {@code is} and {@link not} to construct the sub * {@code Predicate}s for each {@code Operator}, and then {@link and}s them all together. * * @param filters filters to create a predicate for * @return {@code Predicate} from the {@code IS} and {@code NOT} filters */ public static Predicate<String> isAndNot(Iterable<Pair<Operator, Iterable<String>>> filters, Function<Iterable<String>, Predicate<String>> is, Function<Iterable<String>, Predicate<String>> not) { Predicate<String> alwaysTrue = Predicates.<String>alwaysTrue(); if (filters == null) { return alwaysTrue; } return foldl(filters, alwaysTrue, new IsAndNot(is, not)); }
/** * Creates a {@code Predicate} from the {@link CONTAINS} and {@link DOES_NOT_CONTAIN} operators in the list of filters. The returned * {@code Predicate} uses the {@link Function}s {@code contains} and {@link doesNotContain} to construct the sub * {@code Predicate}s for each {@code Operator}, and then {@link and}s them all together. * * @param filters filters to create a predicate for * @return {@code Predicate} from the {@code CONTAINS} and {@code DOES_NOT_CONTAIN} filters */ public static Predicate<String> containsAndDoesNotContain(Iterable<Pair<Operator, Iterable<String>>> filters, Function<Iterable<String>, Predicate<String>> contains, Function<Iterable<String>, Predicate<String>> doesNotContain) { Predicate<String> alwaysTrue = Predicates.<String>alwaysTrue(); if (filters == null) { return alwaysTrue; } return foldl(filters, alwaysTrue, new ContainsAndDoesNotContain(contains, doesNotContain)); }
public static Pair<Set<String>, Set<String>> getIsAndNotValues(Iterable<Pair<Operator, Iterable<String>>> filters) { Pair<Set<String>, Set<String>> emptySets = Pair.<Set<String>, Set<String>>pair(ImmutableSet.<String>of(), ImmutableSet.<String>of()); return foldl(filters, emptySets, extractIsAndNotValues()); }
/** * Unused by Streams, but implemented to ensure that anything removed is also removed from the session. */ @Override public boolean retainAll(final Collection<?> os) { return foldl(ImmutableList.copyOf(this), false, (Function2<Object, Boolean, Boolean>) (o, anyRemoved) -> { if (!os.contains(o)) { return remove(o) || anyRemoved; } else { return anyRemoved; } }); } }
/** * Creates a {@code Predicate} to determine if a date matches the filters from the request. If the request * does not contain any update date filters, the returned {@code Predicate} will return {@code true} for every date. * * @param request request to generate the updated date predicate from * @return {@code Predicate} to determine if a date matches the filters from the request */ public static Predicate<Date> inDateRange(ActivityRequest request) { Predicate<Date> alwaysTrue = Predicates.<Date>alwaysTrue(); return foldl(request.getStandardFilters().get(UPDATE_DATE.getKey()), alwaysTrue, ContainsDate.INSTANCE); }
private Iterable<Iterable<StreamsEntry>> getChangesets(final ActivityRequest request, Supplier<Boolean> cancelled) { return foldl(finder.getRepositories(request), ImmutableList.<Iterable<StreamsEntry>>of(), appendChangesets(request, cancelled)); }
public static Option<Html> titleAsHtml(ActivityObject o) { return foldl(o.getTitle(), o.getTitleAsHtml(), new Function2<String, Option<Html>, Option<Html>>() { public Option<Html> apply(String title, Option<Html> titleAsHtml) { return some(new Html(escapeHtml(title))); } }); } }
private static Clause or(Iterable<Clause> clauses) { if (isEmpty(clauses)) { return newClauseBuilder().buildClause(); } return foldl(drop(1, clauses), newClauseBuilder(get(clauses, 0)), OrClauses.INSTANCE).buildClause(); }
public static Option<Html> titleAsHtml(ActivityObject o) { return foldl(o.getTitle(), o.getTitleAsHtml(), (title, titleAsHtml) -> some(new Html(escapeHtml4(title)))); }
private static Clause and(Iterable<Clause> clauses) { if (isEmpty(clauses)) { return newClauseBuilder().buildClause(); } return foldl(drop(1, clauses), newClauseBuilder(get(clauses, 0)), AndClauses.INSTANCE).buildClause(); }
public Html apply(Iterable<Attachment> attachments) { Pair<? extends Iterable<Attachment>, ? extends Iterable<Attachment>> init = pair(ImmutableList.<Attachment>of(), ImmutableList.<Attachment>of()); Pair<? extends Iterable<Attachment>, ? extends Iterable<Attachment>> items = Fold.foldl(attachments, init, splitAttachments()); return new Html(render(templateRenderer, "attachment-list.vm", ImmutableMap.of( "comment", withComment ? item.getComment().map(helper.renderComment()).flatMap(trimHtmlToNone()) : none(), "attachments", ImmutableList.copyOf(transform(items.first(), asAttachmentItem(baseUri))), "thumbnails", ImmutableList.copyOf(transform(items.second(), asThumbnailItem(baseUri)))))); }