Example usage for com.google.common.collect Maps newHashMap

List of usage examples for com.google.common.collect Maps newHashMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newHashMap.

Prototype

public static <K, V> HashMap<K, V> newHashMap() 

Source Link

Document

Creates a mutable, empty HashMap instance.

Usage

From source file:org.apache.ctakes.temporal.eval.EvaluationOfTimeSpans.java

public static void main(String[] args) throws Exception {
    Options options = CliFactory.parseArguments(Options.class, args);
    List<Integer> trainItems = null;
    List<Integer> devItems = null;
    List<Integer> testItems = null;

    List<Integer> patientSets = options.getPatients().getList();
    if (options.getXMLFormat() == XMLFormat.I2B2) {
        trainItems = I2B2Data.getTrainPatientSets(options.getXMLDirectory());
        devItems = I2B2Data.getDevPatientSets(options.getXMLDirectory());
        testItems = I2B2Data.getTestPatientSets(options.getXMLDirectory());
    } else {/*  w  w  w. java2 s . c  o m*/
        trainItems = THYMEData.getPatientSets(patientSets, options.getTrainRemainders().getList());
        devItems = THYMEData.getPatientSets(patientSets, options.getDevRemainders().getList());
        testItems = THYMEData.getPatientSets(patientSets, options.getTestRemainders().getList());
    }

    List<Integer> allTrain = new ArrayList<>(trainItems);
    List<Integer> allTest = null;

    if (options.getTest()) {
        allTrain.addAll(devItems);
        allTest = new ArrayList<>(testItems);
    } else {
        allTest = new ArrayList<>(devItems);
    }

    // specify the annotator classes to use
    List<Class<? extends JCasAnnotator_ImplBase>> annotatorClasses = Lists.newArrayList();
    if (options.getRunBackwards())
        annotatorClasses.add(BackwardsTimeAnnotator.class);
    if (options.getRunForwards())
        annotatorClasses.add(TimeAnnotator.class);
    if (options.getRunParserBased())
        annotatorClasses.add(ConstituencyBasedTimeAnnotator.class);
    if (options.getRunCrfBased())
        annotatorClasses.add(CRFTimeAnnotator.class);
    if (annotatorClasses.size() == 0) {
        // run all
        annotatorClasses.add(BackwardsTimeAnnotator.class);
        annotatorClasses.add(TimeAnnotator.class);
        annotatorClasses.add(ConstituencyBasedTimeAnnotator.class);
        annotatorClasses.add(CRFTimeAnnotator.class);
    }
    Map<Class<? extends JCasAnnotator_ImplBase>, String[]> annotatorTrainingArguments = Maps.newHashMap();

    // THYME best params: Backwards: 0.1, CRF 0.3, Time 0.1, Constituency 0.3
    // i2b2 best params: Backwards 0.1, CRF 3.0, Time 0.1, Constituency 0.3
    //      String gridParam = "0.01";
    annotatorTrainingArguments.put(BackwardsTimeAnnotator.class, new String[] { "-c", "0.1" });
    annotatorTrainingArguments.put(TimeAnnotator.class, new String[] { "-c", "0.1" });
    annotatorTrainingArguments.put(ConstituencyBasedTimeAnnotator.class, new String[] { "-c", "0.3" });
    annotatorTrainingArguments.put(CRFTimeAnnotator.class, new String[] { "-p", "c2=" + "0.3" });

    // run one evaluation per annotator class
    final Map<Class<?>, AnnotationStatistics<?>> annotatorStats = Maps.newHashMap();
    for (Class<? extends JCasAnnotator_ImplBase> annotatorClass : annotatorClasses) {
        EvaluationOfTimeSpans evaluation = new EvaluationOfTimeSpans(new File("target/eval/time-spans"),
                options.getRawTextDirectory(), options.getXMLDirectory(), options.getXMLFormat(),
                options.getSubcorpus(), options.getXMIDirectory(), options.getTreebankDirectory(),
                options.getFeatureSelectionThreshold(), options.getSMOTENeighborNumber(), annotatorClass,
                options.getPrintOverlappingSpans(), annotatorTrainingArguments.get(annotatorClass));
        evaluation.prepareXMIsFor(patientSets);
        evaluation.setSkipTrain(options.getSkipTrain());
        evaluation.printErrors = options.getPrintErrors();
        if (options.getI2B2Output() != null)
            evaluation.setI2B2Output(options.getI2B2Output() + "/" + annotatorClass.getSimpleName());
        String name = String.format("%s.errors", annotatorClass.getSimpleName());
        evaluation.setLogging(Level.FINE, new File("target/eval", name));
        AnnotationStatistics<String> stats = evaluation.trainAndTest(allTrain, allTest);
        annotatorStats.put(annotatorClass, stats);
    }

    // allow ordering of models by F1
    Ordering<Class<? extends JCasAnnotator_ImplBase>> byF1 = Ordering.natural()
            .onResultOf(new Function<Class<? extends JCasAnnotator_ImplBase>, Double>() {
                @Override
                public Double apply(Class<? extends JCasAnnotator_ImplBase> annotatorClass) {
                    return annotatorStats.get(annotatorClass).f1();
                }
            });

    // print out models, ordered by F1
    for (Class<?> annotatorClass : byF1.sortedCopy(annotatorClasses)) {
        System.err.printf("===== %s =====\n", annotatorClass.getSimpleName());
        System.err.println(annotatorStats.get(annotatorClass));
    }
}

