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

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

Introduction

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

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Usage

From source file:org.apache.eagle.alert.engine.UnitSparkUnionTopologyMain.java

public static void main(String[] args) throws InterruptedException {

    Config config;//from w w  w  . j  a  v  a2  s  . c  om
    if (args != null && args.length == 15) {
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        ImmutableMap<String, String> argsMap = builder.put(BATCH_DURATION, args[0])
                .put(ROUTER_TASK_NUM, args[1]).put(ALERT_TASK_NUM, args[2]).put(PUBLISH_TASK_NUM, args[3])
                .put(SLIDE_DURATION_SECOND, args[4]).put(WINDOW_DURATIONS_SECOND, args[5])
                .put(CHECKPOINT_PATH, args[6]).put(TOPOLOGY_GROUPID, args[7]).put(AUTO_OFFSET_RESET, args[8])
                .put(EAGLE_CORRELATION_CONTEXT, args[9]).put(EAGLE_CORRELATION_SERVICE_PORT, args[10])
                .put(EAGLE_CORRELATION_SERVICE_HOST, args[11]).put(TOPOLOGY_MULTIKAFKA, args[12])
                .put(SPOUT_KAFKABROKERZKQUORUM, args[13]).put(ZKCONFIG_ZKQUORUM, args[14]).build();
        config = ConfigFactory.parseMap(argsMap);
    } else {
        config = ConfigFactory.load();
    }
    boolean useMultiKafka = config.getBoolean(TOPOLOGY_MULTIKAFKA);
    if (useMultiKafka) {
        new UnitSparkUnionTopologyRunner(config).run();
    } else {
        new UnitSparkTopologyRunner(config).run();
    }

}

From source file:com.google.devtools.build.skydoc.SkydocMain.java

public static void main(String[] args) throws IOException, InterruptedException {
    if (args.length != 2) {
        throw new IllegalArgumentException(
                "Expected two arguments. Usage:\n" + "{skydoc_bin} {target_skylark_file} {output_file}");
    }//ww w.ja v  a2 s  .c  om

    String bzlPath = args[0];
    String outputPath = args[1];

    Path path = Paths.get(bzlPath);
    byte[] content = Files.readAllBytes(path);

    ParserInputSource parserInputSource = ParserInputSource.create(content,
            PathFragment.create(path.toString()));

    ImmutableMap.Builder<String, RuleInfo> ruleInfoMap = ImmutableMap.builder();
    ImmutableList.Builder<RuleInfo> unexportedRuleInfos = ImmutableList.builder();

    new SkydocMain().eval(parserInputSource, ruleInfoMap, unexportedRuleInfos);

    try (PrintWriter printWriter = new PrintWriter(outputPath, "UTF-8")) {
        printRuleInfos(printWriter, ruleInfoMap.build(), unexportedRuleInfos.build());
    }
}

From source file:org.phunt.blur.shell.Main.java

public static void main(String[] args) throws Throwable {
    commands = new ImmutableMap.Builder<String, Command>().put("help", new HelpCommand())
            .put("debug", new DebugCommand()).put("timed", new TimedCommand()).put("quit", new QuitCommand())
            .put("listtables", new ListTablesCommand()).put("createtable", new CreateTableCommand())
            .put("enabletable", new EnableDisableTableCommand())
            .put("disabletable", new EnableDisableTableCommand()).put("removetable", new RemoveTableCommand())
            .put("describetable", new DescribeTableCommand()).put("tablestats", new TableStatsCommand())
            .put("schema", new SchemaTableCommand()).put("query", new QueryCommand())
            .put("getrow", new GetRowCommand()).put("mutaterow", new MutateRowCommand())
            .put("indexaccesslog", new IndexAccessLogCommand())
            .put("shardclusterlist", new ShardClusterListCommand())
            .put("shardserverlayout", new ShardServerLayoutCommand()).build();

    try {/*from   ww  w .ja v  a 2 s . c o m*/
        ConsoleReader reader = new ConsoleReader();

        reader.setPrompt("blur> ");

        if ((args == null) || (args.length != 1)) {
            usage();
            return;
        }

        String[] hostport = args[0].split(":");

        if (hostport.length != 2) {
            usage();
            return;
        }

        List<Completer> completors = new LinkedList<Completer>();

        completors.add(new StringsCompleter(commands.keySet()));
        completors.add(new FileNameCompleter());

        for (Completer c : completors) {
            reader.addCompleter(c);
        }

        TTransport trans = new TSocket(hostport[0], Integer.parseInt(hostport[1]));
        TProtocol proto = new TBinaryProtocol(new TFramedTransport(trans));
        Client client = new Client(proto);
        try {
            trans.open();

            String line;
            PrintWriter out = new PrintWriter(reader.getOutput());
            try {
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    // ignore empty lines and comments
                    if (line.length() == 0 || line.startsWith("#")) {
                        continue;
                    }
                    String[] commandArgs = line.split("\\s");
                    Command command = commands.get(commandArgs[0]);
                    if (command == null) {
                        out.println("unknown command \"" + commandArgs[0] + "\"");
                    } else {
                        long start = System.nanoTime();
                        try {
                            command.doit(out, client, commandArgs);
                        } catch (QuitCommandException e) {
                            // exit gracefully
                            System.exit(0);
                        } catch (CommandException e) {
                            out.println(e.getMessage());
                            if (debug) {
                                e.printStackTrace(out);
                            }
                        } catch (BlurException e) {
                            out.println(e.getMessage());
                            if (debug) {
                                e.printStackTrace(out);
                            }
                        } finally {
                            if (timed) {
                                out.println("Last command took "
                                        + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) + "ms");
                            }
                        }
                    }
                }
            } finally {
                out.close();
            }
        } finally {
            trans.close();
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    }
}

