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

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

Introduction

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

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.facebook.buck.util.autosparse.AbstractAutoSparseConfig.java

public static AutoSparseConfig of(boolean enabled, List<String> ignore) {
    ImmutableSet.Builder<Path> ignoredPaths = ImmutableSet.builder();
    for (String path : ignore) {
        ignoredPaths.add(Paths.get(path));
    }//  w ww .j  a  v a 2 s . c om
    return AutoSparseConfig.of(enabled, ignoredPaths.build());
}

From source file:ca.cutterslade.match.scheduler.Slot.java

static ImmutableSet<Slot> forNames(Set<Time> times, Set<Court> courts, Set<Day> days) {
    ImmutableSet.Builder<Slot> b = ImmutableSet.builder();
    for (Day day : days)
        for (Court court : courts)
            for (Time time : times)
                b.add(new Slot(time, day, court));
    return b.build();
}

From source file:com.wrmsr.neurosis.util.ImmutableCollectors.java

public static <T> Collector<T, ?, ImmutableSet<T>> toImmutableSet() {
    return Collector.<T, ImmutableSet.Builder<T>, ImmutableSet<T>>of(ImmutableSet.Builder::new,
            ImmutableSet.Builder::add, (left, right) -> {
                left.addAll(right.build());
                return left;
            }, ImmutableSet.Builder::build, Collector.Characteristics.UNORDERED);
}

From source file:co.cask.cdap.common.MasterUtils.java

/**
 * Creates a set of system service resource keys
 * @param cConf the configured CDAP settings
 * @return a set of {@link ServiceResourceKeys} for all system services
 *///from   w  ww. j  av  a2 s  .co  m
public static Set<ServiceResourceKeys> createSystemServicesResourceKeysSet(CConfiguration cConf) {
    ImmutableSet.Builder<ServiceResourceKeys> builder = ImmutableSet.<ServiceResourceKeys>builder()
            .add(new ServiceResourceKeys(cConf, Constants.Service.TRANSACTION,
                    Constants.Transaction.Container.MEMORY_MB, Constants.Transaction.Container.NUM_CORES,
                    Constants.Transaction.Container.NUM_INSTANCES,
                    Constants.Transaction.Container.MAX_INSTANCES))
            .add(new ServiceResourceKeys(cConf, Constants.Service.STREAMS, Constants.Stream.CONTAINER_MEMORY_MB,
                    Constants.Stream.CONTAINER_VIRTUAL_CORES, Constants.Stream.CONTAINER_INSTANCES,
                    Constants.Stream.MAX_INSTANCES))
            .add(new ServiceResourceKeys(cConf, Constants.Service.METRICS, Constants.Metrics.MEMORY_MB,
                    Constants.Metrics.NUM_CORES, Constants.Metrics.NUM_INSTANCES,
                    Constants.Metrics.MAX_INSTANCES))
            .add(new ServiceResourceKeys(cConf, Constants.Service.METRICS_PROCESSOR,
                    Constants.MetricsProcessor.MEMORY_MB, Constants.MetricsProcessor.NUM_CORES,
                    Constants.MetricsProcessor.NUM_INSTANCES, Constants.MetricsProcessor.MAX_INSTANCES))
            .add(new ServiceResourceKeys(cConf, Constants.Service.LOGSAVER, Constants.LogSaver.MEMORY_MB,
                    Constants.LogSaver.NUM_CORES, Constants.LogSaver.NUM_INSTANCES,
                    Constants.LogSaver.MAX_INSTANCES))
            .add(new ServiceResourceKeys(cConf, Constants.Service.DATASET_EXECUTOR,
                    Constants.Dataset.Executor.CONTAINER_MEMORY_MB,
                    Constants.Dataset.Executor.CONTAINER_VIRTUAL_CORES,
                    Constants.Dataset.Executor.CONTAINER_INSTANCES, Constants.Dataset.Executor.MAX_INSTANCES))
            .add(new ServiceResourceKeys(cConf, Constants.Service.MESSAGING_SERVICE,
                    Constants.MessagingSystem.CONTAINER_MEMORY_MB,
                    Constants.MessagingSystem.CONTAINER_VIRTUAL_CORES,
                    Constants.MessagingSystem.CONTAINER_INSTANCES, Constants.MessagingSystem.MAX_INSTANCES));
    if (cConf.getBoolean(Constants.Explore.EXPLORE_ENABLED)) {
        builder.add(new ExploreServiceResourceKeys(cConf, Constants.Service.EXPLORE_HTTP_USER_SERVICE,
                Constants.Explore.CONTAINER_MEMORY_MB, Constants.Explore.CONTAINER_VIRTUAL_CORES));
    }
    return builder.build();
}

