Example usage for com.google.common.collect ImmutableSet.Builder add

List of usage examples for com.google.common.collect ImmutableSet.Builder add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:com.google.u2f.server.impl.U2FServerReferenceImpl.java

private static Set<String> canonicalizeOrigins(Set<String> origins) {
    ImmutableSet.Builder<String> result = ImmutableSet.builder();
    for (String origin : origins) {
        result.add(canonicalizeOrigin(origin));
    }//from  ww  w  .j  a  v  a 2  s  .  co  m
    return result.build();
}

From source file:com.wrmsr.wava.analyze.Analyses.java

public static Set<Name> getReferencedNames(Node root) {
    ImmutableSet.Builder<Name> builder = ImmutableSet.builder();
    Visitors.preWalk(root, new Visitor<Void, Void>() {
        @Override/*ww  w  . j  av  a  2  s.c o  m*/
        public Void visitBreak(Break node, Void context) {
            builder.add(node.getTarget());
            return null;
        }

        @Override
        public Void visitBreakTable(BreakTable node, Void context) {
            builder.addAll(node.getTargets());
            builder.add(node.getDefaultTarget());
            return null;
        }
    }, null);
    return builder.build();
}

From source file:google.registry.model.registry.label.ReservedList.java

private static ImmutableSet<ReservedList> loadReservedLists(ImmutableSet<Key<ReservedList>> reservedListKeys) {
    ImmutableSet.Builder<ReservedList> builder = new ImmutableSet.Builder<>();
    for (Key<ReservedList> listKey : reservedListKeys) {
        try {/*from   w  w w .  j  av a2 s  .  c om*/
            builder.add(cache.get(listKey.getName()));
        } catch (ExecutionException e) {
            throw new UncheckedExecutionException(
                    String.format("Could not load the reserved list '%s' from the cache", listKey.getName()),
                    e);
        }
    }

    return builder.build();
}

From source file:com.google.errorprone.scanner.BuiltInCheckerSuppliers.java

@SafeVarargs
public static ImmutableSet<BugCheckerInfo> getSuppliers(Class<? extends BugChecker>... checkers) {
    ImmutableSet.Builder<BugCheckerInfo> result = ImmutableSet.builder();
    for (Class<? extends BugChecker> checker : checkers) {
        result.add(BugCheckerInfo.create(checker));
    }/*from w  w  w. j a v a  2  s  .co m*/
    return result.build();
}

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

public static StoreResponseReadResult readStoreRequest(DataInputStream input, OutputStream payloadSink)
        throws IOException {
    ImmutableSet.Builder<RuleKey> rawRuleKeys = ImmutableSet.builder();
    int ruleKeysCount = input.readInt();
    for (int i = 0; i < ruleKeysCount; i++) {
        rawRuleKeys.add(new RuleKey(input.readUTF()));
    }/* w  ww  . ja v a2s. co m*/

    MetadataAndPayloadReadResultInternal resultInternal = readMetadataAndPayload(input, payloadSink);

    StoreResponseReadResult.Builder result = StoreResponseReadResult.builder().from(resultInternal);
    result.setRawKeys(rawRuleKeys.build());
    return result.build();
}

From source file:google.registry.model.index.DomainApplicationIndex.java

/**
 * Returns the set of all DomainApplications for the given fully qualified domain name that do
 * not have a deletion time before the supplied DateTime.
 *///  w ww  . j  a va2s .  com
public static ImmutableSet<DomainApplication> loadActiveApplicationsByDomainName(
        String fullyQualifiedDomainName, DateTime now) {
    DomainApplicationIndex index = load(fullyQualifiedDomainName);
    if (index == null) {
        return ImmutableSet.of();
    }
    ImmutableSet.Builder<DomainApplication> apps = new ImmutableSet.Builder<>();
    for (DomainApplication app : ofy().load().keys(index.getKeys()).values()) {
        DateTime forwardedNow = latestOf(now, app.getUpdateAutoTimestamp().getTimestamp());
        if (app.getDeletionTime().isAfter(forwardedNow)) {
            apps.add(app.cloneProjectedAtTime(forwardedNow));
        }
    }
    return apps.build();
}

From source file:com.facebook.buck.apple.toolchain.impl.ProvisioningProfileMetadataFactory.java

