Example usage for com.google.common.collect Iterables contains

List of usage examples for com.google.common.collect Iterables contains

Introduction

In this page you can find the example usage for com.google.common.collect Iterables contains.

Prototype

public static boolean contains(Iterable<?> iterable, @Nullable Object element) 

Source Link

Document

Returns true if iterable contains any object for which equals(element) is true.

Usage

From source file:com.microsoftopentechnologies.auth.jwt.JWTClaimsSet.java

public static JWTClaimsSet parse(JsonObject claims) {
    JWTClaimsSet claimsSet = new JWTClaimsSet();

    // initialize standard claims
    claimsSet.setIssuer(JsonUtils.getJsonStringProp(claims, "iss"));
    claimsSet.setSubject(JsonUtils.getJsonStringProp(claims, "sub"));
    claimsSet.setAudience(JsonUtils.getJsonStringProp(claims, "aud"));
    claimsSet.setExpirationTime(new Date(JsonUtils.getJsonLongProp(claims, "exp") * 1000));
    claimsSet.setNotBeforeTime(new Date(JsonUtils.getJsonLongProp(claims, "nbf") * 1000));
    claimsSet.setIssueTime(new Date(JsonUtils.getJsonLongProp(claims, "iat") * 1000));
    claimsSet.setJwtID(JsonUtils.getJsonStringProp(claims, "jti"));

    // initialize custom claims
    Map<String, JsonElement> customClaims = claimsSet.getCustomClaims();
    for (Map.Entry<String, JsonElement> entry : claims.entrySet()) {
        if (!Iterables.contains(standardClaims, entry.getKey())) {
            customClaims.put(entry.getKey(), entry.getValue());
        }/*from  w ww. java  2s  . c o m*/
    }

    return claimsSet;
}

From source file:com.yammer.collections.azure.AbstractCollectionView.java

@Override
public boolean contains(Object o) {
    return o != null && Iterables.contains(Iterables.transform(getBackingIterable(), typeExtractor), o);
}

From source file:net.kerflyn.broceliand.loader.SellerLoader.java

private boolean isInteresting(QName name) {
    return Iterables.contains(Arrays.asList("country", "city", "seller"), name.toString());
}

From source file:org.sosy_lab.cpachecker.util.expressions.And.java

private And(ImmutableSet<ExpressionTree<LeafType>> pOperands) {
    assert Iterables.size(pOperands) >= 2;
    assert !Iterables.contains(pOperands, ExpressionTrees.getFalse());
    assert !Iterables.contains(pOperands, ExpressionTrees.getTrue());
    assert !FluentIterable.from(pOperands).anyMatch(Predicates.instanceOf(And.class));
    operands = pOperands;/*from w  w  w.  j a  v  a2 s  .  co  m*/
    hashCode = operands.hashCode();
}

From source file:eu.numberfour.n4js.external.RebuildWorkspaceProjectsScheduler.java

/**
 * Schedules a build with the given projects. Does nothing if the {@link Platform platform} is not running, or the
 * iterable of projects is empty.//from   ww w  .j a  v  a2  s  .  c om
 *
 * @param toUpdate
 *            an iterable of projects to build.
 */
public void scheduleBuildIfNecessary(final Iterable<IProject> toUpdate) {
    if (Platform.isRunning() && !Iterables.isEmpty(toUpdate)) {
        final Workspace workspace = (Workspace) ResourcesPlugin.getWorkspace();
        final IBuildConfiguration[] projectsToReBuild = from(asList(workspace.getBuildOrder()))
                .filter(config -> Iterables.contains(toUpdate, config.getProject()))
                .toArray(IBuildConfiguration.class);

        if (!Arrays2.isEmpty(projectsToReBuild)) {
            new RebuildWorkspaceProjectsJob(projectsToReBuild).schedule();
        }
    }
}

From source file:org.apache.whirr.service.TagBuilder.java

public static <T extends NodeMetadata> NodeMetadata getSingleNodeInRole(final String roleAbreviation,
        Collection<T> nodes) {
    return Iterables.getOnlyElement(Collections2.filter(nodes, new Predicate<NodeMetadata>() {
        @Override// www.  j  av a  2 s  .c  om
        public boolean apply(NodeMetadata metadata) {
            return Iterables.contains(rolesFromTag(metadata.getTag()), roleAbreviation);
        }
    }));
}

From source file:org.jclouds.vcloud.director.v1_5.functions.OrgsForNames.java

