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:org.killbill.billing.plugin.simpletax.config.http.TaxCodeController.java

private static TaxCodesGETRsc toTaxCodesGETRscOrNull(UUID invoiceId, UUID invoiceItemId, String taxCodes) {
    Set<String> names = splitTaxCodes(taxCodes);
    if (names.size() == 0) {
        return null;
    }//from   ww  w.java  2 s.com
    ImmutableSet.Builder<TaxCodeRsc> codes = ImmutableSet.builder();
    for (String name : names) {
        codes.add(new TaxCodeRsc(name));
    }
    return new TaxCodesGETRsc(invoiceItemId, invoiceId, codes.build());
}

From source file:com.google.devtools.build.lib.rules.objc.Xcdatamodel.java

/**
 * Returns the files that should be supplied to Xcodegen when generating a project that includes
 * all of the given xcdatamodel source files.
 *//*from   w ww . ja  v a 2s.c o m*/
public static Iterable<Artifact> inputsToXcodegen(Iterable<Artifact> datamodelFiles) {
    ImmutableSet.Builder<Artifact> inputs = new ImmutableSet.Builder<>();
    for (Artifact generalInput : datamodelFiles) {
        if (generalInput.getExecPath().getBaseName().equals(".xccurrentversion")) {
            inputs.add(generalInput);
        }
    }
    return inputs.build();
}

From source file:google.registry.testing.FullFieldsTestEntityHelper.java

public static HostResource makeHostResource(String fqhn, @Nullable String ip1, @Nullable String ip2) {
    HostResource.Builder builder = new HostResource.Builder().setRepoId(generateNewContactHostRoid())
            .setFullyQualifiedHostName(Idn.toASCII(fqhn))
            .setCreationTimeForTest(DateTime.parse("2000-10-08T00:45:00Z"));
    if ((ip1 != null) || (ip2 != null)) {
        ImmutableSet.Builder<InetAddress> ipBuilder = new ImmutableSet.Builder<>();
        if (ip1 != null) {
            ipBuilder.add(InetAddresses.forString(ip1));
        }//  w  w w.  j a  va 2s.  c  o  m
        if (ip2 != null) {
            ipBuilder.add(InetAddresses.forString(ip2));
        }
        builder.setInetAddresses(ipBuilder.build());
    }
    return builder.build();
}

From source file:io.ytcode.reflect.Reflect.java

public static ImmutableSet<Constructor<?>> constructors(Class<?> c, Predicate<Constructor<?>> p) {
    checkNotNull(c);//from  www  . j  av a  2  s  .c  o  m
    checkNotNull(p);

    ImmutableSet.Builder<Constructor<?>> b = ImmutableSet.builder();
    for (Constructor<?> constructor : c.getDeclaredConstructors()) {
        if (p.apply(constructor)) {
            b.add(constructor);
        }
    }

    for (Class<?> cls : superTypes(c)) {
        for (Constructor<?> constructor : cls.getDeclaredConstructors()) {
            if (p.apply(constructor)) {
                b.add(constructor);
            }
        }
    }
    return b.build();
}

From source file:com.facebook.swift.codec.metadata.ReflectionHelper.java

private static <T extends Annotation> void addAllClassAnnotations(Class<?> type, Class<T> annotation,
        ImmutableSet.Builder<T> builder) {
    if (type.isAnnotationPresent(annotation)) {
        builder.add(type.getAnnotation(annotation));
    }/*w  ww .  jav  a 2 s. co m*/
    if (type.getSuperclass() != null) {
        addAllClassAnnotations(type.getSuperclass(), annotation, builder);
    }
    for (Class<?> anInterface : type.getInterfaces()) {
        addAllClassAnnotations(anInterface, annotation, builder);
    }
}

From source file:org.onos.yangtools.yang.data.util.DataSchemaContextNode.java

public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchema augmentation) {
    ImmutableSet.Builder<QName> potentialChildren = ImmutableSet.builder();
    for (DataSchemaNode child : augmentation.getChildNodes()) {
        potentialChildren.add(child.getQName());
    }/*w w w. java  2 s. co  m*/
    return new AugmentationIdentifier(potentialChildren.build());
}

From source file:com.facebook.buck.util.hashing.PathHashing.java

public static ImmutableSet<Path> hashPath(Hasher hasher, ProjectFileHashLoader fileHashLoader,
        ProjectFilesystem projectFilesystem, Path root) throws IOException {
    Preconditions.checkArgument(!root.equals(EMPTY_PATH), "Path to hash (%s) must not be empty", root);
    ImmutableSet.Builder<Path> children = ImmutableSet.builder();
    for (Path path : ImmutableSortedSet.copyOf(projectFilesystem.getFilesUnderPath(root))) {
        StringHashing.hashStringAndLength(hasher, MorePaths.pathWithUnixSeparators(path));
        if (!root.equals(path)) {
            children.add(root.relativize(path));
        }/*w  w w . j  ava  2  s.co m*/
        hasher.putBytes(fileHashLoader.get(path).asBytes());
    }
    return children.build();
}

From source file:com.google.devtools.build.android.ziputils.SplitZipFilters.java

/**
 * Returns a predicate that returns true for filenames contained in the given zip file.
 *///from  w w  w .j  ava2s.co  m
public static Predicate<String> entriesIn(String filterZip) throws IOException {
    // Aggregate filenames into a set so Predicates.in is efficient
    ImmutableSet.Builder<String> filenames = ImmutableSet.builder();
    @SuppressWarnings("resource") // ZipIn takes ownership but isn't Closable
    ZipIn zip = new ZipIn(new FileInputStream(filterZip).getChannel(), filterZip);
    for (DirectoryEntry entry : zip.centralDirectory().list()) {
        filenames.add(entry.getFilename());
    }
    return Predicates.in(filenames.build());
}

From source file:com.google.devtools.build.lib.actions.ActionInputHelper.java

/** Returns a Set of TreeFileArtifacts with the given parent and parent-relative paths. */
public static Set<TreeFileArtifact> asTreeFileArtifacts(final Artifact parent,
        Set<? extends PathFragment> parentRelativePaths) {
    Preconditions.checkState(parent.isTreeArtifact(), "Given parent %s must be a TreeArtifact", parent);

    ImmutableSet.Builder<TreeFileArtifact> builder = ImmutableSet.builder();
    for (PathFragment path : parentRelativePaths) {
        builder.add(treeFileArtifact(parent, path));
    }/*from  www.  ja v a  2 s  . c o  m*/

    return builder.build();
}

From source file:com.google.api.tools.framework.importers.swagger.TopLevelBuilder.java

private static Set<String> getSwaggerHosts(List<SwaggerFile> swaggers) {
    ImmutableSet.Builder<String> hostNames = ImmutableSet.builder();
    for (SwaggerFile swagger : swaggers) {
        String hostname = swagger.swagger().getHost();
        if (!StringUtils.isBlank(hostname)) {
            hostNames.add(hostname.trim());
        }/* w  w  w  .j  a v a2 s  . c o m*/
    }
    return hostNames.build();
}