Example usage for java.util TreeMap putAll

List of usage examples for java.util TreeMap putAll

Introduction

In this page you can find the example usage for java.util TreeMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> map) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:uk.ac.ebi.phenotype.service.StatisticalResultService.java

/**
 * @return Map <String, Long> : <top_level_mp_name, number_of_annotations>
 * @author tudose/*from  w  w w.  j ava  2  s .co  m*/
 */
public TreeMap<String, Long> getDistributionOfAnnotationsByMPTopLevel(ArrayList<String> resourceName,
        Float pValueThreshold) {

    SolrQuery query = new SolrQuery();

    if (resourceName != null) {
        query.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + StatisticalResultDTO.RESOURCE_NAME + ":"));
    } else {
        query.setQuery("*:*");
    }

    if (pValueThreshold != null) {
        query.setFilterQueries(StatisticalResultDTO.P_VALUE + ":[0 TO " + pValueThreshold + "]");
    }

    query.setFacet(true);
    query.setFacetLimit(-1);
    query.setFacetMinCount(1);
    query.setRows(0);
    query.addFacetField(StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME);

    try {
        QueryResponse response = solr.query(query);
        TreeMap<String, Long> res = new TreeMap<>();
        res.putAll(getFacets(response).get(StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME));
        return res;
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizerIncremental.java

@Override
public TreeMap<Double, TariffSpecification> optimizeTariffs(
        HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions,
        HashMap<CustomerInfo, ArrayRealVector> customer2estimatedEnergy,
        List<TariffSpecification> competingTariffs, MarketManager marketManager, ContextManager contextManager,
        CostCurvesPredictor costCurvesPredictor, int currentTimeslot, Broker me) {

    // seed will be the best fixed-rate tariff
    TreeMap<Double, TariffSpecification> sortedTariffs = tariffOptimizerOneShot.optimizeTariffs(
            tariffSubscriptions, customer2estimatedEnergy, competingTariffs, marketManager, contextManager,
            costCurvesPredictor, currentTimeslot, me);
    TariffSpecification fixedRateSeed = extractBestTariffSpec(sortedTariffs);

    // this provides objective function evaluations 
    TariffUtilityEstimateImpl tariffUtilityEstimate = new TariffUtilityEstimateImpl(utilityEstimator, NUM_RATES,
            fixedRateSeed, withdrawFeesOptimizer, tariffSubscriptions, competingTariffs,
            customer2estimatedEnergy, marketPredictionManager, costCurvesPredictor, configuratorFactoryService,
            currentTimeslot, me);//  w w  w . j  a  va 2  s .  co  m

    try {

        TreeMap<Double, TariffSpecification> touTariffs = optimizerWrapper.findOptimum(tariffUtilityEstimate,
                NUM_RATES, NUM_EVAL);

        Entry<Double, TariffSpecification> optimum = touTariffs.lastEntry();
        sortedTariffs.putAll(touTariffs); // adding all tariffs

        // just printing 
        TariffSpecification delete = optimum.getValue();
        log.info("Daniel TOU BEST Candidate " + delete + " util " + optimum.getKey());
        for (Rate r : delete.getRates()) {
            log.info(r);
        }

    } catch (Exception e) {
        log.error("caught exception from incremental tariff optimization, falling back to fixed-rate ", e);
    }
    return sortedTariffs;
}

From source file:org.korecky.nlp.library.BasicTextProcessing.java

/**
 * Segments and calculate words in the input text
 *
 * @param input: Input string//from  w  w  w . jav a2 s.c om
 * @param normalizeText: Indicator, if text should be normalized before
 * counting
 * @param removeAccents: Indicator, if should be removed accent in
 * normalization process
 * @return Sorted TreeMap by count
 */
public TreeMap<String, Long> wordSegmentation(String input, boolean normalizeText, boolean removeAccents) {
    HashMap<String, Long> map = new HashMap<>();
    WordCountComparator comparator = new WordCountComparator(map);
    TreeMap<String, Long> sorted_map = new TreeMap<String, Long>(comparator);

    if (normalizeText) {
        input = normalizeText(input, removeAccents);
    }

    // Words segmentation and calculation
    Pattern pattern = Pattern.compile(
            "[a-zA-Z\\u00C1\\u00C2\\u00C4\\u00C7\\u00C9\\u00CB\\u00CD\\u00CE\\u00D3\\u00D4\\u00D6\\u00DA\\u00DC\\u00DD\\u00DF\\u00E1\\u00E2\\u00E4\\u00E7\\u00E9\\u00EB\\u00ED\\u00EE\\u00F3\\u00F4\\u00F6\\u00FA\\u00FC\\u00FD\\u0102\\u0103\\u0104\\u0105\\u0106\\u0107\\u010C\\u010D\\u010E\\u010F\\u0110\\u0111\\u0118\\u0119\\u011A\\u011B\\u0139\\u013A\\u013D\\u013E\\u0141\\u0142\\u0143\\u0144\\u0147\\u0148\\u0150\\u0151\\u0154\\u0155\\u0158\\u0159\\u015A\\u015B\\u015E\\u015F\\u0160\\u0161\\u0162\\u0163\\u0164\\u0165\\u016E\\u016F\\u0170\\u0171\\u0179\\u017A\\u017B\\u017C\\u017D\\u017E]+");
    Matcher matcher = pattern.matcher(input);
    while (matcher.find()) {
        if (matcher.group() != null) {
            String foundString = matcher.group().trim();
            if (map.containsKey(foundString)) {
                map.replace(foundString, map.get(foundString) + 1);
            } else {
                map.put(foundString, 1L);
            }
        }
    }

    sorted_map.putAll(map);
    return sorted_map;
}

From source file:subsets.GenerateGFKMatrix.java

TreeMap<String, JSONObject> get_SC_BC_Dependency() {

    graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
    registerShutdownHook(graphDb);/* w  ww  . j  av  a 2s .  co m*/
    ExecutionEngine engine = new ExecutionEngine(graphDb);
    ExecutionResult result;

    TreeMap<String, HashSet> SmartCube_SC_Attribut = new TreeMap();
    TreeMap<String, HashSet> MetaCube_SmartCube = new TreeMap();
    TreeMap<String, JSONObject> name_json1 = new TreeMap();
    TreeMap<String, JSONObject> name_json2 = new TreeMap();

    try (Transaction ignored = graphDb.beginTx()) {

        result = (ExecutionResult) engine
                .execute("MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca");
        //TreeMap<String,HashSet> SCAttribut_SCAlgo = new TreeMap();
        //TreeMap<String,HashSet> SCAlgo_BCAttribut = new TreeMap();
        //ArrayList<TreeMap<String,HashSet>> treemaps = new ArrayList();
        for (Map<String, Object> row : result) {
            String SmartCube = null;
            String SC_Attribut = null;
            String SC_Algorithumus = null;
            String BC_Attribut = null;
            String MetaCube = null;

            for (Entry<String, Object> column : row.entrySet()) {
                Node x = (Node) column.getValue();
                if (column.getKey().equals("sca"))
                    SC_Attribut = (String) x.getProperty("name");
                //if (column.getKey().equals("c")) SC_Algorithumus = (String) x.getProperty("name");
                if (column.getKey().equals("sc"))
                    SmartCube = (String) x.getProperty("name");
                //for (String y :x.getPropertyKeys()) System.out.println(y);
                if (column.getKey().equals("sc"))
                    MetaCube = (String) x.getProperty("MetaCube");
            }

            System.out.println("------------------------");

            addAttribute_to_Treemap(MetaCube, SmartCube, MetaCube_SmartCube);
            addAttribute_to_Treemap(SmartCube, SC_Attribut, SmartCube_SC_Attribut);

        } //ende query

    }

    graphDb.shutdown();

    ArrayList<String[]> hirarchy = new ArrayList<String[]>();

    hirarchy.add(sc);
    hirarchy.add(sca);
    hirarchy.add(bca);
    TreeMap<String, JSONObject> SCAttribut_SCAlgo_BCAttribut = getDepTree_old(
            "MATCH (sc:SCAttribut) -[:DERIVED_BY]->(sca:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) RETURN sc,sca,bca",
            hirarchy);

    hirarchy.clear();
    hirarchy.add(sc);
    hirarchy.add(bca);
    TreeMap<String, JSONObject> SCAttribut_BCAttribut = getDepTree(
            "MATCH (sc:SCAttribut) -[:TRANSITION]->(bca:BCAttribut) RETURN sc,bca", hirarchy);

    SCAttribut_SCAlgo_BCAttribut.putAll(SCAttribut_BCAttribut);

    return SCAttribut_SCAlgo_BCAttribut;

    //part_tree(SmartCube_SC_Attribut, SCAttribut_SCAlgo_BCAttribut,name_json1, false);
    //part_tree(MetaCube_SmartCube, name_json1,name_json2, false);

}

From source file:subsets.GenerateGFKMatrix.java

void query2() {

    graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
    registerShutdownHook(graphDb);//w ww.  jav  a2 s . c  om
    ExecutionEngine engine = new ExecutionEngine(graphDb);
    ExecutionResult result;

    TreeMap<String, HashSet> SmartCube_SC_Attribut = new TreeMap();
    TreeMap<String, HashSet> MetaCube_SmartCube = new TreeMap();
    TreeMap<String, JSONObject> name_json1 = new TreeMap();
    TreeMap<String, JSONObject> name_json2 = new TreeMap();

    try (Transaction ignored = graphDb.beginTx()) {

        result = (ExecutionResult) engine
                .execute("MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca");

        //TreeMap<String,HashSet> SCAttribut_SCAlgo = new TreeMap();
        //TreeMap<String,HashSet> SCAlgo_BCAttribut = new TreeMap();
        //ArrayList<TreeMap<String,HashSet>> treemaps = new ArrayList();

        for (Map<String, Object> row : result) {
            String SmartCube = null;
            String SC_Attribut = null;
            String SC_Algorithumus = null;
            String BC_Attribut = null;
            String MetaCube = null;

            for (Entry<String, Object> column : row.entrySet()) {
                Node x = (Node) column.getValue();
                if (column.getKey().equals("sca"))
                    SC_Attribut = (String) x.getProperty("name");
                //if (column.getKey().equals("c")) SC_Algorithumus = (String) x.getProperty("name");
                if (column.getKey().equals("sc"))
                    SmartCube = (String) x.getProperty("name");
                //for (String y :x.getPropertyKeys()) System.out.println(y);
                if (column.getKey().equals("sc"))
                    MetaCube = (String) x.getProperty("MetaCube");
            }

            System.out.println("------------------------");

            addAttribute_to_Treemap(MetaCube, SmartCube, MetaCube_SmartCube);
            addAttribute_to_Treemap(SmartCube, SC_Attribut, SmartCube_SC_Attribut);

        } //ende query

    }

    graphDb.shutdown();

    ArrayList<String[]> hirarchy = new ArrayList<String[]>();

    hirarchy.add(sc);
    hirarchy.add(sca);
    hirarchy.add(bca);
    TreeMap<String, JSONObject> SCAttribut_SCAlgo_BCAttribut = getDepTree_old(
            "MATCH (sc:SCAttribut) -[:DERIVED_BY]->(sca:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) RETURN sc,sca,bca",
            hirarchy);

    hirarchy.clear();
    hirarchy.add(sc);
    hirarchy.add(bca);
    TreeMap<String, JSONObject> SCAttribut_BCAttribut = getDepTree(
            "MATCH (sc:SCAttribut) -[:TRANSITION]->(bca:BCAttribut) RETURN sc,bca", hirarchy);

    SCAttribut_SCAlgo_BCAttribut.putAll(SCAttribut_BCAttribut);

    part_tree(SmartCube_SC_Attribut, SCAttribut_SCAlgo_BCAttribut, name_json1, false);
    part_tree(MetaCube_SmartCube, name_json1, name_json2, false);

    //old and working
    //            part_tree(SmartCube_SC_Attribut, null,name_json1, true);
    //            part_tree(MetaCube_SmartCube, name_json1,name_json2, false);

    //part_tree(SmartCube_SCAttribut, name_json1, name_json2, false);           
    JSONObject MetaCube = new JSONObject();
    try {
        MetaCube.append("name", "MetaCube");

        for (String key : name_json2.keySet()) {
            JSONObject cube = name_json2.get(key);
            MetaCube.append("children", cube);
        }

    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String content = MetaCube.toString();

    try {

        //String content = json_smartcube.toString();

        File file = new File("C://Users//frisch//Desktop//d3//flare.json");

        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();

        System.out.println("Done");

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:kz.nurlan.kaspandr.KaspandrWindow.java

private String checkLessonCountByGroup(String lessons)
        throws JsonParseException, JsonMappingException, IOException {
    String resultString = "";

    ObjectNode rootNode1 = mapper.readValue("{\"lessons\":[" + lessons + "]}", ObjectNode.class);
    JsonNode lessonsNode1 = rootNode1.get("lessons");

    HashMap<String, Integer> groupMap = new HashMap<String, Integer>();
    HashMap<String, String> groupNameMap = new HashMap<String, String>();
    ValueComparator bvc = new ValueComparator(groupNameMap);
    TreeMap<String, String> sortedGroupNameMap = new TreeMap<String, String>(bvc);

    groupMap.put("all", 0);

    if (lessonsNode1 != null && lessonsNode1.isArray()) {
        Iterator<JsonNode> it = lessonsNode1.elements();

        while (it.hasNext()) {
            JsonNode lesson = it.next();

            if (lesson.get("id") != null && !lesson.get("status").textValue().equalsIgnoreCase("deleted")
                    && lesson.get("group") != null && !lesson.get("group").textValue().isEmpty()) {
                if (groupMap.containsKey(lesson.get("group").textValue()))
                    groupMap.put(lesson.get("group").textValue(),
                            groupMap.get(lesson.get("group").textValue()) + 1);
                else
                    groupMap.put(lesson.get("group").textValue(), 1);

                groupNameMap.put(lesson.get("group").textValue(), lesson.get("groupName").textValue());
            }//from   ww  w  . j a va  2s .  c om

            groupMap.put("all", groupMap.get("all") + 1);
        }
    }
    sortedGroupNameMap.putAll(groupNameMap);

    int count = 0;
    for (String group : groupMap.keySet()) {
        if (!group.equals("all")) {
            count += groupMap.get(group);
        }
    }

    for (String group : sortedGroupNameMap.keySet()) {
        if (!resultString.isEmpty())
            resultString += ", ";

        resultString += groupNameMap.get(group) + "(" + groupMap.get(group) + ")";
    }
    resultString = "Lessons(" + count + "/" + groupMap.get("all") + "); " + resultString;

    return resultString;
}

From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java

/**
 * Retruns a map which have either primitive or string keys.
 *
 * This is neccessary to discard object level comparators which may sort the objects based on some non-trivial logic.
 *
 * @param mp//from  w  w w  .  j  a v  a  2 s . c o m
 * @return
 */
private TreeMap<Object, Object> getBasictypeKeyedMap(Map<?, ?> mp) {
    TreeMap<Object, Object> ret = new TreeMap<Object, Object>();
    if (mp.size() > 0) {
        Object firstKey = mp.keySet().iterator().next();
        if (firstKey.getClass().isPrimitive() || firstKey instanceof String) {
            // keep it as-is
            ret.putAll(mp);
            return ret;
        } else {
            for (Entry<?, ?> entry : mp.entrySet()) {
                // discard possibly type related sorting order and replace with alphabetical
                ret.put(entry.getKey().toString(), entry.getValue());
            }
        }
    }
    return ret;
}

From source file:com.isentropy.accumulo.collections.AccumuloSortedMap.java

/**
 * @return a local in memory TreeMap copy containing this ENTIRE map 
 *//*from   ww  w  .ja va 2 s .co  m*/
public final TreeMap<K, V> localCopy() {
    TreeMap<K, V> local = new TreeMap<K, V>();
    local.putAll(this);
    return local;
}

From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizerBinaryOneShot.java

/**
 * evaluate suggestedSpecs(index), and record result to utilToIndex
 * and result//  www .j a v a2  s.  c o m
 * 
 * @param index
 * @param utilToIndex
 * @param result
 * @param suggestedSpecs
 * @param consideredTariffActions
 * @param tariffSubscriptions
 * @param competingTariffs
 * @param costCurvesPredictor
 * @param currentTimeslot
 * @param me
 * @param customer2ShiftedEnergy
 * @param customer2RelevantTariffCharges
 * @param customer2NonShiftedEnergy 
 */
private void evaluateAndRecord(int index, TreeMap<Double, Integer> utilToIndex,
        TreeMap<Double, TariffSpecification> result, List<TariffSpecification> suggestedSpecs,
        ArrayList<TariffSpecification> consideredTariffActions,
        HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions,
        List<TariffSpecification> competingTariffs, CostCurvesPredictor costCurvesPredictor,
        int currentTimeslot, Broker me,
        HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy,
        HashMap<CustomerInfo, ArrayRealVector> customer2NonShiftedEnergy,
        HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> customer2RelevantTariffCharges) {
    TreeMap<Double, TariffSpecification> sortedTariffs;
    consideredTariffActions.clear();
    consideredTariffActions.add(suggestedSpecs.get(index));
    //log.info("computing utilities");
    sortedTariffs = utilityEstimator.estimateUtilities(consideredTariffActions, tariffSubscriptions,
            competingTariffs, customer2RelevantTariffCharges, customer2ShiftedEnergy, customer2NonShiftedEnergy,
            marketPredictionManager, costCurvesPredictor, currentTimeslot, me);
    utilToIndex.put(sortedTariffs.lastEntry().getKey(), index);
    // maintain top 3
    if (utilToIndex.size() > 3) {
        utilToIndex.remove(utilToIndex.firstKey());
    }
    result.putAll(sortedTariffs);
}

From source file:com.searchtechnologies.aspire.components.heritrixconnector.HeritrixScanner.java

@Override
public AspireObject getStatus() throws AspireException {

    HeritrixSourceInfo info = (HeritrixSourceInfo) this.info;

    AspireObject status = addDerivedStatus(STAGE_ID, super.getStatus());

    if (info != null) {
        CrawlJob job = info.getCrawlJob();
        if (job != null) {
            status.push("uriTotalsReportData");
            status.setAttribute("defaultConfig", Boolean.toString(info.useDefaultConfigFile()));
            if (info.useDefaultConfigFile()) {
                status.setAttribute("url", info.getStartUrl());
            } else {
                status.setAttribute("configFile", info.getConfigFileLocation());
            }/*from   w  w w.  java  2 s.co  m*/
            if (job != null & job.uriTotalsReportData() != null)
                for (Entry<String, Long> entry2 : job.uriTotalsReportData().entrySet()) {
                    if (!entry2.getKey().equalsIgnoreCase("futureuricount")) {
                        status.add(entry2.getKey(), entry2.getValue());
                    }
                }
            status.pop(); // uriTotalsReportData
            status.add("uriTotalReport", job.uriTotalsReport());
            status.add("frontierReport", job.frontierReport());
            status.add("elapsedReport", job.elapsedReport());
        }

        status.push("contentSourcesDB");

        if (info.getIncrementalDB() != null) {
            status.push("database");
            //status.setAttribute("id", ""+info.getDatabaseId());
            status.add("friendlyName", info.getFriendlyName());
            status.add("urlAdded", info.getDocsAdded());
            status.add("urlUpdated", info.getDocsUpdated());
            status.add("revisitRate", (info.getDocsUpdated() + 0.0)
                    / ((info.getIncrementalDB().size() - 1) + info.getDocsDeleted() + 0.0));
            status.add("urlDeleted", info.getDocsDeleted());
            status.add("size", info.getIncrementalDB().size() - 1);
            status.add("directory", info.getUrlDir());

            HashMap<String, MutableInt> hostCount = new HashMap<String, MutableInt>();
            HashMap<String, MutableInt> lastHostCount = new HashMap<String, MutableInt>();
            long now = new Date().getTime();
            for (String url : info.getIncrementalDB().keySet()) {
                String hostname = null;
                if (url.equals("||status||"))
                    continue;
                try {
                    hostname = new URL(StringUtilities.safeUrl(url)).getHost();
                } catch (MalformedURLException e) {
                    throw new AspireException(
                            "com.searchtechnologies.aspire.components.heritrixconnector.HeritrixScanner", e,
                            "Error getting hostname for url: %s", url);
                }
                DataBaseURLEntry data = DataBaseURLEntry
                        .createDataBaseURLEntryFromString(info.getIncrementalDB().get(url));
                if (hostCount.containsKey(hostname)) {
                    hostCount.get(hostname).increment();
                } else {
                    hostCount.put(hostname, new MutableInt(1));
                }

                if ((now - data.getTimestamp().getTime()) <= 300000) { //last 5 minutes
                    if (lastHostCount.containsKey(hostname)) {
                        lastHostCount.get(hostname).increment();
                    } else {
                        lastHostCount.put(hostname, new MutableInt(1));
                    }
                }
            }

            ValueComparator comparator = new ValueComparator(hostCount);
            TreeMap<String, MutableInt> sorted_map = new TreeMap<String, MutableInt>(comparator);

            sorted_map.putAll(hostCount);

            status.push("hostnames");
            for (String hostname : sorted_map.keySet()) {
                status.push("hostname");
                status.setAttribute("name", hostname);
                status.add("total", hostCount.get(hostname).toString());
                status.pop(); // hostname
            }
            status.pop(); // hostnames

            comparator = new ValueComparator(lastHostCount);
            sorted_map = new TreeMap<String, MutableInt>(comparator);

            sorted_map.putAll(lastHostCount);

            status.push("lastHostnames");
            for (String hostname : sorted_map.keySet()) {
                status.push("hostname");
                status.setAttribute("name", hostname);
                status.add("total", lastHostCount.get(hostname).toString());
                status.pop(); // hostname
            }
            status.pop(); // lastHostnames

            status.pop();
        }
    }

    status.popAll();
    return status;
}