From source file:com.manydesigns.portofino.utils.JsonMapper.java

/**
 * /*ww w. j a v  a2  s  . c o  m*/
 */
public static void main(String[] args) {
    // 
    List<String> months = Lists.newArrayList();
    for (int t_i = 1; t_i <= 12; t_i++) {
        months.add(t_i + "");
    }
    String json = JsonMapper.getInstance().toJson(months);
    System.out.println(json);

    List<Map<String, Object>> list = Lists.newArrayList();
    Map<String, Object> map = Maps.newHashMap();
    map.put("id", 1);
    map.put("pId", -1);
    map.put("name", "");
    list.add(map);
    map = Maps.newHashMap();
    map.put("id", 2);
    map.put("pId", 1);
    map.put("name", "");
    map.put("open", true);
    list.add(map);
    json = JsonMapper.getInstance().toJson(list);
    System.out.println(json);
}

From source file:com.coul.common.mapper.JsonMapper.java

/**
 * /*from w w  w . ja  v a  2  s. co m*/
 */
public static void main(String[] args) {
    List<Map<String, Object>> list = Lists.newArrayList();
    Map<String, Object> map = Maps.newHashMap();
    map.put("id", 1);
    map.put("pId", -1);
    map.put("name", "");
    list.add(map);
    map = Maps.newHashMap();
    map.put("id", 2);
    map.put("pId", 1);
    map.put("name", "");
    map.put("open", true);
    list.add(map);
    String json = JsonMapper.getInstance().toJson(list);
    System.out.println(json);
}

From source file:org.sbs.goodcrawler.extractor.selector.IFConditions.java

