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.eclipse.emf.compare.diagram.internal.factories.extensions.EdgeChangeFactory.java

@Override
public void setRefiningChanges(Diff extension, DifferenceKind extensionKind, Diff refiningDiff) {
    super.setRefiningChanges(extension, extensionKind, refiningDiff);
    if (extensionKind == DifferenceKind.CHANGE) {
        extension.getRefinedBy().addAll(Collections2.filter(getAllDifferencesForChange(refiningDiff),
                EMFComparePredicates.fromSide(extension.getSource())));
    }/*from  w w w .  j a  v a 2  s.  com*/
}

From source file:de.iteratec.iteraplan.elasticeam.operator.filter.FilterConnectHandler.java

/**{@inheritDoc}**/
@SuppressWarnings("unchecked")
public Object getValue(UniversalModelExpression universal, RelationshipEndExpression relationshipEnd) {
    if (relationshipEnd instanceof FromFilteredRelationshipEnd) {
        return getModel().getValue(universal,
                ((FromFilteredRelationshipEnd) relationshipEnd).getBaseRelationshipEnd());
    } else {/*from   ww  w  .  j av  a2s.  c om*/
        ToFilteredRelationshipEnd re = ((ToFilteredRelationshipEnd) relationshipEnd);
        Object val = getModel().getValue(universal, re.getBaseRelationshipEnd());
        if (val instanceof Collection) {
            return Collections2.filter((Collection<UniversalModelExpression>) val, re.getPredicate());
        } else if (val != null && re.getPredicate().apply((UniversalModelExpression) val)) {
            return val;
        }
        return null;
    }
}

From source file:fr.xebia.cocktail.CocktailRepository.java

public Collection<Cocktail> find(@Nullable final String ingredient, @Nullable final String name) {

    Predicate<Cocktail> ingredientPredicate;
    if (Strings.isNullOrEmpty(ingredient)) {
        ingredientPredicate = Predicates.alwaysTrue();
    } else {//  w w  w. j av  a  2  s. c om
        ingredientPredicate = new Predicate<Cocktail>() {
            @Override
            public boolean apply(@Nullable Cocktail cocktail) {
                for (String cocktailIngredient : cocktail.getIngredientNames()) {
                    if (StringUtils.containsIgnoreCase(cocktailIngredient, ingredient)) {
                        return true;
                    }
                }
                return false;
            }
        };
    }

    Predicate<Cocktail> namePredicate;
    if (Strings.isNullOrEmpty(name)) {
        namePredicate = Predicates.alwaysTrue();
    } else {
        namePredicate = new Predicate<Cocktail>() {
            @Override
            public boolean apply(@Nullable Cocktail cocktail) {
                return StringUtils.containsIgnoreCase(cocktail.getName(), name);
            }
        };
    }

    return Lists.newArrayList(Collections2.filter(cocktails.asMap().values(),
            Predicates.and(namePredicate, ingredientPredicate)));
}

From source file:org.opendaylight.controller.md.statistics.manager.FlowCapableTracker.java

@Override
public synchronized void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
    logger.debug("Tracker at root {} processing notification", root);

    /*//from  w  w  w  .  j  a v  a  2s  .  c  o m
     * First process all the identifiers which were removed, trying to figure out
     * whether they constitute removal of FlowCapableNode.
     */
    final Collection<NodeKey> removedNodes = Collections2
            .filter(Collections2.transform(Sets.filter(change.getRemovedOperationalData(), filterIdentifiers),
                    new Function<InstanceIdentifier<?>, NodeKey>() {
                        @Override
                        public NodeKey apply(final InstanceIdentifier<?> input) {
                            final NodeKey key = input.firstKeyOf(Node.class, NodeKey.class);
                            if (key == null) {
                                // FIXME: do we have a backup plan?
                                logger.info("Failed to extract node key from {}", input);
                            }
                            return key;
                        }
                    }), Predicates.notNull());
    stats.stopNodeHandlers(removedNodes);

    final Collection<NodeKey> addedNodes = Collections2.filter(
            Collections2.transform(Sets.filter(change.getCreatedOperationalData().keySet(), filterIdentifiers),
                    new Function<InstanceIdentifier<?>, NodeKey>() {
                        @Override
                        public NodeKey apply(final InstanceIdentifier<?> input) {
                            final NodeKey key = input.firstKeyOf(Node.class, NodeKey.class);
                            if (key == null) {
                                // FIXME: do we have a backup plan?
                                logger.info("Failed to extract node key from {}", input);
                            }
                            return key;
                        }
                    }),
            Predicates.notNull());
    stats.startNodeHandlers(addedNodes);

    logger.debug("Tracker at root {} finished processing notification", root);
}

