Example usage for java.util TreeMap size

List of usage examples for java.util TreeMap size

Introduction

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

Prototype

int size

To view the source code for java.util TreeMap size.

Click Source Link

Document

The number of entries in the tree

Usage

From source file:org.ala.spatial.analysis.layers.SitesBySpeciesTabulated.java

/**
 * write bioregion tabulation./*w  ww . ja  va 2  s  .c o m*/
 * <p/>
 * Output filename is name + ".csv" and name + ".json".
 *
 * @param name            output filename
 * @param outputDirectory directory for output.
 * @param columns         list of the bioregion names.
 * @param bioMap          data to write.
 * @return
 */
private Map writeBioregions(String name, String outputDirectory, String[] columns,
        HashMap<Integer, Integer>[] bioMap) {
    Map map = new HashMap();
    ArrayList array = new ArrayList();
    try {
        FileWriter fw = new FileWriter(outputDirectory + File.separator + name + ".csv");

        //identify column numbers
        TreeMap<Integer, Integer> tm = new TreeMap();
        for (int i = 0; i < columns.length; i++) {
            tm.putAll(bioMap[i]);
        }
        Integer[] cols = new Integer[tm.size()];
        tm.keySet().toArray(cols);

        ArrayList<Integer> c = new ArrayList<Integer>();
        for (int j = 0; j < cols.length; j++) {
            c.add(cols[j]);
            fw.write(",\"" + cols[j] + "\"");
        }

        //bioregion rows
        for (int i = 0; i < columns.length + 1; i++) {
            if (bioMap[i].size() > 0) {
                ArrayList array2 = new ArrayList();
                String rowname = "Undefined";
                if (i > 0) {
                    rowname = columns[i - 1];
                }
                fw.write("\n\"" + rowname + "\"");
                //count columns
                for (int j = 0; j < cols.length; j++) {
                    Integer v = bioMap[i].get(cols[j]);
                    fw.write(",");
                    if (v != null) {
                        fw.write(v.toString());
                        array2.add(v.toString());
                    } else {
                        array2.add("");
                    }
                }
                Map m3 = new HashMap();
                m3.put("name", rowname);
                m3.put("row", array2);
                array.add(m3);
            }
        }

        Map m4 = new HashMap();
        m4.put("rows", array);
        m4.put("columns", c);
        map.put(name, m4);

        fw.close();

        fw = new FileWriter(outputDirectory + File.separator + name + ".json");
        JSONObject.writeJSONString(map, fw);
        fw.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return map;
}

From source file:com.opengamma.analytics.financial.provider.calculator.discounting.CashFlowEquivalentCalculator.java

@Override
public AnnuityPaymentFixed visitBondFixedSecurity(final BondFixedSecurity bond,
        final MulticurveProviderInterface multicurves) {
    ArgumentChecker.notNull(bond, "Bond");
    ArgumentChecker.notNull(multicurves, "Multicurves provider");
    final Currency ccy = bond.getCurrency();
    final TreeMap<Double, Double> flow = new TreeMap<>();
    final AnnuityPaymentFixed cfeNom = bond.getNominal().accept(this, multicurves);
    final AnnuityPaymentFixed cfeCpn = bond.getCoupon().accept(this, multicurves);
    for (final PaymentFixed p : cfeNom.getPayments()) {
        flow.put(p.getPaymentTime(), p.getAmount());
    }/*  www .j  av a 2s .c om*/
    for (final PaymentFixed p : cfeCpn.getPayments()) {
        addcf(flow, p.getPaymentTime(), p.getAmount());
    }
    final PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()];
    int loopcf = 0;
    for (final double time : flow.keySet()) {
        agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time));
    }
    return new AnnuityPaymentFixed(agregatedCfe);

}

From source file:org.ala.spatial.analysis.layers.SitesBySpeciesTabulated.java

/**
 * write decades tabulation.//from   w  w w .  ja va2s  .  c  om
 * <p/>
 * Output filename is "decades.csv" and "decades.json".
 *
 * @param outputDirectory path to output directory.
 * @param decadeIdx       array of decades.
 * @param decMap          array of map of values to write.
 * @return
 */