@Override
public Iterable<? extends Org> apply(final Iterable<String> from) {
    return from(api.getOrgApi().list()).filter(new Predicate<Reference>() {
        @Override//w ww .  j av a 2 s .com
        public boolean apply(Reference in) {
            return Iterables.contains(from, in.getName());
        }
    }).transform(new Function<Reference, Org>() {

        @Override
        public Org apply(Reference in) {
            return api.getOrgApi().get(in.getHref());
        }

    });
}

From source file:com.bennavetta.vetinari.build.internal.phase.RenderPhase.java

private Renderer getRenderer(Page page, Site site) {
    Renderer renderer = null;/*w w  w.ja va 2 s.c om*/
    // The last file extension is always the renderer, if anything.
    final String extension = getFileExtension(page.getPath().toString());
    Optional<Renderer> rendererFromExtension = Iterables.tryFind(renderers,
            r -> Iterables.contains(r.getFileExtensions(), extension));
    if (rendererFromExtension.isPresent()) {
        renderer = rendererFromExtension.get();
    } else if (page.getMetadata().hasPath("renderer")) {
        final String rendererName = page.getMetadata().getString("renderer");
        renderer = Iterables.find(renderers, r -> rendererName.equals(r.getName()));
    } else {
        renderer = Iterables.find(renderers, r -> site.getDefaultRenderer().equals(r.getName()));
    }
    return renderer;
}

From source file:org.opendaylight.netconf.md.sal.rest.schema.SchemaRetrievalServiceImpl.java

@Override
public SchemaExportContext getSchema(final String mountAndModule) {
    final SchemaContext schemaContext;
    final Iterable<String> pathComponents = SLASH_SPLITTER.split(mountAndModule);
    final Iterator<String> componentIter = pathComponents.iterator();
    if (!Iterables.contains(pathComponents, MOUNT_ARG)) {
        schemaContext = salContext.getGlobalSchema();
    } else {/*from w  w  w. j  av  a  2s.co m*/
        final StringBuilder pathBuilder = new StringBuilder();
        while (componentIter.hasNext()) {
            final String current = componentIter.next();
            // It is argument, not last element.
            if (pathBuilder.length() != 0) {
                pathBuilder.append("/");
            }
            pathBuilder.append(current);
            if (MOUNT_ARG.equals(current)) {
                // We stop right at mountpoint, last two arguments should
                // be module name and revision
                break;
            }
        }
        schemaContext = getMountSchemaContext(pathBuilder.toString());

    }

    RestconfValidationUtils.checkDocumentedError(componentIter.hasNext(), ErrorType.PROTOCOL,
            ErrorTag.INVALID_VALUE, "Module name must be supplied.");
    final String moduleName = componentIter.next();
    RestconfValidationUtils.checkDocumentedError(componentIter.hasNext(), ErrorType.PROTOCOL,
            ErrorTag.INVALID_VALUE, "Revision date must be supplied.");
    final String revisionString = componentIter.next();
    return getExportUsingNameAndRevision(schemaContext, moduleName, revisionString);
}

From source file:org.sosy_lab.cpachecker.util.expressions.And.java

public static <LeafType> ExpressionTree<LeafType> of(Iterable<ExpressionTree<LeafType>> pOperands) {
    // If one of the operands is false, return false
    if (Iterables.contains(pOperands, ExpressionTrees.getFalse())) {
        return ExpressionTrees.getFalse();
    }//ww w. j  av a 2 s  . c  o m
    // Filter out trivial operands and flatten the hierarchy
    ImmutableSet<ExpressionTree<LeafType>> operands = FluentIterable.from(pOperands)
            .filter(Predicates.not(Predicates.equalTo(ExpressionTrees.<LeafType>getTrue())))
            .transformAndConcat(new Function<ExpressionTree<LeafType>, Iterable<ExpressionTree<LeafType>>>() {

                @Override
                public Iterable<ExpressionTree<LeafType>> apply(ExpressionTree<LeafType> pOperand) {
                    if (pOperand instanceof And) {
                        return (And<LeafType>) pOperand;
                    }
                    return Collections.singleton(pOperand);
                }
            }).toSet();
    // If there are no operands, return the neutral element
    if (operands.isEmpty()) {
        return ExpressionTrees.getTrue();
    }
    // If there is only one operand, return it
    if (operands.size() == 1) {
        return operands.iterator().next();
    }
    return new And<>(operands);
}