Example usage for java.util TreeMap get

List of usage examples for java.util TreeMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.apache.hadoop.hbase.backup.util.BackupClientUtil.java

/**
 * Sort history list by start time in descending order.
 * @param historyList history list//  www.  j  a va2  s .  co m
 * @return sorted list of BackupCompleteData
 */
public static ArrayList<BackupInfo> sortHistoryListDesc(ArrayList<BackupInfo> historyList) {
    ArrayList<BackupInfo> list = new ArrayList<BackupInfo>();
    TreeMap<String, BackupInfo> map = new TreeMap<String, BackupInfo>();
    for (BackupInfo h : historyList) {
        map.put(Long.toString(h.getStartTs()), h);
    }
    Iterator<String> i = map.descendingKeySet().iterator();
    while (i.hasNext()) {
        list.add(map.get(i.next()));
    }
    return list;
}

From source file:com.sfs.whichdoctor.xml.writer.PersonXmlWriter.java

/**
 * Gets the mentors xml./*from   w w w  .j ava 2  s .  c  o m*/
 *
 * @param mentors the mentors
 *
 * @return the mentors xml
 */
private static String getMentorsXml(final TreeMap<String, ItemBean> mentors) {

    final XmlWriter xmlwriter = new XmlWriter();

    xmlwriter.writeEntity("mentors");

    for (String orderIndex : mentors.keySet()) {
        ItemBean item = mentors.get(orderIndex);
        xmlwriter.writeEntity("mentor").writeAttribute("personId", item.getObject2GUID());
        xmlwriter.writeEntity("name").writeText(item.getName()).endEntity();

        if (item.getStartDate() != null) {
            xmlwriter.writeEntity("startDate").writeText(Formatter.convertDate(item.getStartDate()))
                    .endEntity();
        }
        if (item.getEndDate() != null) {
            xmlwriter.writeEntity("endDate").writeText(Formatter.convertDate(item.getEndDate())).endEntity();
        }
        if (item.getTitle() != null) {
            xmlwriter.writeEntity("description").writeText(item.getTitle()).endEntity();
        }
        xmlwriter.endEntity();
    }
    xmlwriter.endEntity();

    return xmlwriter.getXml();
}

From source file:Main.java

/**
 * @param r//from www .  j a v  a 2s  .  c  o m
 *          the original rectangle
 * @param includeReservedInsets
 *          if taskbar and other windowing insets should be included in the
 *          returned area
 * @return iff there are multiple monitors the other monitor than the
 *         effective view of the monitor that the rectangle mostly coveres, or
 *         null if there is just one screen
 */
public static Rectangle getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    TreeMap<Integer, Rectangle> prioMap = new TreeMap<Integer, Rectangle>();
    for (GraphicsDevice dev : ge.getScreenDevices()) {
        Rectangle bounds;
        if ((!includeReservedInsets) && dev == ge.getDefaultScreenDevice()) {
            bounds = ge.getMaximumWindowBounds();
        } else {
            bounds = dev.getDefaultConfiguration().getBounds();
        }
        Rectangle intersection = bounds.intersection(r);
        prioMap.put(intersection.width * intersection.height, bounds);
    }
    if (prioMap.size() <= 1) {
        return null;
    } else {
        return prioMap.get(prioMap.firstKey());
    }
}

From source file:com.sfs.whichdoctor.xml.writer.PersonXmlWriter.java

/**
 * Gets the employers xml.//from w w w.  j a  v  a2s  . c  o  m
 *
 * @param employers the employers
 *
 * @return the employers xml
 */
