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:com.googlecode.android_scripting.activity.ApiBrowser.java

private void updateAndFilterMethodDescriptors(final String query) {
    mMethodDescriptors = Lists.newArrayList(Collections2.filter(FacadeConfiguration.collectMethodDescriptors(),
            new Predicate<MethodDescriptor>() {
                @Override/*  w w  w .j a va  2s. c o m*/
                public boolean apply(MethodDescriptor descriptor) {
                    Method method = descriptor.getMethod();
                    if (method.isAnnotationPresent(RpcDeprecated.class)) {
                        return false;
                    } else if (method.isAnnotationPresent(RpcMinSdk.class)) {
                        int requiredSdkLevel = method.getAnnotation(RpcMinSdk.class).value();
                        if (FacadeConfiguration.getSdkLevel() < requiredSdkLevel) {
                            return false;
                        }
                    }
                    if (query == null) {
                        return true;
                    }
                    return descriptor.getName().toLowerCase().contains(query.toLowerCase());
                }
            }));
}

From source file:com.streamsets.datacollector.execution.AclManager.java

private Collection<PipelineState> filterPipelineBasedOnReadAcl() throws PipelineException {
    return Collections2.filter(manager.getPipelines(), new Predicate<PipelineState>() {
        @Override// www  .  j  a  v a  2 s.c  om
        public boolean apply(PipelineState pipelineState) {
            try {
                return aclStore.isPermissionGranted(pipelineState.getPipelineId(), EnumSet.of(Action.READ),
                        currentUser);
            } catch (PipelineException e) {
                LOG.warn("Failed to validate ACL");
            }
            return false;
        }
    });
}

From source file:org.apache.storm.st.wrapper.TopoWrap.java

private static String getJarPath() {
    final String USER_DIR = "user.dir";
    String userDirVal = System.getProperty(USER_DIR);
    Assert.assertNotNull(userDirVal, "property " + USER_DIR + " was not set.");
    File projectDir = new File(userDirVal);
    AssertUtil.exists(projectDir);//w  w  w.ja va2s  .  co m
    Collection<File> allJars = FileUtils.listFiles(projectDir, new String[] { "jar" }, true);
    final Collection<File> jarFiles = Collections2.filter(allJars, new Predicate<File>() {
        @Override
        public boolean apply(@Nullable File input) {
            return input != null && !input.getName().contains("surefirebooter");
        }
    });
    log.info("Found jar files: " + jarFiles);
    AssertUtil.nonEmpty(jarFiles,
            "The jar file is missing - did you run 'mvn clean package -DskipTests' before running tests ?");
    String jarFile = null;
    for (File jarPath : jarFiles) {
        log.info("jarPath = " + jarPath);
        if (jarPath != null && !jarPath.getPath().contains("original")) {
            AssertUtil.exists(jarPath);
            jarFile = jarPath.getAbsolutePath();
            break;
        }
    }
    Assert.assertNotNull(jarFile, "Couldn't detect a suitable jar file for uploading.");
    log.info("jarFile = " + jarFile);
    return jarFile;
}

From source file:org.knime.core.node.defaultnodesettings.DialogComponentRapidMinerProject.java

@Override
@SuppressWarnings("unchecked")
public List<? extends DataTableSpec> getFilteredTableSpecs() {
    if (getLastTableSpecs() == null) {
        return Collections.emptyList();
    }//from ww  w.j a  v a  2  s  .  c  o  m
    @SuppressWarnings("rawtypes")
    final Collection filtered = Collections2.filter(Arrays.asList(getLastTableSpecs()),
            new Predicate<PortObjectSpec>() {

                @Override
                public boolean apply(final PortObjectSpec input) {
                    return input != null && input instanceof DataTableSpec;
                }
            });
    return new ArrayList<DataTableSpec>(filtered);
}

From source file:org.opensaml.saml.metadata.resolver.impl.CompositeMetadataResolver.java

/**
 * Sets the current set of metadata resolvers.
 * //from   www .j  a  v  a2 s. c  om
 * @param newResolvers the metadata resolvers to use
 * 
 * @throws ResolverException thrown if there is a problem adding the metadata provider
 */
public void setResolvers(@Nonnull @NonnullElements List<MetadataResolver> newResolvers)
        throws ResolverException {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);

    if (newResolvers == null || newResolvers.isEmpty()) {
        resolvers = Collections.emptyList();
        return;
    }

    resolvers = new ArrayList<>(Collections2.filter(newResolvers, Predicates.notNull()));
}

From source file:org.tzi.use.uml.sys.MObjectState.java

/**
 * Used for a new object to initialize the values
 * for attributes that have an initialize expression.
 *//*from  ww w  .j  a va2 s.  co  m*/
