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.facebook.watchman.environment.ExecutableFinder.java

private static ImmutableSet<Path> getPaths(ImmutableMap<String, String> env) {
    ImmutableSet.Builder<Path> paths = ImmutableSet.builder();

    // Add the empty path so that when we iterate over it, we can check for the suffixed version of
    // a given path, be it absolute or not.
    paths.add(Paths.get(""));

    String pathEnv = env.get("PATH");
    if (pathEnv != null) {
        paths.addAll(FluentIterable.from(Splitter.on(pathSeparator).omitEmptyStrings().split(pathEnv))
                .transform(TO_PATH));/*from w  w w  . j  av a2  s  .  c om*/
    }

    if (Platform.isMac()) {
        Path osXPaths = Paths.get("/etc/paths");
        if (Files.exists(osXPaths)) {
            try {
                paths.addAll(FluentIterable.from(Files.readAllLines(osXPaths, Charset.defaultCharset()))
                        .transform(TO_PATH));
            } catch (IOException e) {
            }
        }
    }

    return paths.build();
}

From source file:io.prestosql.plugin.accumulo.conf.AccumuloTableProperties.java

/**
 * Gets the configured locality groups for the table, or Optional.empty() if not set.
 * <p>//from   w  w  w. ja  va 2 s  . c  om
 * All strings are lowercase.
 *
 * @param tableProperties The map of table properties
 * @return Optional map of locality groups
 */
public static Optional<Map<String, Set<String>>> getLocalityGroups(Map<String, Object> tableProperties) {
    requireNonNull(tableProperties);

    @SuppressWarnings("unchecked")
    String groupStr = (String) tableProperties.get(LOCALITY_GROUPS);
    if (groupStr == null) {
        return Optional.empty();
    }

    ImmutableMap.Builder<String, Set<String>> groups = ImmutableMap.builder();

    // Split all configured locality groups
    for (String group : PIPE_SPLITTER.split(groupStr)) {
        String[] locGroups = Iterables.toArray(COLON_SPLITTER.split(group), String.class);

        if (locGroups.length != 2) {
            throw new PrestoException(INVALID_TABLE_PROPERTY,
                    "Locality groups string is malformed. See documentation for proper format.");
        }

        String grpName = locGroups[0];
        ImmutableSet.Builder<String> colSet = ImmutableSet.builder();

        for (String f : COMMA_SPLITTER.split(locGroups[1])) {
            colSet.add(f.toLowerCase(Locale.ENGLISH));
        }

        groups.put(grpName.toLowerCase(Locale.ENGLISH), colSet.build());
    }

    return Optional.of(groups.build());
}

From source file:com.outerspacecat.icalendar.VTimeZone.java

/**
 * Parses a time zone component.//from w  ww. j  a  v  a 2s .co m
 * 
 * @param comp the component to parse. Must be non {@code null}.
 * @return a time zone. Never {@code null}.
 * @throws CalendarParseException if {@code comp} does not represent a valid
 *         time zone
 */
public static VTimeZone parse(final Component comp) throws CalendarParseException {
    Preconditions.checkNotNull(comp, "comp required");
    Preconditions.checkArgument(comp.getName().equals("VTIMEZONE"),
            "component name must be VTIMEZONE, saw: " + comp.getName());

    Property prop = comp.getSingleProperty("TZID");
    TypedProperty<TextType> id = new TypedProperty<>(prop.asText(), prop.getParameters().values());

    ImmutableSet.Builder<VTimeZoneObservance> componentsBuilder = ImmutableSet.builder();

    for (Component standard : comp.getComponents().get("STANDARD"))
        componentsBuilder.add(VTimeZoneObservance.parse(standard));

    for (Component daylight : comp.getComponents().get("DAYLIGHT"))
        componentsBuilder.add(VTimeZoneObservance.parse(daylight));

    return new VTimeZone(id, componentsBuilder.build(),
            comp.getPropertiesExcept(RESTRICTED_PROPERTY_NAMES).values(),
            comp.getComponentsExcept(RESTRICTED_COMPONENT_NAMES).values());
}

From source file:io.flutter.utils.FileWatch.java

/**
 * Starts watching some paths beneath a VirtualFile.
 *
 * <p>Each path is relative to the VirtualFile and need not exist.
 *
 * @param callback will be run asynchronously sometime after the file changed.
 *///www.  java 2 s. c o m
public static @NotNull FileWatch subscribe(@NotNull VirtualFile base, @NotNull Iterable<String> paths,
        @NotNull Runnable callback) {
    final ImmutableSet.Builder<Location> builder = ImmutableSet.builder();
    for (String path : paths) {
        builder.add(new Location(base, path));
    }
    final FileWatch watcher = new FileWatch(builder.build(), callback);
    subscriptions.subscribe(watcher);
    return watcher;
}