private static String getEmployersXml(final TreeMap<String, ItemBean> employers) {

    final XmlWriter xmlwriter = new XmlWriter();

    xmlwriter.writeEntity("employers");

    for (String orderIndex : employers.keySet()) {
        ItemBean item = employers.get(orderIndex);
        xmlwriter.writeEntity("employer").writeAttribute("GUID", item.getObject1GUID());
        xmlwriter.writeEntity("name").writeText(item.getName()).endEntity();

        if (item.getStartDate() != null) {
            xmlwriter.writeEntity("startDate").writeText(Formatter.convertDate(item.getStartDate()))
                    .endEntity();
        }
        if (item.getEndDate() != null) {
            xmlwriter.writeEntity("endDate").writeText(Formatter.convertDate(item.getEndDate())).endEntity();
        }
        if (item.getTitle() != null) {
            xmlwriter.writeEntity("description").writeText(item.getTitle()).endEntity();
        }
        xmlwriter.endEntity();
    }
    xmlwriter.endEntity();

    return xmlwriter.getXml();
}

From source file:org.decojer.cavaj.utils.SwitchTypes.java

/**
 * Rewrite string-switches from hash to value: Apply previously extracted case value maps to
 * bytecode case edges./* ww  w . j  av  a2  s.c  o  m*/
 *
 * This works differently to {@link #rewriteCaseValues(BB, Map)} because strings could yield to
 * same hashes and cases have to be restructered. It is more reasonable to add new case edges
 * and delete all previous case edges.
 *
 * @param switchHead
 *            switch head
 * @param string2bb
 *            case value map: string to BB
 * @param defaultCase
 *            default case
 */
public static void rewriteCaseStrings(@Nonnull final BB switchHead, @Nonnull final Map<String, BB> string2bb,
        @Nonnull final BB defaultCase) {
    // remember old switch case edges, for final deletion
    final List<E> outs = switchHead.getOuts();
    int i = outs.size();

    // build sorted map: unique case pc -> matching case keys
    final TreeMap<Integer, List<String>> casePc2values = Maps.newTreeMap();
    // add case branches
    for (final Map.Entry<String, BB> string2bbEntry : string2bb.entrySet()) {
        final int casePc = string2bbEntry.getValue().getPc();
        List<String> caseValues = casePc2values.get(casePc);
        if (caseValues == null) {
            caseValues = Lists.newArrayList();
            casePc2values.put(casePc, caseValues); // pc-sorted
        }
        caseValues.add(string2bbEntry.getKey());
    }
    // add default branch
    final int defaultPc = defaultCase.getPc();
    List<String> defaultCaseValues = casePc2values.get(defaultPc);
    if (defaultCaseValues == null) {
        defaultCaseValues = Lists.newArrayList();
        casePc2values.put(defaultPc, defaultCaseValues);
    }
    defaultCaseValues.add(null);

    // now add successors, preserve pc-order as edge-order
    for (final Map.Entry<Integer, List<String>> casePc2valuesEntry : casePc2values.entrySet()) {
        final List<String> caseValues = casePc2valuesEntry.getValue();

        // get BB from first value via previous string2bb map
        final String caseValue = caseValues.get(0);
        final BB caseBb = caseValue == null ? defaultCase : string2bb.get(caseValue);
        assert caseBb != null;

        final Object[] values = caseValues.toArray(new Object[caseValues.size()]);
        assert values != null;
        switchHead.addSwitchCase(caseBb, values);
    }
    // delete all previous outgoing switch cases
    for (; i-- > 0;) {
        final E out = outs.get(i);
        if (out.isSwitchCase()) {
            out.remove();
        }
    }
}

From source file:com.nubits.nubot.trading.TradeUtils.java

public static String buildQueryString(TreeMap<String, String> args, String encoding) {
    String result = new String();
    for (String hashkey : args.keySet()) {
        if (result.length() > 0) {
            result += '&';
        }//from w ww . j av a  2  s. c o  m
        try {
            result += URLEncoder.encode(hashkey, encoding) + "="
                    + URLEncoder.encode(args.get(hashkey), encoding);
        } catch (Exception ex) {
            LOG.severe(ex.toString());
        }
    }
    return result;
}

From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java

private static String createStringFromTreeMap(TreeMap treemap) {
    String content = "";
    Iterator<Map.Entry<String, TreeMap>> entries = treemap.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry<String, TreeMap> entry = entries.next();
        String vonameinMap = entry.getKey();
        List voDetails = (List) entry.getValue();
        for (int i = 0; i < voDetails.size(); i++) {
            TreeMap details = (TreeMap) voDetails.get(i);
            String server = (String) details.get("server");
            String port = (String) details.get("port");
            String dn = (String) details.get("dn");
            String servervoname = (String) details.get("servervoname");
            String lscString = "\"" + vonameinMap + "\"" + " \"" + server + "\"" + " \"" + port + "\"" + " \""
                    + dn + "\"" + " \"" + servervoname + "\"";
            content += lscString + "\n";
        }//from   w  ww .  j  a va  2  s.  c o m
    }
    return content;
}

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

