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:com.opengamma.analytics.financial.provider.calculator.discounting.CashFlowEquivalentCalculator.java

/**
 * Add a cash flow amount at a given time in the flow map. If the time is present, the amount is added; if the time is not present a new entry is created.
 * @param flow The map describing the cash flows.
 * @param time The time of the flow to add.
 * @param amount The amount of the flow to add.
 *//*from ww  w.  j  av a 2s  .co  m*/
private static void addcf(final TreeMap<Double, Double> flow, final double time, final double amount) {
    if (flow.containsKey(time)) {
        flow.put(time, flow.get(time) + amount);
    } else {
        flow.put(time, amount);
    }
}

From source file:cooccurrence.Omer_Levy.java

/**
 * Method that will extract top D singular values from CoVariance Matrix 
 * It will then identify the corresponding columns from U and V and add it to new matrices 
 * @param U//from w  w w .ja v  a2s  .  co  m
 * @param V
 * @param coVariance
 * @param matrixUd
 * @param matrixVd
 * @param coVarD
 * @param indicesD 
 */
private static void getTopD(RealMatrix U, RealMatrix V, RealMatrix coVariance, RealMatrix matrixUd,
        RealMatrix matrixVd, RealMatrix coVarD, ArrayList<Integer> indicesD) {
    TreeMap<Double, Set<Integer>> tmap = new TreeMap<>();
    for (int i = 0; i < coVariance.getRowDimension(); i++) {
        double val = coVariance.getEntry(i, i);
        if (tmap.containsKey(val)) {
            Set<Integer> temp = tmap.get(val);
            temp.add(i);
        } else {
            Set<Integer> temp = new HashSet<>();
            temp.add(i);
            tmap.put(val, temp);
        }
    }
    Iterator iter = tmap.keySet().iterator();
    while (iter.hasNext()) {
        Double val = (Double) iter.next();
        Set<Integer> indices = tmap.get(val);
        for (int i = 0; i < indices.size(); i++) {
            Iterator iterIndices = indices.iterator();
            while (iterIndices.hasNext()) {
                int index = (Integer) iterIndices.next();
                indicesD.add(index);
                coVarD.addToEntry(index, index, val);
                matrixUd.setColumnVector(index, U.getColumnVector(index));
                matrixVd.setColumnVector(index, V.getColumnVector(index));
            }
        }
    }

}

From source file:org.apache.hadoop.hbase.MultiRegionTable.java

private static int count(final HTable t, final String tableName) throws IOException {

    int size = 0;
    Text[] cols = new Text[] { HConstants.COLUMN_FAMILY };
    HScannerInterface s = t.obtainScanner(cols, HConstants.EMPTY_START_ROW, System.currentTimeMillis(), null);
    try {// w  w  w. j av a 2 s  .  com
        HStoreKey curKey = new HStoreKey();
        TreeMap<Text, byte[]> curVals = new TreeMap<Text, byte[]>();
        while (s.next(curKey, curVals)) {
            HRegionInfo hri = Writables.getHRegionInfoOrNull(curVals.get(HConstants.COL_REGIONINFO));
            if (hri.getTableDesc().getName().toString().equals(tableName)) {
                size++;
            }
        }
        return size;
    } finally {
        s.close();
    }
}

From source file:org.apache.hadoop.hbase.MultiRegionTable.java

private static Map<Text, byte[]> getSplitParentInfo(final HTable t, final HRegionInfo parent)
        throws IOException {
    HScannerInterface s = t.obtainScanner(HConstants.COLUMN_FAMILY_ARRAY, HConstants.EMPTY_START_ROW,
            System.currentTimeMillis(), null);
    try {/*from  w w w. j  a v a 2  s .c  o m*/
        HStoreKey curKey = new HStoreKey();
        TreeMap<Text, byte[]> curVals = new TreeMap<Text, byte[]>();
        while (s.next(curKey, curVals)) {
            HRegionInfo hri = Writables.getHRegionInfoOrNull(curVals.get(HConstants.COL_REGIONINFO));
            if (hri == null) {
                continue;
            }
            // Make sure I get the parent.
            if (hri.getRegionName().toString().equals(parent.getRegionName().toString())) {
                return curVals;
            }
        }
        return null;
    } finally {
        s.close();
    }
}

From source file:org.apache.hadoop.raid.CorruptFileCounterServlet.java

public static String getFailedFiles(long window, TreeMap<Long, BlockFixStatus> countersMap, String path,
        String infoAddr) throws UnsupportedEncodingException {
    BlockFixStatus bfs = countersMap.get(window);
    String counterDisplay = "";
    if (bfs.failedPaths <= 0) {
        counterDisplay = "0";
    } else {//ww  w .  ja v  a  2s .c  o m
        StringBuffer url = new StringBuffer("http://" + infoAddr + "/corruptfilecounter");
        url.append("?root=");
        url.append(URLEncoder.encode(path, "UTF-8"));
        url.append("&recoverytime=" + RaidHistogram.RECOVERY_FAIL);
        counterDisplay = getHTMLLinksText(url.toString(), String.valueOf(bfs.failedPaths));
    }
    return counterDisplay;
}

