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.template.soy.types.parse.ParseErrors.java

/** Pretty prints the parse exception message. */
static String formatParseException(ParseException e) {
    Token errorToken = e.currentToken;/*w w  w.j  a  v  a 2  s .  com*/
    if (errorToken.next != null) {
        errorToken = errorToken.next;
    }

    ImmutableSet.Builder<String> expectedTokenImages = ImmutableSet.builder();
    for (int[] expected : e.expectedTokenSequences) {
        // We only display the first token
        expectedTokenImages.add(getTokenDisplayName(expected[0]));
    }
    return formatParseExceptionDetails(errorToken.image, expectedTokenImages.build().asList());
}

From source file:com.google.template.soy.internal.proto.Field.java

private static ImmutableSet<String> fullFieldNames(Set<? extends Field> fields) {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (Field field : fields) {
        builder.add(field.getDescriptor().getFullName());
    }/*from   w ww. ja  v a  2 s  .  com*/
    return builder.build();
}

From source file:com.palantir.docker.compose.execution.ConflictingContainerRemovingDockerCompose.java

private static Set<String> getConflictingContainerNames(String output) {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    Matcher matcher = NAME_CONFLICT_PATTERN.matcher(output);
    while (matcher.find()) {
        builder.add(matcher.group(1));
    }/*from  w  w w .ja va2 s .  c o  m*/
    return builder.build();
}

From source file:com.facebook.buck.io.ProjectFilesystemDelegateFactory.java

/**
 * Must always create a new delegate for the specified {@code root}.
 *//*  ww  w  .  j  a va2s .  c om*/
public static ProjectFilesystemDelegate newInstance(Path root, String hgCmd, boolean enableAutosparse,
        ImmutableList<String> autosparseIgnore) {
    Optional<EdenClient> client = tryToCreateEdenClient();

    if (client.isPresent()) {
        try {
            EdenMount mount = client.get().getMountFor(root);
            if (mount != null) {
                return new EdenProjectFilesystemDelegate(mount);
            }
        } catch (TException | EdenError e) {
            // If Eden is running but root is not a mount point, Eden getMountFor() should just return
            // null rather than throw an error.
            LOG.error(e, "Failed to find Eden client for %s.", root);
        }
    }

    if (enableAutosparse) {
        // We can't access BuckConfig because that class requires a
        // ProjectFileSystem, which we are in the process of building
        // Access the required info from the Config instead
        HgCmdLineInterface hgCmdLine = new HgCmdLineInterface(new PrintStreamProcessExecutorFactory(), root,
                hgCmd, ImmutableMap.of());
        ImmutableSet.Builder<Path> ignoredPaths = ImmutableSet.builder();
        for (String path : autosparseIgnore) {
            ignoredPaths.add(Paths.get(path));
        }
        AutoSparseState autoSparseState = AbstractAutoSparseFactory.getAutoSparseState(root, hgCmdLine,
                ignoredPaths.build());
        if (autoSparseState != null) {
            LOG.debug("Autosparse enabled, using AutoSparseProjectFilesystemDelegate");
            return new AutoSparseProjectFilesystemDelegate(autoSparseState, root);
        }
    }

    // No Eden or Mercurial info available, use the default
    return new DefaultProjectFilesystemDelegate(root);
}

From source file:org.smartdeveloperhub.vocabulary.util.Version.java

private static ImmutableSet<Namespace> imports(final Module module) {
    final ImmutableSet.Builder<Namespace> builder = ImmutableSet.builder();
    for (final String priorVersion : module.imports()) {
        builder.add(Namespace.create(priorVersion));
    }/*from   w  ww  .jav  a2 s .  co m*/
    return builder.build();
}

From source file:org.sonar.plugins.dotnet.tests.WildcardPatternFileProvider.java

private static void listFiles(ImmutableSet.Builder<File> builder, File dir) {
    File[] files = dir.listFiles();
    if (files != null) {
        builder.add(files);

        for (File file : files) {
            if (file.isDirectory()) {
                listFiles(builder, file);
            }//from   w w w.j  a  va2 s . c o  m
        }
    }
}

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

private static Iterable<PathFragment> uniqueParentDirectories(Iterable<PathFragment> paths) {
    ImmutableSet.Builder<PathFragment> parents = new ImmutableSet.Builder<>();
    for (PathFragment path : paths) {
        parents.add(path.getParentDirectory());
    }//  www .ja  v  a2  s.c o m
    return parents.build();
}

From source file:org.prebake.fs.FilePerms.java

/**
 * @param permBits POSIX style permission bits where bits 6-8 are RWX
 *     respectively for the owner, bits 3-5 are RWX respectively for all users
 *     in the group, and bits 0-2 are RWX respectively for all other users.
 * @return the file permissions corresponding to permBits.
 *///from   w  ww  .jav a 2 s.  c o m
public static @Nonnull Set<PosixFilePermission> permSet(int permBits, boolean isDirectory) {
    if (isDirectory) {
        // Set the executable bit for any of the UGO blocks that have the read
        // or write bits set.
        int fromRead = (permBits >>> 2) & 0111;
        int fromWrite = (permBits >>> 1) & 0111;
        permBits |= fromRead | fromWrite;
    }
    permBits &= 0777;
    ImmutableSet.Builder<PosixFilePermission> posixs = ImmutableSet.builder();
    for (int k = 0; permBits != 0; ++k, permBits >>>= 1) {
        if ((permBits & 1) != 0) {
            posixs.add(POSIX_PERMS[k]);
        }
    }
    return posixs.build();
}

From source file:dk.ilios.spanner.util.Reflection.java

public static ImmutableSet<Method> getAnnotatedMethods(Class<?> clazz,
        Class<? extends Annotation> annotationClass) {
    Method[] methods = clazz.getDeclaredMethods();
    ImmutableSet.Builder<Method> builder = ImmutableSet.builder();
    for (Method method : methods) {
        if (method.isAnnotationPresent(annotationClass)) {
            method.setAccessible(true);// w  w w .j av  a2 s .  co  m
            builder.add(method);
        }
    }
    return builder.build();
}

From source file:org.smartdeveloperhub.vocabulary.util.Version.java

private static ImmutableSet<Namespace> priorVersions(final Module module) {
    final ImmutableSet.Builder<Namespace> builder = ImmutableSet.builder();
    for (final String priorVersion : module.priorVersions()) {
        builder.add(Namespace.create(priorVersion));
    }/*w w w  .ja v  a2 s  .  co  m*/
    return builder.build();
}