Example usage for com.google.common.collect ImmutableMap of

List of usage examples for com.google.common.collect ImmutableMap of

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap of.

Prototype

public static <K, V> ImmutableMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) 

Source Link

Usage

From source file:org.apache.spark.examples.mllib.JavaStratifiedSamplingExample.java

public static void main(String[] args) {

    SparkConf conf = new SparkConf().setAppName("JavaStratifiedSamplingExample");
    JavaSparkContext jsc = new JavaSparkContext(conf);

    @SuppressWarnings("unchecked")
    // $example on$
    List<Tuple2<Integer, Character>> list = Arrays.asList(new Tuple2<>(1, 'a'), new Tuple2<>(1, 'b'),
            new Tuple2<>(2, 'c'), new Tuple2<>(2, 'd'), new Tuple2<>(2, 'e'), new Tuple2<>(3, 'f'));

    JavaPairRDD<Integer, Character> data = jsc.parallelizePairs(list);

    // specify the exact fraction desired from each key Map<K, Double>
    ImmutableMap<Integer, Double> fractions = ImmutableMap.of(1, 0.1, 2, 0.6, 3, 0.3);

    // Get an approximate sample from each stratum
    JavaPairRDD<Integer, Character> approxSample = data.sampleByKey(false, fractions);
    // Get an exact sample from each stratum
    JavaPairRDD<Integer, Character> exactSample = data.sampleByKeyExact(false, fractions);
    // $example off$

    System.out.println("approxSample size is " + approxSample.collect().size());
    for (Tuple2<Integer, Character> t : approxSample.collect()) {
        System.out.println(t._1() + " " + t._2());
    }//from www .  j  a  v a  2  s .  co  m

    System.out.println("exactSample size is " + exactSample.collect().size());
    for (Tuple2<Integer, Character> t : exactSample.collect()) {
        System.out.println(t._1() + " " + t._2());
    }

    jsc.stop();
}

From source file:dbx.compute.spark.jobs.mllib.JavaStratifiedSamplingExample.java

public static void main(String[] args) {

    SparkConf conf = new SparkConf().setAppName("JavaStratifiedSamplingExample");
    JavaSparkContext jsc = new JavaSparkContext(conf);

    @SuppressWarnings("unchecked")
    // $example on$
    List<Tuple2<Integer, Character>> list = Arrays.asList(new Tuple2<Integer, Character>(1, 'a'),
            new Tuple2<Integer, Character>(1, 'b'), new Tuple2<Integer, Character>(2, 'c'),
            new Tuple2<Integer, Character>(2, 'd'), new Tuple2<Integer, Character>(2, 'e'),
            new Tuple2<Integer, Character>(3, 'f'));

    JavaPairRDD<Integer, Character> data = jsc.parallelizePairs(list);

    // specify the exact fraction desired from each key Map<K, Double>
    ImmutableMap<Integer, Double> fractions = ImmutableMap.of(1, 0.1, 2, 0.6, 3, 0.3);

    // Get an approximate sample from each stratum
    JavaPairRDD<Integer, Character> approxSample = data.sampleByKey(false, fractions);
    // Get an exact sample from each stratum
    JavaPairRDD<Integer, Character> exactSample = data.sampleByKeyExact(false, fractions);
    // $example off$

    System.out.println("approxSample size is " + approxSample.collect().size());
    for (Tuple2<Integer, Character> t : approxSample.collect()) {
        System.out.println(t._1() + " " + t._2());
    }//from   w  w  w  .  jav  a 2  s . c o m

    System.out.println("exactSample size is " + exactSample.collect().size());
    for (Tuple2<Integer, Character> t : exactSample.collect()) {
        System.out.println(t._1() + " " + t._2());
    }

    jsc.stop();
}

From source file:google.registry.rdap.RdapTestHelper.java