From source file:com.facebook.presto.sql.planner.DependencyExtractor.java

public static Set<Symbol> extractUnique(Iterable<? extends Expression> expressions) {
    ImmutableSet.Builder<Symbol> unique = ImmutableSet.builder();
    for (Expression expression : expressions) {
        unique.addAll(extractAll(expression));
    }//from  w  w  w .  ja  va 2 s.c o m
    return unique.build();
}

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

static Iterable<PathFragment> datamodelDirs(Iterable<Artifact> xcdatamodels) {
    ImmutableSet.Builder<PathFragment> result = new ImmutableSet.Builder<>();
    for (Collection<Artifact> artifacts : byContainer(xcdatamodels).asMap().values()) {
        result.addAll(ObjcCommon.uniqueContainers(artifacts, FileType.of(".xcdatamodel")));
    }//  w  w  w  .ja v  a  2 s . co m
    return result.build();
}

From source file:org.terasology.util.Varargs.java

/**
 * Combines a single value and array into an immutable set. Iteration of the set maintains the order of the items.
 * This is intended to aid methods using the mandatory-first optional-additional varargs trick.
 *
 * @param first      The first, single value
 * @param additional Any additional values
 * @param <T>        The type of the items
 * @return A set of the combined values/*from ww w.  j  a v a2  s. c o m*/
 */
@SafeVarargs
public static <T> ImmutableSet<T> combineToSet(T first, T... additional) {
    ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    builder.add(first);
    builder.addAll(Arrays.asList(additional));
    return builder.build();
}

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

public static ImmutableSet<Path> hashPath(Hasher hasher, FileHashLoader 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));
        }//from   w  ww . j a  v a  2  s . co  m
        hasher.putBytes(fileHashLoader.get(projectFilesystem.resolve(path)).asBytes());
    }
    return children.build();
}

From source file:com.twitter.aurora.scheduler.base.Numbers.java

/**
 * Converts a set of integers into a set of contiguous closed ranges that equally represent the
 * input integers./*from   w w w  .j ava2s  .com*/
 * <p>
 * The resulting ranges will be in ascending order.
 *
 * @param values Values to transform to ranges.
 * @return Closed ranges with identical members to the input set.
 */
public static Set<Range<Integer>> toRanges(Iterable<Integer> values) {
    ImmutableSet.Builder<Range<Integer>> builder = ImmutableSet.builder();

    PeekingIterator<Integer> iterator = Iterators.peekingIterator(Sets.newTreeSet(values).iterator());

    // Build ranges until there are no numbers left.
    while (iterator.hasNext()) {
        // Start a new range.
        int start = iterator.next();
        int end = start;
        // Increment the end until the range is non-contiguous.
        while (iterator.hasNext() && (iterator.peek() == (end + 1))) {
            end++;
            iterator.next();
        }

        builder.add(Range.closed(start, end));
    }

    return builder.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));
        }/*from w w  w.  j a v a  2 s .c o m*/
        hasher.putBytes(fileHashLoader.get(path).asBytes());
    }
    return children.build();
}