public static void main(String[] args) {
    //      String exp = "a= sd ea and  c= c bc d  and c=e and x=y";
    //      // w  ww .j a  va 2 s.  c  o m
    //      IFConditions ic = new IFConditions(exp);
    //      try {
    //         Map<String, Object> map = Maps.newHashMap();
    //         map.put("a", "sd");
    //         map.put("c", "c bc d");
    ////         map.put("x", "y");
    //         System.out.println(ic.test(map));
    //      } catch (Exception e) {
    //         e.printStackTrace();
    //      }

    String exp = "category= or category=";
    IFConditions ic = new IFConditions(exp);
    try {
        Map<String, Object> map = Maps.newHashMap();
        map.put("category", "");
        System.out.println(ic.test(map));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.appdynamics.extensions.elasticsearch.ElasticSearchQueryMonitor.java

public static void main(String[] args) throws TaskExecutionException {
    Map<String, String> taskArgs = Maps.newHashMap();
    taskArgs.put("config-file",
            "/home/balakrishnav/AppDynamics/ExtensionsProject/elasticsearch-query-monitoring-extension/src/main/resources/conf/config.yml");
    ElasticSearchQueryMonitor esMonitor = new ElasticSearchQueryMonitor();
    esMonitor.execute(taskArgs, null);//from   w w  w.  j a  v a2s .  c  o  m
}

From source file:com.flaptor.indextank.rpc.IndexerClient.java

public static void main(String[] args) {
    IndexerClient client = new IndexerClient("localhost", 7911);

    Map<String, String> fields = Maps.newHashMap();
    fields.put("mono", "lete");
    fields.put("ignacio", "perez");
    fields.put("santi", "miente");
    fields.put("jorge", "grumpy");
    fields.put("spike", "sweet");

    String extra = "";
    if (args.length > 1) {
        fields.put(args[0], args[1]);/* w ww . j  av  a  2s  .c  o m*/
        extra = args[0] + " " + args[1];
    }

    fields.put("todo", "mono lete ignacio perez santi miente jorge grumpy spike y sweet " + extra);
    com.flaptor.indextank.index.Document doc = new com.flaptor.indextank.index.Document(fields);
    client.add("prueba", doc, (int) (System.currentTimeMillis() / 1000), Maps.<Integer, Double>newHashMap());
}

From source file:org.apache.jackrabbit.oak.scalability.ScalabilityRunner.java

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSpec<File> base = parser.accepts("base", "Base directory").withRequiredArg().ofType(File.class)
            .defaultsTo(new File("target"));
    OptionSpec<String> host = parser.accepts("host", "MongoDB host").withRequiredArg().defaultsTo("localhost");
    OptionSpec<Integer> port = parser.accepts("port", "MongoDB port").withRequiredArg().ofType(Integer.class)
            .defaultsTo(27017);//  w  w  w . j ava 2  s. com
    OptionSpec<String> dbName = parser.accepts("db", "MongoDB database").withRequiredArg();
    OptionSpec<Boolean> dropDBAfterTest = parser
            .accepts("dropDBAfterTest", "Whether to drop the MongoDB database after the test").withOptionalArg()
            .ofType(Boolean.class).defaultsTo(true);
    OptionSpec<String> rdbjdbcuri = parser.accepts("rdbjdbcuri", "RDB JDBC URI").withOptionalArg()
            .defaultsTo("jdbc:h2:./target/benchmark");
    OptionSpec<String> rdbjdbcuser = parser.accepts("rdbjdbcuser", "RDB JDBC user").withOptionalArg()
            .defaultsTo("");
    OptionSpec<String> rdbjdbcpasswd = parser.accepts("rdbjdbcpasswd", "RDB JDBC password").withOptionalArg()
            .defaultsTo("");
    OptionSpec<String> rdbjdbctableprefix = parser.accepts("rdbjdbctableprefix", "RDB JDBC table prefix")
            .withOptionalArg().defaultsTo("");
    OptionSpec<Boolean> mmap = parser.accepts("mmap", "TarMK memory mapping").withOptionalArg()
            .ofType(Boolean.class).defaultsTo("64".equals(System.getProperty("sun.arch.data.model")));
    OptionSpec<Integer> cache = parser.accepts("cache", "cache size (MB)").withRequiredArg()
            .ofType(Integer.class).defaultsTo(100);
    OptionSpec<Integer> fdsCache = parser.accepts("blobCache", "cache size (MB)").withRequiredArg()
            .ofType(Integer.class).defaultsTo(32);
    OptionSpec<Boolean> withStorage = parser.accepts("storage", "Index storage enabled").withOptionalArg()
            .ofType(Boolean.class);
    OptionSpec<File> csvFile = parser.accepts("csvFile", "File to write a CSV version of the benchmark data.")
            .withOptionalArg().ofType(File.class);
    OptionSpec help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
    OptionSpec<String> nonOption = parser.nonOptions();

    OptionSet options = parser.parse(args);

    if (options.has(help)) {
        parser.printHelpOn(System.out);
        System.exit(0);
    }

    int cacheSize = cache.value(options);
    RepositoryFixture[] allFixtures = new RepositoryFixture[] {
            new JackrabbitRepositoryFixture(base.value(options), cacheSize),
            OakRepositoryFixture.getMemoryNS(cacheSize * MB),
            OakRepositoryFixture.getMongo(host.value(options), port.value(options), dbName.value(options),
                    dropDBAfterTest.value(options), cacheSize * MB),
            OakRepositoryFixture.getMongoWithFDS(host.value(options), port.value(options),
                    dbName.value(options), dropDBAfterTest.value(options), cacheSize * MB, base.value(options),
                    fdsCache.value(options)),
            OakRepositoryFixture.getMongoNS(host.value(options), port.value(options), dbName.value(options),
                    dropDBAfterTest.value(options), cacheSize * MB),
            OakRepositoryFixture.getTar(base.value(options), 256, cacheSize, mmap.value(options)),
            OakRepositoryFixture.getTarWithBlobStore(base.value(options), 256, cacheSize, mmap.value(options)),
            OakRepositoryFixture.getSegmentTar(base.value(options), 256, cacheSize, mmap.value(options)),
            OakRepositoryFixture.getSegmentTarWithBlobStore(base.value(options), 256, cacheSize,
                    mmap.value(options)),
            OakRepositoryFixture.getRDB(rdbjdbcuri.value(options), rdbjdbcuser.value(options),
                    rdbjdbcpasswd.value(options), rdbjdbctableprefix.value(options),
                    dropDBAfterTest.value(options), cacheSize * MB),
            OakRepositoryFixture.getRDBWithFDS(rdbjdbcuri.value(options), rdbjdbcuser.value(options),
                    rdbjdbcpasswd.value(options), rdbjdbctableprefix.value(options),
                    dropDBAfterTest.value(options), cacheSize * MB, base.value(options),
                    fdsCache.value(options)) };
    ScalabilitySuite[] allSuites = new ScalabilitySuite[] {
            new ScalabilityBlobSearchSuite(withStorage.value(options)).addBenchmarks(new FullTextSearcher(),
                    new NodeTypeSearcher(), new FormatSearcher(), new FacetSearcher(),
                    new LastModifiedSearcher(Date.LAST_2_HRS), new LastModifiedSearcher(Date.LAST_24_HRS),
                    new LastModifiedSearcher(Date.LAST_7_DAYS), new LastModifiedSearcher(Date.LAST_MONTH),
                    new LastModifiedSearcher(Date.LAST_YEAR), new OrderByDate()),
            new ScalabilityNodeSuite(withStorage.value(options)).addBenchmarks(new OrderBySearcher(),
                    new SplitOrderBySearcher(), new OrderByOffsetPageSearcher(),
                    new SplitOrderByOffsetPageSearcher(), new OrderByKeysetPageSearcher(),
                    new SplitOrderByKeysetPageSearcher(), new MultiFilterOrderBySearcher(),
                    new MultiFilterSplitOrderBySearcher(), new MultiFilterOrderByOffsetPageSearcher(),
                    new MultiFilterSplitOrderByOffsetPageSearcher(), new MultiFilterOrderByKeysetPageSearcher(),
                    new MultiFilterSplitOrderByKeysetPageSearcher(), new ConcurrentReader(),
                    new ConcurrentWriter()),
            new ScalabilityNodeRelationshipSuite(withStorage.value(options))
                    .addBenchmarks(new AggregateNodeSearcher()) };

    Set<String> argset = Sets.newHashSet(nonOption.values(options));
    List<RepositoryFixture> fixtures = Lists.newArrayList();
    for (RepositoryFixture fixture : allFixtures) {
        if (argset.remove(fixture.toString())) {
            fixtures.add(fixture);
        }
    }

    Map<String, List<String>> argmap = Maps.newHashMap();
    // Split the args to get suites and benchmarks (i.e. suite:benchmark1,benchmark2)
    for (String arg : argset) {
        List<String> tokens = Splitter.on(":").limit(2).splitToList(arg);
        if (tokens.size() > 1) {
            argmap.put(tokens.get(0), Splitter.on(",").trimResults().splitToList(tokens.get(1)));
        } else {
            argmap.put(tokens.get(0), null);
        }
        argset.remove(arg);
    }

    if (argmap.isEmpty()) {
        System.err.println(
                "Warning: no scalability suites specified, " + "supported  are: " + Arrays.asList(allSuites));
    }

    List<ScalabilitySuite> suites = Lists.newArrayList();
    for (ScalabilitySuite suite : allSuites) {
        if (argmap.containsKey(suite.toString())) {
            List<String> benchmarks = argmap.get(suite.toString());
            // Only keep requested benchmarks
            if (benchmarks != null) {
                Iterator<String> iter = suite.getBenchmarks().keySet().iterator();
                for (; iter.hasNext();) {
                    String availBenchmark = iter.next();
                    if (!benchmarks.contains(availBenchmark)) {
                        iter.remove();
                    }
                }
            }
            suites.add(suite);
            argmap.remove(suite.toString());
        }
    }

    if (argmap.isEmpty()) {
        PrintStream out = null;
        if (options.has(csvFile)) {
            out = new PrintStream(FileUtils.openOutputStream(csvFile.value(options), true), false,
                    Charsets.UTF_8.name());
        }
        for (ScalabilitySuite suite : suites) {
            if (suite instanceof CSVResultGenerator) {
                ((CSVResultGenerator) suite).setPrintStream(out);
            }
            suite.run(fixtures);
        }
        if (out != null) {
            out.close();
        }
    } else {
        System.err.println("Unknown arguments: " + argset);
    }
}

From source file:samson.IOSTypes.java

/**
 * Creates a hash map copied from an iOS dictionary.
 *///  w w  w  .j  ava 2  s  .co m
public static Map<String, String> toMap(NSDictionary dict) {
    Map<String, String> result = Maps.newHashMap();
    for (NSObject key : dict.get_Keys()) {
        NSObject val = dict.ObjectForKey(key);
        if (val != null) {
            result.put(key.ToString(), val.ToString());
        }
    }
    return result;
}

From source file:org.geoserver.jdbcconfig.internal.DbUtils.java

public static Map<String, ?> params(Object... kv) {
    Map<String, Object> params = Maps.newHashMap();
    String paramName;//from   w ww.  j a v a2 s.  com
    Object paramValue;
    for (int i = 0; i < kv.length; i += 2) {
        paramName = (String) kv[i];
        paramValue = kv[i + 1];
        params.put(paramName, paramValue);
    }
    return params;
}

From source file:org.zht.framework.util.RequestUtil.java

public static String getRequestHeaders(HttpServletRequest request) {
    Map<String, List<String>> headers = Maps.newHashMap();
    Enumeration<String> namesEnumeration = request.getHeaderNames();
    while (namesEnumeration != null && namesEnumeration.hasMoreElements()) {
        String name = namesEnumeration.nextElement();
        Enumeration<String> valueEnumeration = request.getHeaders(name);
        List<String> values = Lists.newArrayList();
        while (valueEnumeration.hasMoreElements()) {
            values.add(valueEnumeration.nextElement());
        }//from  w  w w. j  ava2s  .c  o m
        headers.put(name, values);
    }
    return JSON.toJSONString(headers);
}