static void addTermsOfServiceNotice(ImmutableMap.Builder<String, Object> builder, String linkBase) {
    builder.put("notices",
            ImmutableList.of(ImmutableMap.of("title", "RDAP Terms of Service", "description",
                    ImmutableList.of(/*  w w  w . j av a2 s  .com*/
                            "By querying our Domain Database, you are agreeing to comply with these terms"
                                    + " so please read them carefully.",
                            "Any information provided is 'as is' without any guarantee of accuracy.",
                            "Please do not misuse the Domain Database. It is intended solely for"
                                    + " query-based access.",
                            "Don't use the Domain Database to allow, enable, or otherwise support the"
                                    + " transmission of mass unsolicited, commercial advertising or"
                                    + " solicitations.",
                            "Don't access our Domain Database through the use of high volume, automated"
                                    + " electronic processes that send queries or data to the systems of any"
                                    + " ICANN-accredited registrar.",
                            "You may only use the information contained in the Domain Database for lawful"
                                    + " purposes.",
                            "Do not compile, repackage, disseminate, or otherwise use the information"
                                    + " contained in the Domain Database in its entirety, or in any substantial"
                                    + " portion, without our prior written permission.",
                            "We may retain certain details about queries to our Domain Database for the"
                                    + " purposes of detecting and preventing misuse.",
                            "We reserve the right to restrict or deny your access to the database if we"
                                    + " suspect that you have failed to comply with these terms.",
                            "We reserve the right to modify this agreement at any time."),
                    "links",
                    ImmutableList.of(ImmutableMap.of("value", linkBase + "help/tos", "rel", "alternate", "href",
                            "https://www.registry.tld/about/rdap/tos.html", "type", "text/html")))));
}

From source file:io.v.impl.google.namespace.NamespaceTestUtil.java

/**
 * Starts a new test mount server and attaches it to a new context derived from the
 * provided context./*  ww  w.ja  v  a2  s  . c  o m*/
 */
public static VContext withTestMountServer(VContext ctx) throws Exception {
    ctx = V.withListenSpec(ctx, V.getListenSpec(ctx).withAddress(new ListenSpec.Address("tcp", "localhost:0")));
    AccessList acl = new AccessList(ImmutableList.of(new BlessingPattern("...")), ImmutableList.<String>of());
    Permissions allowAll = new Permissions(ImmutableMap.of(Constants.READ.getValue(), acl,
            Constants.WRITE.getValue(), acl, Constants.ADMIN.getValue(), acl));
    ctx = MountTableServer.withNewServer(ctx, new MountTableServer.Params()
            .withPermissions(ImmutableMap.of("test", allowAll)).withStatsPrefix("test"));
    Namespace n = V.getNamespace(ctx);
    n.setRoots(ImmutableList.of(V23TestUtil.getServerEndpoint(ctx).name()));
    return ctx;
}

From source file:org.openqa.selenium.logging.profiler.HttpProfilerLogEntry.java

private static String constructMessage(EventType eventType, String commandName, boolean isStart) {
    Map<String, ?> map = ImmutableMap.of("event", eventType.toString(), "command", commandName, "startorend",
            isStart ? "start" : "end");
    return new Gson().toJson(map);
}

From source file:co.cask.cdap.common.metrics.MetricsTags.java

public static Map<String, String> service(Id.Program id) {
    return ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, id.getNamespaceId(), Constants.Metrics.Tag.APP,
            id.getApplicationId(), Constants.Metrics.Tag.SERVICE, id.getId());
}

From source file:co.cask.cdap.common.metrics.MetricsContexts.java

public static Map<String, String> forService(Id.Program id) {
    return ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, id.getNamespaceId(), Constants.Metrics.Tag.APP,
            id.getApplicationId(), Constants.Metrics.Tag.SERVICE, id.getId());
}

From source file:org.prebake.service.bake.JsOperatingSystemEnv.java

private static ImmutableMap<String, ?> stubProcess(final Integer result, final String model) {
    return ImmutableMap.of("help_",
            ("A process that mimics the UNIX " + model + " command by" + " yielding " + result
                    + " without consuming any input or" + " producing any output."),
            "run", new SimpleMembranableMethod("Returns the process so that calls can be chained", "run",
                    "a process object") {
                public Object apply(Object[] args) {
                    return args[0];
                }/*from  ww  w .j av  a 2s.  co m*/
            }, "waitFor",
            new SimpleMembranableMethod("Returns " + result + " without delay", "run", "a process object") {
                public Object apply(Object[] args) {
                    return result;
                }
            });
}

From source file:com.github.jcustenborder.kafka.connect.cdc.Change.java

static Map<String, Object> sourcePartition(Change change) {
    Preconditions.checkNotNull(change, "change cannot be null.");
    return ImmutableMap.of(Constants.DATABASE_NAME_VARIABLE, change.databaseName(),
            Constants.SCHEMA_NAME_VARIABLE, change.schemaName(), Constants.TABLE_NAME_VARIABLE,
            change.tableName());//from w w  w . jav a  2 s  . c  om
}

From source file:org.caleydo.core.internal.cmd.ZoomHandlerParameters.java

@Override
public Map<?, ?> getParameterValues() {
    return ImmutableMap.of("Zoom In", "zoomIn", "Zoom Out", "zoomOut", "Reset Zoom", "reset");
}