public void initialize(MSystemState state) {

    Collection<MAttribute> initAttr = Collections2.filter(fAttrSlots.keySet(), new Predicate<MAttribute>() {
        @Override
        public boolean apply(MAttribute input) {
            return input.getInitExpression().isPresent();
        }
    });

    if (initAttr.isEmpty()) {
        return;
    }

    List<MAttribute> sortedAttributes = new ArrayList<>(initAttr);

    // Definition order is important for init expressions.
    Collections.sort(sortedAttributes, new Comparator<MAttribute>() {
        @Override
        public int compare(MAttribute attr1, MAttribute attr2) {
            int position1 = attr1.getPositionInModel();
            int position2 = attr2.getPositionInModel();
            return Integer.compare(position1, position2);
        }
    });

    for (MAttribute attr : sortedAttributes) {
        Value v = state.evaluateInitExpression(this.fObject, attr.getInitExpression().get());
        setAttributeValue(attr, v);
    }
}

From source file:net.shibboleth.idp.saml.saml2.profile.delegation.DelegationContext.java

/**
 * Set the relying party credentials which will be included in the assertion's {@link KeyInfoConfirmationDataType}.
 * //from  ww w  . ja v a  2 s.  c  o m
 * @param credentials the confirmation credentials
 */
public void setSubjectConfirmationCredentials(@Nullable @NonnullElements final List<Credential> credentials) {
    if (credentials == null) {
        subjectConfirmationCredentials = null;
    } else {
        subjectConfirmationCredentials = new ArrayList<>(
                Collections2.filter(credentials, Predicates.notNull()));
    }
}

From source file:org.apache.bazel.checkstyle.PythonCheckstyle.java

@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {

    ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
    SpawnInfo spawnInfo = info.getExtension(SpawnInfo.spawnInfo);

    return Collections2.filter(spawnInfo.getInputFileList(),
            Predicates.and(/*  www  .  j  a v  a2 s.com*/
                    Predicates.or(Predicates.containsPattern(".*/src/.+\\.py[c]{0,1}$"),
                            Predicates.containsPattern("^heronpy/.+\\.py[c]{0,1}$")),
                    Predicates.not(Predicates.containsPattern("third_party/")),
                    Predicates.not(Predicates.containsPattern("integration_test/"))));
}

From source file:net.shibboleth.idp.authn.impl.ValidateUserAgentAddress.java

/**
 * Set the IP range(s) to authenticate as particular principals.
 * //from w ww  .  ja va 2  s  .c o m
 * @param newMappings the IP range(s) to authenticate as particular principals
 */
public void setMappings(@Nonnull @NonnullElements Map<String, Collection<IPRange>> newMappings) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);

    mappings = new HashMap(newMappings.size());
    for (Map.Entry<String, Collection<IPRange>> e : newMappings.entrySet()) {
        if (!Strings.isNullOrEmpty(e.getKey())) {
            mappings.put(e.getKey(), new ArrayList(Collections2.filter(e.getValue(), Predicates.notNull())));
        }
    }
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.ChoiceModificationStrategy.java

ChoiceModificationStrategy(final ChoiceSchemaNode schemaNode, final DataTreeConfiguration treeConfig) {
    super(ChoiceNode.class, treeConfig);

    final Builder<PathArgument, ModificationApplyOperation> childBuilder = ImmutableMap.builder();
    final Builder<PathArgument, CaseEnforcer> enforcerBuilder = ImmutableMap.builder();
    for (final ChoiceCaseNode caze : schemaNode.getCases()) {
        final CaseEnforcer enforcer = CaseEnforcer.forTree(caze, treeConfig);
        if (enforcer != null) {
            for (final Entry<NodeIdentifier, DataSchemaNode> e : enforcer.getChildEntries()) {
                childBuilder.put(e.getKey(), SchemaAwareApplyOperation.from(e.getValue(), treeConfig));
                enforcerBuilder.put(e.getKey(), enforcer);
            }//from   w w  w  .j  ava 2 s.c o m
            for (final Entry<AugmentationIdentifier, AugmentationSchema> e : enforcer
                    .getAugmentationEntries()) {
                childBuilder.put(e.getKey(),
                        new AugmentationModificationStrategy(e.getValue(), caze, treeConfig));
                enforcerBuilder.put(e.getKey(), enforcer);
            }
        }
    }
    childNodes = childBuilder.build();
    caseEnforcers = enforcerBuilder.build();

    final Map<CaseEnforcer, Collection<CaseEnforcer>> exclusionsBuilder = new HashMap<>();
    for (final CaseEnforcer e : caseEnforcers.values()) {
        exclusionsBuilder.put(e, ImmutableList
                .copyOf(Collections2.filter(caseEnforcers.values(), Predicates.not(Predicates.equalTo(e)))));
    }
    exclusions = ImmutableMap.copyOf(exclusionsBuilder);
}