private Map writeDecades(String outputDirectory, short[] decadeIdx, HashMap<Integer, Integer>[] decMap) {
    Map map = new HashMap();
    ArrayList array = new ArrayList();

    try {
        FileWriter fw = new FileWriter(outputDirectory + File.separator + "decades.csv");

        //identify column numbers
        TreeMap<Integer, Integer> tm = new TreeMap();
        for (int i = 0; i < decMap.length; i++) {
            tm.putAll(decMap[i]);
        }
        Integer[] cols = new Integer[tm.size()];
        tm.keySet().toArray(cols);

        ArrayList<Integer> c = new ArrayList<Integer>();
        for (int j = 0; j < cols.length; j++) {
            c.add(cols[j]);
            fw.write(",\"" + cols[j] + "\"");
        }

        //bioregion rows
        for (int i = 0; i < decMap.length; i++) {
            if (decMap[i].size() > 0) {
                ArrayList array2 = new ArrayList();
                int pos = java.util.Arrays.binarySearch(decadeIdx, (short) i);
                //seek to first
                while (pos > 0 && decadeIdx[pos - 1] == i) {
                    pos--;
                }
                String rowname = "no year recorded";
                if (i > 0) {
                    rowname = pos + " to " + (pos + 9);
                }
                fw.write("\n\"" + rowname + "\"");
                //count columns
                for (int j = 0; j < cols.length; j++) {
                    Integer v = decMap[i].get(cols[j]);
                    fw.write(",");
                    if (v != null) {
                        fw.write(v.toString());
                        array2.add(v.toString());
                    } else {
                        array2.add("");
                    }
                }
                Map m3 = new HashMap();
                m3.put("name", rowname);
                m3.put("row", array2);
                array.add(m3);
            }
        }

        Map m4 = new HashMap();
        m4.put("rows", array);
        m4.put("columns", c);
        map.put("decades", m4);

        fw.close();

        fw = new FileWriter(outputDirectory + File.separator + "decades.json");
        JSONObject.writeJSONString(map, fw);
        fw.close();

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

    return map;
}

From source file:org.ala.spatial.analysis.layers.SitesBySpeciesTabulated.java

/**
 * write decade counts tabulation.//from   w  w  w. j  a v a 2  s .c o  m
 * <p/>
 * Output filename is "decadecounts.csv" and "decadecounts.json".
 *
 * @param outputDirectory path to output directory.
 * @param decadeIdx       array of decades.
 * @param decMap          array of map of values to write.
 * @return
 */
private Map writeDecadeCounts(String outputDirectory, HashMap<Integer, Integer>[] decCountMap) {
    Map map = new HashMap();
    ArrayList array = new ArrayList();

    try {
        FileWriter fw = new FileWriter(outputDirectory + File.separator + "decadecounts.csv");

        //identify column numbers
        TreeMap<Integer, Integer> tm = new TreeMap();
        for (int i = 1; i < decCountMap.length; i++) {
            tm.putAll(decCountMap[i]);
        }
        Integer[] cols = new Integer[tm.size()];
        tm.keySet().toArray(cols);

        ArrayList<Integer> c = new ArrayList<Integer>();
        for (int j = 0; j < cols.length; j++) {
            c.add(cols[j]);
            fw.write(",\"" + cols[j] + "\"");
        }

        //bioregion rows
        for (int i = 1; i < decCountMap.length; i++) {
            if (decCountMap[i].size() > 0) {
                ArrayList array2 = new ArrayList();
                String rowname = i + " Decades";
                fw.write("\n\"" + rowname + "\"");
                //count columns
                for (int j = 0; j < cols.length; j++) {
                    Integer v = decCountMap[i].get(cols[j]);
                    fw.write(",");
                    if (v != null) {
                        fw.write(v.toString());
                        array2.add(v.toString());
                    } else {
                        array2.add("");
                    }
                }
                Map m3 = new HashMap();
                m3.put("name", rowname);
                m3.put("row", array2);
                array.add(m3);
            }
        }

        Map m4 = new HashMap();
        m4.put("rows", array);
        m4.put("columns", c);
        map.put("decadecounts", m4);

        fw.close();

        fw = new FileWriter(outputDirectory + File.separator + "decadecounts.json");
        JSONObject.writeJSONString(map, fw);
        fw.close();

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

    return map;
}

From source file:com.opengamma.analytics.financial.provider.calculator.discounting.CashFlowEquivalentCalculator.java

@Override
public AnnuityPaymentFixed visitSwap(final Swap<?, ?> swap, final MulticurveProviderInterface multicurves) {
    ArgumentChecker.notNull(swap, "Swap");
    ArgumentChecker.notNull(multicurves, "Multicurves provider");
    final Currency ccy = swap.getFirstLeg().getCurrency();
    Validate.isTrue(ccy.equals(swap.getSecondLeg().getCurrency()),
            "Cash flow equivalent available only for single currency swaps.");
    final TreeMap<Double, Double> flow = new TreeMap<>();
    final AnnuityPaymentFixed cfeLeg1 = swap.getFirstLeg().accept(this, multicurves);
    final AnnuityPaymentFixed cfeLeg2 = swap.getSecondLeg().accept(this, multicurves);
    for (final PaymentFixed p : cfeLeg1.getPayments()) {
        flow.put(p.getPaymentTime(), p.getAmount());
    }/*from  w  w  w  . j  a v a  2s .c  om*/
    for (final PaymentFixed p : cfeLeg2.getPayments()) {
        addcf(flow, p.getPaymentTime(), p.getAmount());
    }
    final PaymentFixed[] agregatedCfe = new PaymentFixed[flow.size()];
    int loopcf = 0;
    for (final double time : flow.keySet()) {
        agregatedCfe[loopcf++] = new PaymentFixed(ccy, time, flow.get(time));
    }
    return new AnnuityPaymentFixed(agregatedCfe);
}

From source file:org.powertac.common.config.ConfiguratorTest.java

@Test
public void testBootstrapState() {
    final TreeMap<String, Object> map = new TreeMap<String, Object>();
    ConfigurationRecorder cr = new ConfigurationRecorder() {
        @Override/*  w  w w. j a  va 2s.  c om*/
        public void recordItem(String key, Object value) {
            map.put(key, value);
        }
    };
    ConfigTestDummy dummy = new ConfigTestDummy();
    Configurator uut = new Configurator();
    uut.gatherBootstrapState(dummy, cr);
    assertEquals(2, map.size(), "two entries");
    assertEquals(0, ((Integer) map.get("pt.configTestDummy.intProperty")).intValue(), "correct int");
    assertEquals(-0.06, (Double) map.get("pt.configTestDummy.fixedPerKwh"), 1e-6, "correct double");
}

From source file:org.powertac.common.config.ConfiguratorTest.java

@Test
public void testPublishConfig() {
    final TreeMap<String, Object> map = new TreeMap<String, Object>();
    ConfigurationRecorder cr = new ConfigurationRecorder() {
        @Override/*from   ww  w  .  jav  a 2  s  .  c o  m*/
        public void recordItem(String key, Object value) {
            map.put(key, value);
        }
    };
    ConfigTestDummy dummy = new ConfigTestDummy();
    Configurator uut = new Configurator();
    uut.gatherPublishedConfiguration(dummy, cr);
    assertEquals(2, map.size(), "two entries");
    assertEquals("dummy", (String) map.get("pt.configTestDummy.stringProperty"), "correct String");
    assertEquals(-0.06, (Double) map.get("pt.configTestDummy.fixedPerKwh"), 1e-6, "correct double");
}

From source file:com.almende.dht.Bucket.java

/**
 * Gets the closest nodes.//from  w  w  w .  j a v a  2s  .  c om
 *
 * @param near
 *            the near
 * @param limit
 *            the limit
 * @param filter
 *            the filter
 * @return the closest nodes
 */
public List<Node> getClosestNodes(final Key near, final int limit, final Collection<Key> filter) {
    synchronized (nodes) {
        final TreeMap<Key, Node> distMap = new TreeMap<Key, Node>();
        final Iterator<Entry<Key, Node>> iter = nodes.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<Key, Node> entry = iter.next();
            if (filter != null && filter.contains(entry.getKey())) {
                continue;
            }
            distMap.put(near.dist(entry.getKey()), entry.getValue());
        }
        final Node[] values = distMap.values().toArray(new Node[0]);
        return Arrays.asList(Arrays.copyOf(values, Math.min(limit, distMap.size())));
    }
}

From source file:edu.fullerton.ldvw.ImageHistory.java

/**
 * Add a table of buttons/links and info to control display and deletion
 *
 * @param imgCnt total number of records in selection
 *///from  ww w.  j  a va 2 s  . c  o m
private PageItemList getNavBar(int imgCnt, boolean isBottom, String frmName)
        throws WebUtilException, LdvTableException, SQLException {
    PageItemList ret = new PageItemList();
    PageTable navBar = new PageTable();
    PageTableRow cmds = new PageTableRow();

    // add next/prev buttons if applicable
    PageFormButton prevBtn = new PageFormButton("submitAct", "<", "Prev");
    prevBtn.setEnabled(strt > 0);
    cmds.add(prevBtn);

    String botSuffix = isBottom ? "2" : "";

    int curPage = strt / cnt + 1;
    int nPage = (imgCnt + cnt - 1) / cnt;
    PageItemList pageSel = new PageItemList();
    pageSel.add("Page: ");
    PageFormText pageNum = new PageFormText("pageNum" + botSuffix, String.format("%1$,d", curPage));
    pageNum.setSize(3);
    pageNum.setMaxLen(6);
    pageNum.addEvent("onchange", "historySubmit('Go" + botSuffix + "', this);");
    pageSel.add(pageNum);
    pageSel.add(String.format(" of %d ", nPage));
    cmds.add(pageSel);

    PageFormButton nextBtn = new PageFormButton("submitAct", ">", "Next");
    nextBtn.setEnabled(curPage < nPage);
    cmds.add(nextBtn);

    int stop = Math.min(strt + cnt, imgCnt);
    String showing = String.format("Showing %1$d-%2$d for:", strt + 1, stop);
    cmds.add(showing);

    // add selection by user
    String cn = vuser.getCn();

    TreeMap<String, Integer> ucounts = imgTbl.getCountByUser();
    String[] usrs = new String[ucounts.size() + 1];
    String sel = "All";
    usrs[0] = "All";
    int i = 1;
    for (Map.Entry<String, Integer> entry : ucounts.entrySet()) {
        String u = entry.getKey();
        Integer cnts = entry.getValue();
        String opt = String.format("%1$s (%2$d)", u, cnts);
        if (userWanted.equalsIgnoreCase(u)) {
            sel = opt;
        }
        usrs[i] = opt;
        i++;
    }
    if (!isBottom) {
        // allow them to select another user (or all)
        PageFormSelect usrSel = new PageFormSelect("usrSel", usrs);
        usrSel.setSelected(sel);
        usrSel.addEvent("onchange", "this.form.submit()");
        PageItemList owner = new PageItemList();
        owner.add(new PageItemString("Owner:&nbsp;", false));
        owner.add(usrSel);
        cmds.add(owner);

        // Group selector
        TreeSet<String> groups = imgGrpTbl.getGroups(userWanted);
        if (!groups.isEmpty()) {
            PageItemList grpPIL = new PageItemList();
            grpPIL.add(new PageItemString("Group:&nbsp;", false));
            groups.add("All");
            PageFormSelect grpSel = new PageFormSelect("group");
            grpSel.add(groups);
            String curGroup = request.getParameter("group");
            if (curGroup != null && !curGroup.isEmpty() && groups.contains(curGroup)) {
                grpSel.setSelected(curGroup);
            } else {
                grpSel.setSelected("All");
            }
            grpSel.addEvent("onchange", "document." + frmName + ".submit()");
            grpPIL.add(grpSel);
            cmds.add(grpPIL);
        }
    }
    cmds.setClassAll("noborder");
    navBar.addRow(cmds);
    ret.add(navBar);

    if (!isBottom) {
        // New table because this one has fewer columns and we want to hide it by default
        navBar = new PageTable();
        navBar.setClassName("hidable");
        navBar.addStyle("display", "none");

        // allow them to change image size
        PageTableRow cmd2 = new PageTableRow();
        String[] sizes = { "original", "small", "med" };
        PageFormSelect sizeSel = new PageFormSelect("size", sizes);
        String curSize = request.getParameter("size");
        if (curSize != null && !curSize.isEmpty() && ArrayUtils.contains(sizes, curSize)) {
            sizeSel.setSelected(curSize);
        }
        sizeSel.addEvent("onchange", "document." + frmName + ".submit()");
        PageItemString lbl;
        lbl = new PageItemString("Size:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        cmd2.add(lbl);
        PageTableColumn col;
        col = new PageTableColumn(sizeSel);
        cmd2.add(col);
        cmd2.add();
        cmd2.add();
        cmd2.setClassAll("noborder");
        navBar.addRow(cmd2);

        cmd2 = new PageTableRow();
        lbl = new PageItemString("Selections:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        cmd2.add(lbl);

        PageFormButton selAll = new PageFormButton("selAll", "Select all", "selall");
        selAll.setType("button");
        selAll.addEvent("onclick", "setChkBoxByClass('selBox',true)");
        cmd2.add(selAll);

        PageFormButton clrAll = new PageFormButton("selAll", "Clear all", "clrall");
        clrAll.setType("button");
        clrAll.addEvent("onclick", "setChkBoxByClass('selBox', false)");
        cmd2.add(clrAll);
        cmd2.add();
        cmd2.setClassAll("noborder");
        navBar.addRow(cmd2);

        if (userWanted.equalsIgnoreCase(vuser.getCn()) || vuser.isAdmin()) {
            cmd2 = new PageTableRow();
            lbl = new PageItemString("Delete images:&nbsp;", false);
            lbl.setAlign(PageItem.Alignment.RIGHT);
            cmd2.add(lbl);

            col = new PageTableColumn(new PageFormSubmit("submitAct", "Delete Selected"));
            cmd2.add(col);
            cmd2.add();
            cmd2.add();
            cmd2.setClassAll("noborder");
            navBar.addRow(cmd2);
        }

        PageTableRow grpRow = new PageTableRow();
        lbl = new PageItemString("My groups:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        grpRow.add(lbl);

        TreeSet<String> myGroup = imgGrpTbl.getGroups(curUser);
        if (!myGroup.contains("Favorites")) {
            myGroup.add("Favorites");
        }
        myGroup.remove("Last result");
        PageFormSelect grpSel = new PageFormSelect("op_group");
        grpSel.add(myGroup);
        String curGroup = request.getParameter("groupSel");
        if (curGroup != null && !curGroup.isEmpty() && myGroup.contains(curGroup)) {
            grpSel.setSelected(curGroup);
        } else {
            grpSel.setSelected("Favorites");
        }
        grpRow.add(grpSel);

        grpRow.add(new PageFormSubmit("submitAct", "Add to grp"));
        grpRow.add(new PageFormSubmit("submitAct", "Del from grp"));
        grpRow.setClassAll("noborder");
        navBar.addRow(grpRow);
        grpRow = new PageTableRow();
        lbl = new PageItemString("New Group:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        grpRow.add(lbl);
        PageFormText grpNameTxt = new PageFormText("newGrpName", "<new group name>");
        grpNameTxt.addEvent("onfocus", "if(this.value == '<new group name>'){ this.value = ''; }");
        grpNameTxt.addEvent("onblur", "if(this.value == ''){ this.value = '<new group name>'; }");
        grpRow.add(grpNameTxt);
        PageFormSubmit newGrpBtn = new PageFormSubmit("submitAct", "New grp");
        grpRow.add(newGrpBtn);
        grpRow.add();
        grpRow.setClassAll("noborder");
        navBar.addRow(grpRow);
        ret.add(navBar);

        PageItemString optBtn = new PageItemString("+More options");
        optBtn.addEvent("onclick", "showByClass('hidable',this)");
        optBtn.setClassName("showCmd");
        ret.addBlankLines(1);
        ret.add(optBtn);
    }
    vpage.includeJS("showByClass.js");
    return ret;
}

From source file:GitBackend.GitAPI.java

public RevCommit getMostRecentCommit(Date execDate, String path) {
    TreeMap<DateTime, RevCommit> allCommits = this.getAllCommitsBefore(execDate, path);
    if (allCommits.size() == 0) {
        logger.severe("Error... No commit");
        return null;
    } else {//from  www.  j  a  va2s.  c o  m
        RevCommit lastCommit = allCommits.lastEntry().getValue();
        System.out.println("Last entry: " + lastCommit.getName() + " was at "
                + new DateTime(lastCommit.getCommitterIdent().getWhen()));
        return lastCommit;

    }

}