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

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

Introduction

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

Prototype

public static <E> ImmutableSet<E> copyOf(Iterator<? extends E> elements) 

Source Link

Usage

From source file:com.google.devtools.build.lib.worker.ExampleWorker.java

public static void main(String[] args) throws Exception {
    if (ImmutableSet.copyOf(args).contains("--persistent_worker")) {
        OptionsParser parser = OptionsParser.newOptionsParser(ExampleWorkerOptions.class);
        parser.setAllowResidue(false);// w  ww . ja v  a 2s  . co  m
        parser.parse(args);
        ExampleWorkerOptions workerOptions = parser.getOptions(ExampleWorkerOptions.class);
        Preconditions.checkState(workerOptions.persistentWorker);

        runPersistentWorker(workerOptions);
    } else {
        // This is a single invocation of the example that exits after it processed the request.
        processRequest(ImmutableList.copyOf(args));
    }
}

From source file:edu.mit.streamjit.test.Benchmarker.java

public static void main(String[] args) throws InterruptedException, ExecutionException {
    OptionParser parser = new OptionParser();
    //      ArgumentAcceptingOptionSpec<String> requiredTestClasses = parser.accepts("require-test-class")
    //            .withRequiredArg().withValuesSeparatedBy(',').ofType(String.class);
    ArgumentAcceptingOptionSpec<String> includedStreamClasses = parser.accepts("include-stream-class")
            .withRequiredArg().withValuesSeparatedBy(',').ofType(String.class);
    ArgumentAcceptingOptionSpec<String> excludedStreamClasses = parser.accepts("exclude-stream-class")
            .withRequiredArg().withValuesSeparatedBy(',').ofType(String.class);
    ArgumentAcceptingOptionSpec<Attribute> includedAttributes = parser.accepts("include-attribute")
            .withRequiredArg().withValuesSeparatedBy(',').ofType(Attribute.class);
    ArgumentAcceptingOptionSpec<Attribute> excludedAttributes = parser.accepts("exclude-attribute")
            .withRequiredArg().withValuesSeparatedBy(',').ofType(Attribute.class);
    ArgumentAcceptingOptionSpec<Integer> threadsOpt = parser.accepts("threads").withOptionalArg()
            .ofType(Integer.class).defaultsTo(Runtime.getRuntime().availableProcessors());
    parser.accepts("check");

    OptionSet options = parser.parse(args);
    ImmutableSet<String> includedClasses = ImmutableSet.copyOf(includedStreamClasses.values(options));
    ImmutableSet<String> excludedClasses = ImmutableSet.copyOf(excludedStreamClasses.values(options));
    EnumSet<Attribute> includedAttrs = options.has(includedAttributes)
            ? EnumSet.copyOf(includedAttributes.values(options))
            : EnumSet.noneOf(Attribute.class);
    EnumSet<Attribute> excludedAttrs = options.has(excludedAttributes)
            ? EnumSet.copyOf(excludedAttributes.values(options))
            : EnumSet.noneOf(Attribute.class);
    int threads = !options.has(threadsOpt) ? 1 : options.valueOf(threadsOpt);

    ExecutorService executor = Executors.newFixedThreadPool(threads);
    CountingExecutorCompletionService<Result> completionService = new CountingExecutorCompletionService<>(
            executor);/*from  w w  w .j a v  a 2  s  .co  m*/
    for (Iterator<BenchmarkProvider> providerIterator = new SkipMissingServicesIterator<>(
            ServiceLoader.load(BenchmarkProvider.class).iterator()); providerIterator.hasNext();)
        completionService.submit(new BenchmarkProviderFilterTask(providerIterator.next(), includedClasses,
                excludedClasses, includedAttrs, excludedAttrs, completionService), null);

    while (completionService.pendingTasks() > 0) {
        Result r = completionService.take().get();
        if (r != null)
            r.print(System.out);
    }
    executor.shutdown();
    executor.awaitTermination(5, TimeUnit.SECONDS);
    //Even if we didn't shut down cleanly, we're done.
    System.exit(0);
}

From source file:software.betamax.ComposedMatchRule.java

public static MatchRule of(MatchRule... rules) {
    return new ComposedMatchRule(ImmutableSet.copyOf(rules));
}

From source file:com.facebook.presto.spi.testing.InterfaceTestUtils.java

public static <I, C extends I> void assertAllMethodsOverridden(Class<I> iface, Class<C> clazz) {
    assertEquals(ImmutableSet.copyOf(clazz.getInterfaces()), ImmutableSet.of(iface));
    for (Method method : iface.getMethods()) {
        try {/* ww  w  . j  a va2  s  .  c  om*/
            Method override = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
            assertEquals(override.getReturnType(), method.getReturnType());
        } catch (NoSuchMethodException e) {
            fail(format("%s does not override [%s]", clazz.getName(), method));
        }
    }
}

From source file:org.graylog2.indexer.esplugin.IndicesClosedEvent.java

public static IndicesClosedEvent create(Set<String> indices) {
    return new AutoValue_IndicesClosedEvent(ImmutableSet.copyOf(indices));
}

From source file:org.graylog2.indexer.esplugin.IndicesReopenedEvent.java

public static IndicesReopenedEvent create(Set<String> indices) {
    return new AutoValue_IndicesReopenedEvent(ImmutableSet.copyOf(indices));
}

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

static ImmutableSet<Day> forNames(Set<String> days) {
    return ImmutableSet.copyOf(Collections2.transform(days, new Function<String, Day>() {

        @Override// ww w.  j  a  v  a  2 s . c o  m
        public Day apply(String name) {
            return new Day(name);
        }
    }));
}

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

static ImmutableSet<Gym> forNames(Set<String> names) {
    return ImmutableSet.copyOf(Collections2.transform(names, new Function<String, Gym>() {

        @Override//from  w  ww  .j a  v a 2s  . com
        public Gym apply(String name) {
            return new Gym(name);
        }
    }));
}

From source file:com.facebook.presto.hive.metastore.HivePrivilege.java

public static Set<HivePrivilege> parsePrivilege(PrivilegeGrantInfo userGrant) {
    String name = userGrant.getPrivilege().toUpperCase(ENGLISH);
    switch (name) {
    case "ALL":
        return ImmutableSet.copyOf(values());
    case "SELECT":
        return ImmutableSet.of(SELECT);
    case "INSERT":
        return ImmutableSet.of(INSERT);
    case "UPDATE":
        return ImmutableSet.of(UPDATE);
    case "DELETE":
        return ImmutableSet.of(DELETE);
    case "OWNERSHIP":
        return ImmutableSet.of(OWNERSHIP);
    }/*from   w w  w. j av a  2  s.c  om*/
    return ImmutableSet.of();
}

From source file:org.graylog2.indexer.indices.events.IndicesDeletedEvent.java

public static IndicesDeletedEvent create(Set<String> indices) {
    return new AutoValue_IndicesDeletedEvent(ImmutableSet.copyOf(indices));
}