public static ProvisioningProfileMetadata fromProvisioningProfilePath(ProcessExecutor executor,
        ImmutableList<String> readCommand, Path profilePath) throws IOException, InterruptedException {
    Set<Option> options = EnumSet.of(Option.EXPECTING_STD_OUT);

    // Extract the XML from its signed message wrapper.
    ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(readCommand)
            .addCommand(profilePath.toString()).build();
    ProcessExecutor.Result result;
    result = executor.launchAndExecute(processExecutorParams, options, /* stdin */ Optional.empty(),
            /* timeOutMs */ Optional.empty(), /* timeOutHandler */ Optional.empty());
    if (result.getExitCode() != 0) {
        throw new IOException(result.getMessageForResult("Invalid provisioning profile: " + profilePath));
    }/*from  w ww .  j  a v a 2s  . com*/

    try {
        NSDictionary plist = (NSDictionary) PropertyListParser.parse(result.getStdout().get().getBytes());
        Date expirationDate = ((NSDate) plist.get("ExpirationDate")).getDate();
        String uuid = ((NSString) plist.get("UUID")).getContent();

        ImmutableSet.Builder<HashCode> certificateFingerprints = ImmutableSet.builder();
        NSArray certificates = (NSArray) plist.get("DeveloperCertificates");
        HashFunction hasher = Hashing.sha1();
        if (certificates != null) {
            for (NSObject item : certificates.getArray()) {
                certificateFingerprints.add(hasher.hashBytes(((NSData) item).bytes()));
            }
        }

        ImmutableMap.Builder<String, NSObject> builder = ImmutableMap.builder();
        NSDictionary entitlements = ((NSDictionary) plist.get("Entitlements"));
        for (String key : entitlements.keySet()) {
            builder = builder.put(key, entitlements.objectForKey(key));
        }
        String appID = entitlements.get("application-identifier").toString();

        ProvisioningProfileMetadata.Builder provisioningProfileMetadata = ProvisioningProfileMetadata.builder();
        if (plist.get("Platform") != null) {
            for (Object platform : (Object[]) plist.get("Platform").toJavaObject()) {
                provisioningProfileMetadata.addPlatforms((String) platform);
            }
        }
        return provisioningProfileMetadata.setAppID(ProvisioningProfileMetadata.splitAppID(appID))
                .setExpirationDate(expirationDate).setUUID(uuid).setProfilePath(profilePath)
                .setEntitlements(builder.build())
                .setDeveloperCertificateFingerprints(certificateFingerprints.build()).build();
    } catch (Exception e) {
        throw new IllegalArgumentException("Malformed embedded plist: " + e);
    }
}

From source file:com.spotify.missinglink.ClassLoader.java

private static ImmutableSet<DeclaredField> readDeclaredFields(ClassNode classNode) {
    ImmutableSet.Builder<DeclaredField> fields = new ImmutableSet.Builder<>();

    @SuppressWarnings("unchecked")
    final Iterable<FieldNode> classFields = (Iterable<FieldNode>) classNode.fields;
    for (FieldNode field : classFields) {
        fields.add(new DeclaredFieldBuilder().name(field.name).descriptor(TypeDescriptors.fromRaw(field.desc))
                .build());//from  w  w  w  .ja  v a2  s .co  m
    }
    return fields.build();
}

From source file:com.google.api.codegen.config.ProtoField.java

public static Iterable<Iterable<String>> getOneofFieldsNames(Iterable<FieldModel> fields, SurfaceNamer namer) {
    ImmutableSet.Builder<Oneof> oneOfsBuilder = ImmutableSet.builder();
    for (FieldModel field : fields) {
        Oneof oneof = ((ProtoField) field).protoField.getOneof();
        if (oneof == null) {
            continue;
        }//  ww w .  j  a  v a 2  s. c om
        oneOfsBuilder.add(oneof);
    }

    Iterable<Oneof> oneOfs = oneOfsBuilder.build();

    ImmutableList.Builder<Iterable<String>> fieldsNames = ImmutableList.builder();

    for (Oneof oneof : oneOfs) {
        boolean hasItems = false;
        ImmutableSet.Builder<String> fieldNames = ImmutableSet.builder();
        for (Field field : oneof.getFields()) {
            fieldNames.add(namer.getVariableName(new ProtoField(field)));
            hasItems = true;
        }
        if (hasItems) {
            fieldsNames.add(fieldNames.build());
        }
    }
    return fieldsNames.build();
}

From source file:com.google.auto.factory.processor.Parameter.java

static ImmutableSet<Parameter> forParameterList(List<? extends VariableElement> variables,
        List<? extends TypeMirror> variableTypes) {
    checkArgument(variables.size() == variableTypes.size());
    ImmutableSet.Builder<Parameter> builder = ImmutableSet.builder();
    Set<String> names = Sets.newHashSetWithExpectedSize(variables.size());
    for (int i = 0; i < variables.size(); i++) {
        Parameter parameter = forVariableElement(variables.get(i), variableTypes.get(i));
        checkArgument(names.add(parameter.name));
        builder.add(parameter);
    }/*from ww w  .  ja v a 2s  .co  m*/
    ImmutableSet<Parameter> parameters = builder.build();
    checkArgument(variables.size() == parameters.size());
    return parameters;
}