From source file:org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils.java

@NotNull
//TODO: hack, implemented because irrelevant actions behave in different ways on build server and locally
// this behaviour should be investigated and hack can be removed
private static Collection<String> filterOutIrrelevantActions(@NotNull Collection<String> actions) {
    return Collections2.filter(actions, new Predicate<String>() {
        @Override//from ww  w  .  j  a  v  a2 s.co m
        public boolean apply(String input) {
            for (String prefix : IRRELEVANT_ACTION_PREFIXES) {
                if (input.startsWith(prefix)) {
                    return false;
                }
            }
            return true;
        }
    });
}

From source file:org.eclipse.emf.compare.diagram.internal.factories.extensions.NodeChangeFactory.java

/**
 * {@inheritDoc}//from  w  ww.  j a  v a2  s  .c om
 * 
 * @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#setRefiningChanges(org.eclipse.emf.compare.diagram.internal.extensions.DiagramDiff,
 *      org.eclipse.emf.compare.DifferenceKind, org.eclipse.emf.compare.Diff)
 */
@Override
public void setRefiningChanges(Diff extension, DifferenceKind extensionKind, Diff refiningDiff) {
    if (refiningDiff.getSource() == extension.getSource()) {
        // Macroscopic change on a node is refined by the unit main change and unit children related
        // changes.
        extension.getRefinedBy().add(refiningDiff);
        extension.getRefinedBy().addAll(Collections2.filter(getAllContainedDifferences(refiningDiff),
                EMFComparePredicates.fromSide(extension.getSource())));
    }
}

From source file:io.druid.indexing.overlord.autoscaling.TasksAndWorkersFilteredByIp.java

@Override
public Collection<Task> getPendingTaskPayloads() {
    return ImmutableList.copyOf(Collections2.filter(delegate.getPendingTaskPayloads(), taskPredicate));
}

From source file:com.cloudbees.clickstack.domain.metadata.Metadata.java

@Nonnull
public <R extends Resource> Collection<R> getResources(@Nullable final Class<R> type) {
    if (type == null)
        return (Collection<R>) resources.values();

    return (Collection<R>) Collections2.filter(resources.values(), new Predicate<Resource>() {
        @Override//  ww  w  .jav a 2 s.  c  o m
        public boolean apply(@Nullable Resource r) {
            return type.isAssignableFrom(r.getClass());
        }
    });
}

From source file:org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain.java

/**
 * Set the list of {@link MetadataFilter}s that make up this chain.
 * /*from ww  w.j  a  v a 2s  .  c o  m*/
 * @param newFilters list of {@link MetadataFilter}s that make up this chain
 */
public void setFilters(@Nonnull @NonnullElements final List<MetadataFilter> newFilters) {
    Constraint.isNotNull(newFilters, "Filter collection cannot be null");

    filters = new ArrayList<>(Collections2.filter(newFilters, Predicates.notNull()));
}

From source file:edu.umn.msi.tropix.persistence.service.impl.FolderServiceImpl.java

private Collection<TropixObjectContext<VirtualFolder>> buildSharedFolderContexts(
        final Collection<VirtualFolder> virtualFolders, final String gridId) {
    final Multimap<String, String> objectsRoles = getTropixObjectDao().getRoles(gridId,
            ModelUtils.getIds(virtualFolders));
    return Collections2.transform(Collections2.filter(virtualFolders, new Predicate<TropixObject>() {

        public boolean apply(final TropixObject input) {
            return objectsRoles.containsKey(input.getId())
                    && ModelPredicates.isValidObjectPredicate().apply(input);
        }//  w w w. j  a v  a  2s .c  o m

    }), new Function<VirtualFolder, TropixObjectContext<VirtualFolder>>() {

        public TropixObjectContext<VirtualFolder> apply(final VirtualFolder input) {
            final Collection<String> objectRoles = objectsRoles.get(input.getId());
            final TropixObjectUserAuthorities context = new TropixObjectUserAuthorities(
                    objectRoles.contains("write"), objectRoles.contains("write"));
            return new TropixObjectContext<VirtualFolder>(context, input);
        }

    });

}