From source file:com.google.devtools.build.android.ManifestMergerAction.java

public static void main(String[] args) throws Exception {
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
    optionsParser.parseAndExitUponError(args);
    options = optionsParser.getOptions(Options.class);

    final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(stdLogger);

    try {//from   ww w .j  a v a 2s  .com
        Path mergedManifest;
        if (options.mergeType == MergeType.APPLICATION) {
            // Remove uses-permission tags from mergees before the merge.
            Path tmp = Files.createTempDirectory("manifest_merge_tmp");
            tmp.toFile().deleteOnExit();
            ImmutableMap.Builder<Path, String> mergeeManifests = ImmutableMap.builder();
            for (Entry<Path, String> mergeeManifest : options.mergeeManifests.entrySet()) {
                mergeeManifests.put(removePermissions(mergeeManifest.getKey(), tmp), mergeeManifest.getValue());
            }

            // Ignore custom package at the binary level.
            mergedManifest = resourceProcessor.mergeManifest(options.manifest, mergeeManifests.build(),
                    options.mergeType, options.manifestValues, options.manifestOutput, options.log);
        } else {
            // Only need to stamp custom package into the library level.
            mergedManifest = resourceProcessor.writeManifestPackage(options.manifest, options.customPackage,
                    options.manifestOutput);
        }

        if (!mergedManifest.equals(options.manifestOutput)) {
            Files.copy(options.manifest, options.manifestOutput, StandardCopyOption.REPLACE_EXISTING);
        }

        // Set to the epoch for caching purposes.
        Files.setLastModifiedTime(options.manifestOutput, FileTime.fromMillis(0L));
    } catch (IOException e) {
        logger.log(SEVERE, "Error during merging manifests", e);
        throw e;
    } finally {
        resourceProcessor.shutdown();
    }
}

From source file:com.google.devtools.build.android.ZipFilterAction.java

