Example usage for com.google.common.collect ImmutableSet iterator

List of usage examples for com.google.common.collect ImmutableSet iterator

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:com.google.errorprone.bugpatterns.BadImport.java

@Override
public Description matchImport(ImportTree tree, VisitorState state) {
    Symbol symbol;/*  w  w w  .ja va2  s . c  om*/
    ImmutableSet<Symbol> symbols;

    if (!tree.isStatic()) {
        symbol = ASTHelpers.getSymbol(tree.getQualifiedIdentifier());
        if (symbol == null || isAcceptableImport(symbol, BAD_NESTED_CLASSES)) {
            return Description.NO_MATCH;
        }

        symbols = ImmutableSet.of(symbol);
    } else {
        StaticImportInfo staticImportInfo = StaticImports.tryCreate(tree, state);
        if (staticImportInfo == null || staticImportInfo.members().isEmpty()) {
            return Description.NO_MATCH;
        }

        symbols = staticImportInfo.members();

        // Pick an arbitrary symbol. They've all got the same simple name, so it doesn't matter which.
        symbol = symbols.iterator().next();
        if (isAcceptableImport(symbol, BAD_STATIC_IDENTIFIERS)) {
            return Description.NO_MATCH;
        }
    }

    if (symbol.getEnclosingElement() instanceof PackageSymbol) {
        return Description.NO_MATCH;
    }

    SuggestedFix.Builder builder = SuggestedFix.builder().removeImport(symbol.getQualifiedName().toString());

    // Have to start at the symbol's enclosing element because otherwise we find the symbol again
    // immediately.
    String replacement = SuggestedFixes.qualifyType(getCheckState(state), builder, symbol.getEnclosingElement())
            + ".";

    return buildDescription(builder, symbols, replacement, state);
}

From source file:dagger2.internal.codegen.BindingGraphValidator.java

@SuppressWarnings("resource") // Appendable is a StringBuilder.
private void reportProviderMayNotDependOnProducer(Deque<ResolvedRequest> path,
        ValidationReport.Builder<BindingGraph> reportBuilder) {
    StringBuilder errorMessage = new StringBuilder();
    if (path.size() == 1) {
        new Formatter(errorMessage).format(ErrorMessages.PROVIDER_ENTRY_POINT_MAY_NOT_DEPEND_ON_PRODUCER_FORMAT,
                keyFormatter.format(path.peek().request().key()));
    } else {/*  w  w  w .  ja va 2s .  c o  m*/
        ImmutableSet<ProvisionBinding> dependentProvisions = provisionsDependingOnLatestRequest(path);
        // TODO(user): Consider displaying all dependent provisions in the error message. If we do
        // that, should we display all productions that depend on them also?
        new Formatter(errorMessage).format(ErrorMessages.PROVIDER_MAY_NOT_DEPEND_ON_PRODUCER_FORMAT,
                keyFormatter.format(dependentProvisions.iterator().next().key()));
    }
    reportBuilder.addItem(errorMessage.toString(), path.getLast().request().requestElement());
}

From source file:eu.eidas.node.auth.connector.AUCONNECTORSAML.java

private void checkIdentifierFormat(IAuthenticationResponse authnResponse) throws InternalErrorEIDASException {
    String patterEidentifier = "^[A-Z]{2}/[A-Z]{2}/[A-Za-z0-9+/=\r\n]+$";
    if (authnResponse.getAttributes() != null) {
        ImmutableSet personIdentifier = authnResponse.getAttributes().getAttributeValuesByNameUri(
                EidasSpec.Definitions.PERSON_IDENTIFIER.getNameUri().toASCIIString());
        if (personIdentifier != null && !personIdentifier.isEmpty()) {
            if (!Pattern.matches(patterEidentifier,
                    ((StringAttributeValue) personIdentifier.iterator().next()).getValue())) {
                throw new InternalErrorEIDASException(EidasErrorKey.COLLEAGUE_RESP_INVALID_SAML.errorCode(),
                        "Person Identifier has an invalid format.");
            }/* www .j a va 2  s  .  c om*/
        }
        ImmutableSet legalPersonIdentifier = authnResponse.getAttributes().getAttributeValuesByNameUri(
                EidasSpec.Definitions.LEGAL_PERSON_IDENTIFIER.getNameUri().toASCIIString());
        if (legalPersonIdentifier != null && !legalPersonIdentifier.isEmpty()) {
            if (!Pattern.matches(patterEidentifier,
                    ((StringAttributeValue) legalPersonIdentifier.iterator().next()).getValue())) {
                throw new InternalErrorEIDASException(EidasErrorKey.COLLEAGUE_RESP_INVALID_SAML.errorCode(),
                        "Legal person Identifier has an invalid format.");
            }

        }
    }

}

From source file:com.facebook.buck.artifact_cache.SQLiteArtifactCache.java

private ListenableFuture<Void> storeContent(ImmutableSet<RuleKey> contentHashes, BorrowablePath content) {
    try {/*from   ww  w .  jav a 2s .  c o  m*/
        ImmutableSet<RuleKey> toStore = notPreexisting(contentHashes);
        if (toStore.isEmpty()) {
            return Futures.immediateFuture(null);
        }

        long size = filesystem.getFileSize(content.getPath());
        if (size <= maxInlinedBytes) {
            // artifact is small enough to inline in the database
            db.storeArtifact(toStore, Files.readAllBytes(content.getPath()), size);
        } else if (!toStore.isEmpty()) {
            // artifact is too large to inline, store on disk and put path in database
            Path artifactPath = getArtifactPath(toStore.iterator().next());
            filesystem.mkdirs(artifactPath.getParent());

            if (content.canBorrow()) {
                filesystem.move(content.getPath(), artifactPath, StandardCopyOption.REPLACE_EXISTING);
            } else {
                storeArtifactOutput(content.getPath(), artifactPath);
            }

            db.storeFilepath(toStore, artifactPath.toString(), size);
        }
    } catch (IOException | SQLException e) {
        LOG.warn(e, "Artifact store(%s, %s) error", contentHashes, content);
    }

    return Futures.immediateFuture(null);
}