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:uk.ac.ed.inf.ace.ResultsAnalyser.java

public static boolean analyse(Engine<?, ?> engine, Programme programme) throws Exception {
    Map<String, List<Evaluator>> groups = Maps.newHashMap();

    for (Experiment experiment : programme.getExperiments()) {
        String groupName = experiment.getGroupName();
        List<Evaluator> evaluators = groups.get(groupName);
        File file = experiment.getConfusionMatrixFile();

        if (!file.exists()) {
            continue;
        }/*ww w.  j  a va 2s  . c o m*/

        if (evaluators == null) {
            evaluators = Lists.newArrayList();
            groups.put(groupName, evaluators);
        }

        evaluators.add(experiment.getTask().readEvaluator(experiment, file));
    }

    for (Entry<String, List<Evaluator>> entry : groups.entrySet()) {
        String groupName = entry.getKey();
        List<Evaluator> evaluators = entry.getValue();
        Experiment experiment = evaluators.get(0).getExperiment();
        Evaluator aggregateEvaluator = experiment.getTask().createEvaluator(experiment);

        for (Evaluator evaluator : evaluators) {
            for (Result result : evaluator) {
                aggregateEvaluator.add(result);
            }
        }

        aggregateEvaluator.output(
                new File(engine.getEnvironment().getOutputDirectory(), groupName + "-ConfusionMatrix.txt"));
        File resultsFile = engine.getEnvironment().getResultsFile();

        synchronized (resultsFile) {

            try (FileWriter fileWriter = new FileWriter(resultsFile, true)) {
                writeResult(fileWriter, groupName, "ACC", aggregateEvaluator.getAccuracy());
                writeResult(fileWriter, groupName, "PRE", aggregateEvaluator.getPrecision());
                writeResult(fileWriter, groupName, "REC", aggregateEvaluator.getRecall());
                writeResult(fileWriter, groupName, "FSC", aggregateEvaluator.getFScore());
                writeResult(fileWriter, groupName, "NPV", aggregateEvaluator.getNegativePredictiveValue());
                writeResult(fileWriter, groupName, "SPE", aggregateEvaluator.getSpecificity());
            }
        }
    }

    return true;
}

From source file:cn.imethan.common.mongodb.SearchFilter.java

/**
 * ??//from   w  ww  .j a va  2 s  . co  m
 * searchParamskey?OPERATOR_FIELDNAME
 * 
 * @param searchParams
 * @return
 *
 * @author Ethan Wong
 * @datetime 2015101?1:24:57
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (StringUtils.isBlank((String) value)) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = names[1];
        Operator operator = Operator.valueOf(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }
    return filters;
}

From source file:com.querydsl.jpa.support.DialectSupport.java

public static Map<String, SQLFunction> createFunctions(SQLTemplates templates) {
    Map<String, SQLFunction> functions = Maps.newHashMap();
    functions.put("second", createFunction(templates, Ops.DateTimeOps.SECOND));
    functions.put("minute", createFunction(templates, Ops.DateTimeOps.MINUTE));
    functions.put("hour", createFunction(templates, Ops.DateTimeOps.HOUR));
    functions.put("day", createFunction(templates, Ops.DateTimeOps.DAY_OF_MONTH));
    functions.put("week", createFunction(templates, Ops.DateTimeOps.WEEK));
    functions.put("month", createFunction(templates, Ops.DateTimeOps.MONTH));
    functions.put("year", createFunction(templates, Ops.DateTimeOps.YEAR));
    return functions;
}

From source file:org.andrewhitchcock.duwamish.util.Accumulators.java

@SuppressWarnings("unchecked")
public static Map<String, Object> getAccumulations(Map<String, Accumulator> accumulators,
        Multimap<String, Object> accumulationMessages) {
    Map<String, Object> results = Maps.newHashMap();
    for (Map.Entry<String, Accumulator> entry : accumulators.entrySet()) {
        String name = entry.getKey();
        Accumulator accumulator = entry.getValue();
        results.put(name, accumulator.accumulate(accumulationMessages.get(name)));
    }/*from w  w  w. ja  v a  2 s.  c  om*/
    return results;
}