static double calDistincValue(TreeMap<String, Integer> para, int num_sampled_rows) {

    int num_multiple = 0;
    int num_distinct = para.keySet().size();
    LOG.debug("num_distinct: " + num_distinct);
    double stat_distinct_values;
    for (String s : para.keySet()) {
        if (para.get(s) > 1) {
            num_multiple++;/*from ww w. j a  v  a 2  s  .  c  o  m*/
        }
    }
    LOG.debug("num_multiple: " + num_multiple);
    if (num_multiple == 0) {
        stat_distinct_values = -1;
        return stat_distinct_values;
    } else if (num_multiple == num_distinct) {
        stat_distinct_values = num_distinct;
        return stat_distinct_values;
    }
    int totalrows = num_sampled_rows;
    int f1 = num_distinct - num_multiple;
    int d = num_distinct;
    int numer = num_sampled_rows * d;
    int denom = (num_sampled_rows - f1) + f1 * num_sampled_rows / totalrows;
    LOG.debug("numer: " + numer);
    LOG.debug("denom: " + denom);
    int distinct_values = numer / denom;
    if (distinct_values < d) {
        distinct_values = d;
    } else if (distinct_values > totalrows) {
        distinct_values = totalrows;
    }
    LOG.debug("distinct_values: " + distinct_values);
    LOG.debug("totalrows: " + totalrows);
    stat_distinct_values = Math.floor(distinct_values + 0.5);
    if (stat_distinct_values > 0.1 * totalrows) {
        stat_distinct_values = -(stat_distinct_values / totalrows);
    }
    LOG.debug("stat_distinct_values: " + stat_distinct_values);
    return stat_distinct_values;
}

From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java

public static boolean compareTreeMapInList(String voName, TreeMap favInfo, List list) {
    boolean isSame = false;
    String favServer = (String) favInfo.get("server");
    String favPort = (String) favInfo.get("port");
    String favDN = (String) favInfo.get("dn");
    for (int j = 0; j < list.size(); j++) {
        TreeMap info = (TreeMap) list.get(j);
        String egiServer = (String) info.get("server");
        if (favServer.equals(egiServer)) {
            //Now check also the port and dn
            String egiPort = (String) info.get("port");
            String egiDN = (String) info.get("dn");
            if (egiPort.equals(favPort) && egiDN.equals(favDN)) {
                isSame = true;//from www . j a v a2  s . co  m
                break;
            }
        }
    }
    return isSame;

}

From source file:com.sfs.whichdoctor.xml.writer.helper.AccreditationXmlHelper.java

/**
 * Output the training summary as an XML string.
 *
 * @param trainingSummary the training summary
 * @param type the type//ww w . j a v  a2s.  co  m
 *
 * @return the xml string
 */
