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.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.java

public static State findStateFullyQualified(Statechart sc, final String name) {

    Collection<EObject> states = Collections2.filter(EcoreUtil2.eAllContentsAsList(sc),
            new Predicate<Object>() {

                public boolean apply(Object obj) {
                    // TODO Auto-generated method stub
                    return obj != null && obj instanceof State && name.equals(fqn((State) obj));
                }//w  w w. j  a v a2 s  .  co m
            });

    return (states.size() > 0) ? (State) states.iterator().next() : null;
}

From source file:net.shibboleth.idp.authn.context.CertificateContext.java

/**
 * Set the additional certificates accompanying the end-entity certificate.
 * /*w  w w. ja  v  a2s  . c  om*/
 * @param certs additional certificates
 * 
 * @return this context
 */
public CertificateContext setIntermediates(@Nonnull @NonnullElements final Collection<Certificate> certs) {
    Constraint.isNotNull(certs, "Intermediate certificate collection cannot be null");

    intermediates.clear();
    intermediates.addAll(Collections2.filter(certs, Predicates.notNull()));

    return this;
}

From source file:org.opensaml.security.credential.impl.AbstractChainingCredentialResolver.java

/**
 * Constructor.//w w  w. j  av  a 2s .  c om
 * 
 * @param credResolvers the list of chained credential resolvers
 */
public AbstractChainingCredentialResolver(@Nonnull final List<ResolverType> credResolvers) {
    Constraint.isNotNull(credResolvers, "CredentialResolver list cannot be null");
    resolvers = new ArrayList<>(Collections2.filter(credResolvers, Predicates.notNull()));
}

From source file:fi.csc.idp.stepup.impl.CheckRequestedAuthenticationContext.java

/**
 * Sets the list of authentication methods requiring step up.
 * /*from  w w w . j  av  a2 s  .com*/
 * 
 * @param <T>
 *            a type of principal to add, if not generic
 * @param principals
 *            supported principals to add
 */

public <T extends Principal> void setStepupMethods(@Nonnull @NonnullElements final Collection<T> principals) {

    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    Constraint.isNotNull(principals, "Principal collection cannot be null.");
    if (stepupPrincipals == null) {
        stepupPrincipals = new Subject();
    }
    stepupPrincipals.getPrincipals().clear();
    stepupPrincipals.getPrincipals().addAll(Collections2.filter(principals, Predicates.notNull()));

}

From source file:org.opensaml.core.xml.util.IndexedXMLObjectChildrenList.java

/**
 * Constructor./*from   w w w . java 2s .  c  o m*/
 * 
 * @param parent the parent of all elements
 * @param col collection to add to this list
 */
public IndexedXMLObjectChildrenList(@Nonnull final XMLObject parent,
        @Nonnull final Collection<ElementType> col) {
    super(parent);
    Constraint.isNotNull(col, "Initial collection cannot be null");

    objectIndex = new LazyMap<>();

    // This does call our add, which handles the null case properly, but
    // I didn't want to depend on that implementation. Keeping the fail silently
    // behavior means not using an Immutable collection copy.
    addAll(Collections2.filter(col, Predicates.notNull()));
}

From source file:org.xacml4j.v30.Attribute.java

/**
 * Gets all instances of {@link AttributeExp} by type
 *
 * @param type an attribute type/* w  w w  .  j  a  v a  2 s .c  om*/
 * @return a collection of {@link AttributeExp} of given type
 */
public Collection<AttributeExp> getValuesByType(final AttributeExpType type) {
    return Collections2.filter(values, new Predicate<AttributeExp>() {
        @Override
        public boolean apply(AttributeExp a) {
            return a.getType().equals(type);
        }
    });
}

From source file:org.eclipse.emf.compare.rcp.internal.match.MatchEngineFactoryRegistryWrapper.java

/**
 * Return a Collection of enabled {@link IMatchEngine.Factory}.
 * /*  www  .j av  a 2  s . co  m*/
 * @return Collection<IMatchEngine.Factory>
 */
private Collection<IMatchEngine.Factory> getEnabledFactories() {
    Function<IItemDescriptor<Factory>, Factory> toFactoryFunction = AbstractItemDescriptor.getItemFunction();

    Collection<IItemDescriptor<Factory>> enableFactories = Collections2.filter(registry.getItemDescriptors(),
            Predicates.not(Predicates.in(getDisabledEngines())));
    return Collections2.transform(enableFactories, toFactoryFunction);
}

From source file:org.eclipse.smarthome.core.common.registry.AbstractManagedProvider.java

@Override
public Collection<E> getAll() {
    final Function<String, E> toElementList = new Function<String, E>() {
        @Override//from  w w  w.jav a  2  s  . c  om
        public E apply(String elementKey) {
            PE persistableElement = storage.get(elementKey);
            if (persistableElement != null) {
                return toElement(elementKey, persistableElement);
            } else {
                return null;
            }
        }
    };

    Collection<String> keys = storage.getKeys();
    Collection<E> elements = Collections2.filter(Collections2.transform(keys, toElementList),
            Predicates.notNull());

    return ImmutableList.copyOf(elements);
}

From source file:com.strandls.alchemy.inject.AlchemyModuleLister.java

/**
 * Get all guice {@link Module}s for a give environment.
 *
 * @param environment//from   ww  w.  j av a 2 s . c om
 *            the environment to get modules for. Cannot be
 *            <code>null</code>.
 * @return
 */
public Collection<Module> getModules(@NonNull final Environment environment) {
    // get all classes with Alchemy module marker
    final Set<Class<?>> classes = typeQueryHandler.getTypesAnnotatedWith(".*", AlchemyModule.class);
    final List<Module> modules = new ArrayList<Module>();

    log.debug("Looking for modules in Environment: {}", environment);
    for (final Class<?> klass : classes) {
        try {
            final AlchemyModule marker = klass.getAnnotation(AlchemyModule.class);

            log.debug("Found class {}", klass);
            // match against desired environment
            if (marker != null && environment.isCompatible(marker.value())) {
                log.debug("For Environment: {} using : {}", environment, klass);
                modules.add((Module) klass.newInstance());
            } else {
                log.debug("Ignored class {}", klass);
            }
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    // apply the filter and return the result
    return Collections2.filter(modules,
            new AlchemyModuleFilter(filterConfiguration.getFilterConfiguration(environment)));
}

From source file:com.marvelution.bamboo.plugins.sonar.tasks.actions.admin.ViewSonarServerMatrix.java

/**
 * Getter for buildables//w  w  w . j a  va  2 s . c  o m
 *
 * @return the buildables
 */
public Collection<Buildable> getBuildables() {
    if (buildables == null) {
        buildables = Collections2.filter(planManager.getAllPlans(Buildable.class), Predicates.and(
                Predicates.not(PlanPredicates.isSuspendedFromBuilding()), SonarPredicates.hasSonarTasks()));
    }
    return buildables;
}