From source file:io.macgyver.test.RequestUtil.java

public static Map<String, String> parseFormBody(String body, String encoding) {

    try {//  w ww  .  j  a v  a 2  s  .com
        Map<String, String> m = Maps.newHashMap();

        for (String kv : Splitter.on("&").omitEmptyStrings().split(Strings.nullToEmpty(body))) {

            List<String> kvList = Splitter.on("=").omitEmptyStrings().splitToList(kv);

            if (kvList.size() == 2) {
                m.put(URLDecoder.decode(kvList.get(0), encoding), URLDecoder.decode(kvList.get(1), encoding));
            }

        }

        return m;
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.cloudera.oryx.kmeans.computation.covariance.DistanceData.java

public static Map<ClusterKey, DistanceData> load(String prefix, int n) throws IOException {
    Map<ClusterKey, CovarianceDataBuilder> db = Maps.newHashMap();

    Store store = Store.get();/*from  www. j a  va  2s. c om*/
    for (String file : store.list(prefix, true)) {
        for (String line : new FileLineIterable(store.readFrom(file))) {
            CovarianceData cd = CovarianceData.parse(line);
            ClusterKey key = new ClusterKey(cd.getClusteringId(), cd.getCenterId());
            CovarianceDataBuilder cdb = db.get(key);
            if (cdb == null) {
                cdb = new CovarianceDataBuilder(n);
                db.put(key, cdb);
            }
            cdb.update(cd);
        }
    }

    return Maps.transformValues(db, new Function<CovarianceDataBuilder, DistanceData>() {
        @Override
        public DistanceData apply(CovarianceDataBuilder input) {
            return input.getDistanceData();
        }
    });
}

From source file:com.cloudera.exhibit.core.composite.CompositeExhibit.java

public static CompositeExhibit create(List<Exhibit> components) {
    List<ObsDescriptor> descs = Lists.newArrayList();
    Map<String, ObsDescriptor> frameDescs = Maps.newHashMap();
    for (Exhibit e : components) {
        descs.add(e.descriptor().attributes());
        frameDescs.putAll(e.descriptor().frames());
    }// ww  w  . j  av  a  2 s  .c  o m
    return create(new ExhibitDescriptor(new CompositeObsDescriptor(descs), frameDescs), components);
}

From source file:org.opentestsystem.shared.progman.domain.TenantType.java

public static Map<TenantType, String> findTypes(final Map<String, String[]> inParameterMap) {
    Map<TenantType, String> typeAndValues = Maps.newHashMap();
    for (TenantType tenantType : TenantType.values()) {
        String[] typeValues = inParameterMap.get(tenantType.typeName);
        if (typeValues != null && typeValues.length > 0) {
            String typeValue = typeValues[0];
            if (!StringUtils.isEmpty(typeValue)) {
                typeAndValues.put(tenantType, typeValue);
            }/*from  w  w  w.  j  a  v a  2 s  . co m*/
        }
    }
    return typeAndValues;
}

From source file:com.cloudera.exhibit.server.store.KiteExhibitStore.java

public static ExhibitStore create(String uri, String idCol) {
    Dataset<GenericRecord> data = Datasets.load(uri);
    DatasetReader<GenericRecord> reader = data.newReader();
    Map<String, Exhibit> exhibits = Maps.newHashMap();
    try {/* w w w.  ja  v  a 2s . co m*/
        while (reader.hasNext()) {
            GenericRecord rec = reader.next();
            Exhibit e = AvroExhibit.create(rec);
            exhibits.put(e.attributes().get(idCol, String.class), e);
        }
    } finally {
        reader.close();
    }
    return new KiteExhibitStore(exhibits);
}

From source file:org.auraframework.docs.DocsController.java

@AuraEnabled
public static Component getTopic(@Key("topic") String topic) throws QuickFixException {
    Map<String, Object> attributes = Maps.newHashMap();
    attributes.put("topic", topic);
    return Aura.getInstanceService().getInstance("auradocs:topicPanel", ComponentDef.class, attributes);
}