Example usage for com.google.common.collect Collections2 filter

List of usage examples for com.google.common.collect Collections2 filter

Introduction

In this page you can find the example usage for com.google.common.collect Collections2 filter.

Prototype



@CheckReturnValue
public static <E> Collection<E> filter(Collection<E> unfiltered, Predicate<? super E> predicate) 

Source Link

Document

Returns the elements of unfiltered that satisfy a predicate.

Usage

From source file:org.deephacks.tools4j.support.test.InMemoryStorage.java

/**
 * Finds objects that matches the query.
 * /*w  ww.ja  va  2 s .  co m*/
 * @param criteria used to match objects.
 * @return Operation to be performed on the matching objects.
 */
@SuppressWarnings("unchecked")
public Operation select(final Criteria criteria) {
    return new Operation() {

        @Override
        public <T> Collection<T> from(Class<T> clazz) {
            Collection<T> objects = getAll(clazz);
            return Collections2.filter(objects, criteria);
        }

    };
}

From source file:org.opensaml.xmlsec.criterion.SignatureValidationConfigurationCriterion.java

/**
 * Constructor.//from   ww  w .jav a  2 s  . c  o m
 *
 * @param configurations list of configuration instances
 */
public SignatureValidationConfigurationCriterion(
        @Nonnull @NonnullElements @NotEmpty List<SignatureValidationConfiguration> configurations) {
    Constraint.isNotNull(configurations, "List of configurations cannot be null");
    configs = new ArrayList<>(Collections2.filter(configurations, Predicates.notNull()));
    Constraint.isGreaterThanOrEqual(1, configs.size(), "At least one configuration is required");

}

From source file:org.zoumbox.tarot.TarotActivity.java

protected List<String> getSavedFileNames() {
    String[] files = fileList();/*  ww w  .j a v a  2s .c  o m*/
    List<String> filesList = Lists.newArrayList(files);

    List<String> result = Lists.newArrayList();
    result.addAll(Collections2.filter(filesList, new Predicate<String>() {
        @Override
        public boolean apply(String input) {
            Matcher matcher = BOARD_FILENAME_1_2_PATTERN.matcher(input);
            boolean result = matcher.matches();
            return result;
        }
    }));

    Collections.sort(result, new Comparator<String>() {
        @Override
        public int compare(String file1, String file2) {
            return file1.compareTo(file2);
        }
    });

    return result;
}

From source file:net.sourceforge.fenixedu.presentationTier.renderers.providers.candidacy.DegreeChangeIndividualCandidacyDegreesProvider.java

@Override
public Object provide(Object source, Object currentValue) {
    final Set<AcademicProgram> programs = AcademicAuthorizationGroup.getProgramsForOperation(
            AccessControl.getPerson(), AcademicOperationType.MANAGE_INDIVIDUAL_CANDIDACIES);

    return Collections2.filter(getDegrees(source), new Predicate<Degree>() {
        @Override/*from ww w.j a va 2 s . co  m*/
        public boolean apply(Degree degree) {
            return programs.contains(degree);
        }
    });
}

From source file:org.apache.activemq.artemis.core.management.impl.view.ActiveMQAbstractView.java

public String getResultsAsJson(int page, int pageSize) {
    JsonObjectBuilder obj = JsonLoader.createObjectBuilder();
    JsonArrayBuilder array = JsonLoader.createArrayBuilder();
    collection = Collections2.filter(collection, getPredicate());
    for (T element : getPagedResult(page, pageSize)) {
        array.add(toJson(element));//from  w w w  .jav  a2 s.  c om
    }
    obj.add("data", array);
    obj.add("count", collection.size());
    return obj.build().toString();
}

From source file:com.manning.siia.kitchen.domain.Recipe.java

private Collection<Ingredient> findMissingIngredients(final List<Product> products) {
    return Collections2.filter(ingredients, new Predicate<Ingredient>() {
        public boolean apply(Ingredient input) {
            for (Product mealIngredient : products) {
                if (input.isSatisfiedBy(mealIngredient)) {
                    return false;
                }/*from w  w w .j  a  va2  s. com*/
            }
            return true;
        }
    });
}

From source file:additionalpipes.tileentity.TileTeleportManager.java

public Collection<Integer> getMapsLinkTo(final ITeleportPipe pipe) {
    if (!matchesOwner(pipe)) {
        return Collections.emptyList();
    }//from  w  w  w  . j a v  a 2s.c o m

    return Collections2.filter(maps, new Predicate<Integer>() {
        @Override
        public boolean apply(Integer input) {
            return hasLinkedWithMap(input, pipe);
        }
    });
}

From source file:org.opensaml.xmlsec.impl.WhitelistBlacklistConfigurationCriterion.java

/**
 * Constructor.//from   ww  w. ja  v a  2 s. c om
 *
 * @param configurations list of configuration instances
 */
public WhitelistBlacklistConfigurationCriterion(
        @Nonnull @NonnullElements @NotEmpty List<WhitelistBlacklistConfiguration> configurations) {
    Constraint.isNotNull(configurations, "List of configurations may not be null");
    configs = new ArrayList<>(Collections2.filter(configurations, Predicates.notNull()));
    Constraint.isGreaterThanOrEqual(1, configs.size(), "At least one configuration is required");

}

From source file:org.fluentlenium.core.search.Search.java

/**
 * Central methods to find elements on the page. Can provide some filters. Able to use css1, css2, css3, see WebDriver  restrictions
 *
 * @param name/*from ww w . ja  v a 2 s.c om*/
 * @param filters
 * @return
 */
@Override
public FluentList<FluentWebElement> find(String name, final Filter... filters) {
    StringBuilder sb = new StringBuilder(name);
    List<Filter> postFilterSelector = new ArrayList<Filter>();
    if (filters != null && filters.length > 0) {
        for (Filter selector : filters) {
            if (selector.isPreFilter()) {
                sb.append(selector.toString());
            } else {
                postFilterSelector.add(selector);
            }
        }
    }
    Collection<FluentWebElement> postFiltered = select(sb.toString());
    for (Filter selector : postFilterSelector) {
        postFiltered = Collections2.filter(postFiltered, new FilterPredicate(selector));
    }

    return new FluentListImpl<FluentWebElement>(postFiltered);
}

From source file:fixture.todo.simple.ToDoItemsRecreateAndCompleteSeveral.java

private ToDoItem findToDoItem(final String description, final String user) {
    final Collection<ToDoItem> filtered = Collections2.filter(getContainer().allInstances(ToDoItem.class),
            new Predicate<ToDoItem>() {
                @Override/*from   ww w. ja  va2s  .  c o m*/
                public boolean apply(ToDoItem input) {
                    return Objects.equal(description, input.getDescription())
                            && Objects.equal(user, input.getOwnedBy());
                }
            });
    return filtered.isEmpty() ? null : filtered.iterator().next();
}