public static String getSummaryXml(final TreeMap<String, AccreditationBean[]> trainingSummary,
        final String type) {

    final XmlWriter xmlwriter = new XmlWriter();

    if (trainingSummary.size() > 0) {

        int totalCore = 0;
        int totalNonCore = 0;

        TreeMap<String, ArrayList<AccreditationBean[]>> summaryTreemap = new TreeMap<String, ArrayList<AccreditationBean[]>>();

        for (String summaryKey : trainingSummary.keySet()) {

            AccreditationBean[] details = trainingSummary.get(summaryKey);
            AccreditationBean core = details[0];
            AccreditationBean nonCore = details[1];

            totalCore += core.getWeeksCertified();
            totalNonCore += nonCore.getWeeksCertified();

            if (StringUtils.isNotBlank(core.getSpecialtyType())) {

                ArrayList<AccreditationBean[]> summaries = new ArrayList<AccreditationBean[]>();

                if (!summaryTreemap.containsKey(core.getSpecialtyType())) {
                    /* New type of specialty */
                    summaries.add(details);
                } else {
                    /* Existing specialty */
                    summaries = summaryTreemap.get(core.getSpecialtyType());
                    summaries.add(details);
                }
                summaryTreemap.put(core.getSpecialtyType(), summaries);
            }
        }

        xmlwriter.writeEntity("trainingSummary");
        xmlwriter.writeAttribute("type", type);
        xmlwriter.writeAttribute("totalCore", Formatter.getWholeMonths(totalCore));
        xmlwriter.writeAttribute("totalNonCore", Formatter.getWholeMonths(totalNonCore));

        xmlwriter.writeEntity("specialtyTraining");

        for (String specialtyType : summaryTreemap.keySet()) {

            ArrayList<AccreditationBean[]> summaries = summaryTreemap.get(specialtyType);
            int typeCoreWeeks = 0;
            int typeNCWeeks = 0;

            if (summaries != null) {
                // For each accredited specialty create an element
                xmlwriter.writeEntity("specialty");
                xmlwriter.writeEntity("subtypes");
                String division = "";
                String abbreviation = "";
                String specialtytype = "";
                String typeAbbreviation = "";
                for (Object[] summary : summaries) {
                    boolean blSubType = false;
                    AccreditationBean core = (AccreditationBean) summary[0];
                    AccreditationBean nonCore = (AccreditationBean) summary[1];

                    division = core.getAccreditationClass();
                    abbreviation = core.getAbbreviation();
                    specialtytype = core.getSpecialtyType();
                    typeAbbreviation = core.getSpecialtyTypeAbbreviation();

                    if (StringUtils.isNotBlank(core.getSpecialtySubType())) {
                        blSubType = true;
                        xmlwriter.writeEntity("subtype");
                        xmlwriter.writeEntity("name").writeText(core.getSpecialtySubType()).endEntity();
                        xmlwriter.writeEntity("coreMonths")
                                .writeText(Formatter.getWholeMonths(core.getWeeksCertified())).endEntity();
                        xmlwriter.writeEntity("nonCoreMonths")
                                .writeText(Formatter.getWholeMonths(nonCore.getWeeksCertified())).endEntity();

                        xmlwriter.endEntity();

                        typeCoreWeeks += core.getWeeksCertified();
                        typeNCWeeks += nonCore.getWeeksCertified();
                    }
                    if (!blSubType) {
                        xmlwriter.writeEntity("subtype");
                        xmlwriter.writeEntity("coreMonths")
                                .writeText(Formatter.getWholeMonths(core.getWeeksCertified())).endEntity();
                        xmlwriter.writeEntity("nonCoreMonths")
                                .writeText(Formatter.getWholeMonths(nonCore.getWeeksCertified())).endEntity();

                        xmlwriter.endEntity();

                        typeCoreWeeks += core.getWeeksCertified();
                        typeNCWeeks += nonCore.getWeeksCertified();
                    }
                }
                xmlwriter.endEntity();

                xmlwriter.writeEntity("division").writeText(division).endEntity();
                xmlwriter.writeEntity("abbreviation").writeText(abbreviation).endEntity();
                xmlwriter.writeEntity("type").writeText(specialtytype).endEntity();
                xmlwriter.writeEntity("typeAbbreviation").writeText(typeAbbreviation).endEntity();
                xmlwriter.writeEntity("coreMonths").writeText(Formatter.getWholeMonths(typeCoreWeeks))
                        .endEntity();
                xmlwriter.writeEntity("nonCoreMonths").writeText(Formatter.getWholeMonths(typeNCWeeks))
                        .endEntity();

                xmlwriter.endEntity();
            }
        }
        xmlwriter.endEntity();

        xmlwriter.endEntity();
    }
    return xmlwriter.getXml();
}