From source file:org.glowroot.plugin.servlet.ServletPluginProperties.java

private static ImmutableSet<String> buildCaptureSessionAttributeNames() {
    ImmutableSet.Builder<String> names = ImmutableSet.builder();
    for (String captureSessionAttributePath : captureSessionAttributePaths) {
        int index = captureSessionAttributePath.indexOf('.');
        if (index == -1) {
            names.add(captureSessionAttributePath);
        } else {//from  ww w  .  ja  v  a  2  s .  c o m
            names.add(captureSessionAttributePath.substring(0, index));
        }
    }
    return names.build();
}

From source file:uk.ac.ebi.atlas.search.baseline.BaselineExperimentAssayGroupSearchService.java

static ImmutableSet<IndexedAssayGroup> createSetOfIndexedAssayGroups(
        SetMultimap<String, String> assayGroupsPerExperiment) {
    ImmutableSet.Builder<IndexedAssayGroup> builder = ImmutableSet.builder();

    for (Map.Entry<String, String> entry : assayGroupsPerExperiment.entries()) {
        builder.add(new IndexedAssayGroup(entry.getKey(), entry.getValue()));
    }/*from   w  w  w. j a  v a  2s .c  om*/

    return builder.build();
}

From source file:co.cask.cdap.common.lang.ProgramClassLoader.java

/**
 * Constructs an instance that load classes from the given directory for the given program type.
 * <p/>//  w  w w . jav  a2s .c om
 * The URLs for class loading are:
 * <p/>
 * <pre>
 * [dir]
 * [dir]/*.jar
 * [dir]/lib/*.jar
 * </pre>
 */
public static ProgramClassLoader create(File unpackedJarDir, ClassLoader parentClassLoader,
        @Nullable ProgramType programType) throws IOException {
    Set<String> visibleResources = ProgramResources.getVisibleResources(programType);
    ImmutableSet.Builder<String> visiblePackages = ImmutableSet.builder();
    for (String resource : visibleResources) {
        if (resource.endsWith(".class")) {
            int idx = resource.lastIndexOf('/');
            // Ignore empty package
            if (idx > 0) {
                visiblePackages.add(resource.substring(0, idx));
            }
        }
    }

    ClassLoader filteredParent = new FilterClassLoader(Predicates.in(visibleResources),
            Predicates.in(visiblePackages.build()), parentClassLoader);
    return new ProgramClassLoader(unpackedJarDir, filteredParent);
}

From source file:dagger2.internal.codegen.writer.Snippet.java

public static Snippet format(String format, Object... args) {
    ImmutableSet.Builder<TypeName> types = ImmutableSet.builder();
    for (Object arg : args) {
        if (arg instanceof Snippet) {
            types.addAll(((Snippet) arg).types);
        }//from   w  w  w .j a v  a  2 s  .c  o m
        if (arg instanceof TypeName) {
            types.add((TypeName) arg);
        }
        if (arg instanceof HasTypeName) {
            types.add(((HasTypeName) arg).name());
        }
    }
    return new Snippet(format, types.build(), ImmutableList.copyOf(args));
}

From source file:org.openspotlight.common.util.SLCollections.java

public static <T> Iterable<T> iterableOfOne(final T t) {
    final ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    builder.add(t);
    return builder.build();
}

From source file:com.spectralogic.ds3autogen.java.generators.typemodels.BaseTypeGenerator.java

/**
 * Gets all the required imports that the elements will need in order to properly
 * generate the java model/*from  w w w .j a va  2  s  .c  o m*/
 */
protected static ImmutableList<String> getImportsFromDs3Elements(final ImmutableList<Ds3Element> elements) {
    if (isEmpty(elements)) {
        return ImmutableList.of();
    }
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (final Ds3Element element : elements) {
        if (element.getType().contains(".") && !ConvertType.isModelName(element.getType())) {
            builder.add(ConvertType.toModelName(element.getType()));
        }
        if (hasContent(element.getComponentType()) && element.getComponentType().contains(".")) {
            if (!ConvertType.isModelName(element.getComponentType())) {
                builder.add(ConvertType.toModelName(element.getComponentType()));
            }
            builder.add("java.util.List");
            builder.add("java.util.ArrayList");
            builder.add("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper");
        }
        if (isAttribute(element.getDs3Annotations())) {
            builder.add("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty");
        }
    }
    return builder.build().asList();
}