From source file:org.apache.hadoop.raid.CorruptFileCounterServlet.java

public static String getRecoveryLag(long window, TreeMap<Long, BlockFixStatus> countersMap, String path,
        String infoAddr) throws UnsupportedEncodingException {
    BlockFixStatus bfs = countersMap.get(window);
    StringBuilder sb1 = new StringBuilder();
    for (int i = 0; i < bfs.percents.size(); i++) {
        if (i > 0) {
            sb1.append("/");
        }//from   ww  w.  j  a va 2 s . c  o m
        if (bfs.percentValues != null && bfs.percentValues[i] >= 0) {
            StringBuffer url = new StringBuffer("http://" + infoAddr + "/corruptfilecounter");
            url.append("?root=");
            url.append(URLEncoder.encode(path, "UTF-8"));
            url.append("&recoverytime=" + bfs.percentValues[i]);
            sb1.append(JspUtils.linkWithColor(String.valueOf(bfs.percentValues[i]), i, url.toString()));
        } else {
            sb1.append("-");
        }
    }
    return format(window) + " " + sb1.toString();
}

From source file:cfappserver.Bot.java

public static TreeMap<String, Integer> addToTree(String a, TreeMap<String, Integer> tm){
    if(tm.containsKey(a))tm.put(a, 1+tm.get(a));
    else tm.put(a, 1);
    return tm;/* w  w  w.j a v a 2s .  c o m*/
}

From source file:org.esxx.Response.java

static private void writeCSVRow(Context cx, CSVWriter csv, TreeMap<String, Integer> columns, Object r) {
    KeyValueWrapper row = new KeyValueWrapper(r);
    String[] fields = new String[columns.size()];

    for (Object c : row.getKeys()) {
        int idx = columns.get(StringUtil.toSortable(c));
        // System.out.println("Column " + Context.toString(c) + " has index " + idx);
        // System.out.println(Context.toString(row.getValue(cx, c)));
        fields[idx] = Context.toString(row.getValue(cx, c));
    }/*from  w  w w  .  ja v a  2s  .c o  m*/

    csv.writeNext(fields);
}

From source file:cht.Parser.java

@SuppressWarnings("unchecked")
static TreeMap<String, Object> myPut(TreeMap<String, Object> parentMap, String rootName, String leftName) {
    //int firstdot = key.indexOf(".");
    Object old = null;//from   www .  j  a v  a 2 s .  c  o m
    if (leftName == null || leftName.length() == 0) { // is Leaf
        // is string only
        parentMap.put(rootName, value);
        return parentMap;
    } else {
        TreeMap<String, Object> childMap = null;
        if (parentMap.get(rootName) != null) {
            old = parentMap.get(rootName);
            if (old instanceof TreeMap == false) {
                System.out.println("different type of key:" + rootName);
                return parentMap;
            }
            childMap = (TreeMap<String, Object>) old;
        } else {
            childMap = new TreeMap<String, Object>();
        }

        int firstdot = leftName.indexOf(".");
        String keyName, keyAttribute;
        if (firstdot > 0) {// c, d.f --> d, f
            keyName = leftName.substring(0, firstdot);
            keyAttribute = leftName.substring(firstdot + 1);
        } else {// c, d  -> d, null
            keyName = leftName;
            keyAttribute = null;
        }
        TreeMap<String, Object> object = myPut(childMap, keyName, keyAttribute);
        parentMap.put(rootName, object);
        return parentMap;
    }

}

From source file:cit360.sandbox.BackEndMenu.java

public static void ticketPrices() {
    TreeMap ageGroup = new TreeMap();

    // Add some ageGroup.
    ageGroup.put("Adult", 8.75);
    ageGroup.put("Child", 5.50);
    ageGroup.put("Senior Citizen", 5.25);
    ageGroup.put("Military Veteran", 5.00);

    // Iterate over all ageGroup, using the keySet method.
    for (Object key : ageGroup.keySet())
        System.out.println(key + " - $" + ageGroup.get(key));
    System.out.println();//from   w  w w . j  a v  a  2s .  c  om

    System.out.println("Highest key: " + ageGroup.lastKey());
    System.out.println("Lowest key: " + ageGroup.firstKey());

    System.out.println("\nPrinting all values: ");
    for (Object val : ageGroup.values())
        System.out.println("$" + val);
    System.out.println();

    // Clear all values.
    ageGroup.clear();

    // Equals to zero.
    System.out.println("After clear operation, size: " + ageGroup.size());
}