public static void main(String[] args) throws IOException {
    Options options = new Options();
    new JCommander(options).parse(args);
    logger.fine(String.format("Creating filter from entries of type %s, in zip files %s.", options.filterTypes,
            options.filterZips));/*from   w w  w  .  ja v a  2s.  c om*/

    final Stopwatch timer = Stopwatch.createStarted();
    final Multimap<String, Long> entriesToOmit = getEntriesToOmit(options.filterZips, options.filterTypes);
    final String explicitFilter = options.explicitFilters.isEmpty() ? ""
            : String.format(".*(%s).*", Joiner.on("|").join(options.explicitFilters));
    logger.fine(String.format("Filter created in %dms", timer.elapsed(TimeUnit.MILLISECONDS)));

    ImmutableMap.Builder<String, Long> inputEntries = ImmutableMap.builder();
    try (ZipReader input = new ZipReader(options.inputZip.toFile())) {
        for (ZipFileEntry entry : input.entries()) {
            inputEntries.put(entry.getName(), entry.getCrc());
        }
    }
    ZipEntryFilter entryFilter = new ZipFilterEntryFilter(explicitFilter, entriesToOmit, inputEntries.build(),
            options.errorOnHashMismatch);

    try (OutputStream out = Files.newOutputStream(options.outputZip);
            ZipCombiner combiner = new ZipCombiner(options.outputMode, entryFilter, out)) {
        combiner.addZip(options.inputZip.toFile());
    }
    logger.fine(String.format("Filtering completed in %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
}

From source file:org.quickgeo.generate.Downloader.java

public static final ImmutableMap<String, File> download(Dataset dataset) {

    ImmutableMap.Builder<String, File> builder = new ImmutableMap.Builder<String, File>();

    for (String artifact : dataset.getArtifacts()) {
        try {/* www.ja  va 2 s. c o m*/
            String cc = artifact.replaceAll(REPLACE_ARTIFACT, "").toUpperCase();
            String url = URL_STRING.replaceAll(";cc;", cc);

            File tempFile = File.createTempFile("geo-" + cc + System.currentTimeMillis(), null);
            FileUtils.copyURLToFile(new URL(url), tempFile);
            builder.put(cc, tempFile);

            Settings.getSettings().getLogger().log(Level.INFO, "Downloaded file from {0} to {1}",
                    new Object[] { url, tempFile.getPath() });

        } catch (Exception ex) {
            Settings.getSettings().getLogger().log(Level.WARNING, "Couldn't fetch artifact", ex);
        }
    }

    return builder.build();
}

From source file:com.google.javascript.jscomp.TagNameToType.java

static Map<String, String> getMap() {
    return new ImmutableMap.Builder<String, String>().put("a", "HTMLAnchorElement")
            .put("area", "HTMLAreaElement").put("audio", "HTMLAudioElement").put("base", "HTMLBaseElement")
            .put("body", "HTMLBodyElement").put("br", "HTMLBRElement").put("button", "HTMLButtonElement")
            .put("canvas", "HTMLCanvasElement").put("caption", "HTMLTableCaptionElement")
            .put("col", "HTMLTableColElement").put("content", "HTMLContentElement")
            .put("data", "HTMLDataElement").put("datalist", "HTMLDataListElement").put("del", "HTMLModElement")
            .put("dir", "HTMLDirectoryElement").put("div", "HTMLDivElement").put("dl", "HTMLDListElement")
            .put("embed", "HTMLEmbedElement").put("fieldset", "HTMLFieldSetElement")
            .put("font", "HTMLFontElement").put("form", "HTMLFormElement").put("frame", "HTMLFrameElement")
            .put("frameset", "HTMLFrameSetElement").put("h1", "HTMLHeadingElement")
            .put("head", "HTMLHeadElement").put("hr", "HTMLHRElement").put("html", "HTMLHtmlElement")
            .put("iframe", "HTMLIFrameElement").put("img", "HTMLImageElement").put("input", "HTMLInputElement")
            .put("keygen", "HTMLKeygenElement").put("label", "HTMLLabelElement")
            .put("legend", "HTMLLegendElement").put("li", "HTMLLIElement").put("link", "HTMLLinkElement")
            .put("map", "HTMLMapElement").put("marquee", "HTMLMarqueeElement").put("menu", "HTMLMenuElement")
            .put("menuitem", "HTMLMenuItemElement").put("meta", "HTMLMetaElement")
            .put("meter", "HTMLMeterElement").put("object", "HTMLObjectElement").put("ol", "HTMLOListElement")
            .put("optgroup", "HTMLOptGroupElement").put("option", "HTMLOptionElement")
            .put("output", "HTMLOutputElement").put("p", "HTMLParagraphElement")
            .put("param", "HTMLParamElement").put("pre", "HTMLPreElement")
            .put("progress", "HTMLProgressElement").put("q", "HTMLQuoteElement")
            .put("script", "HTMLScriptElement").put("select", "HTMLSelectElement")
            .put("shadow", "HTMLShadowElement").put("source", "HTMLSourceElement")
            .put("span", "HTMLSpanElement").put("style", "HTMLStyleElement").put("table", "HTMLTableElement")
            .put("tbody", "HTMLTableSectionElement").put("template", "HTMLTemplateElement")
            .put("textarea", "HTMLTextAreaElement").put("thead", "HTMLTableSectionElement")
            .put("time", "HTMLTimeElement").put("title", "HTMLTitleElement").put("tr", "HTMLTableRowElement")
            .put("track", "HTMLTrackElement").put("ul", "HTMLUListElement").put("video", "HTMLVideoElement")
            .build();//from w w  w.ja v  a  2s.c o m
}

From source file:org.codice.ddf.admin.application.service.migratable.JsonSupport.java

public static Map<String, Object> toImmutableMap(Object... keysAndValues) {
    final ImmutableMap.Builder builder = ImmutableMap.builder();

    for (int i = 0; i < keysAndValues.length; i += 2) {
        builder.put(keysAndValues[i], keysAndValues[i + 1]);
    }/*  w ww  . ja  v a 2 s  .c o  m*/
    return builder.build();
}

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(/*from www.  j av  a2 s  .c  o  m*/
                            "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:com.googlecode.wmbutil.util.ElementUtil.java

public static ImmutableMap<String, Object> asImmutableMap(MbElement parent) throws MbException {
    MbElement child = parent.getFirstChild();

    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    while (child != null) {
        if (child.getType() == MbElement.TYPE_NAME_VALUE) {
            builder.put(child.getName(), child.getValue());
        }//  ww  w. jav a 2 s  .  c o  m
        child = child.getNextSibling();
    }
    return builder.build();
}