Example usage for java.util SortedMap entrySet

List of usage examples for java.util SortedMap entrySet

Introduction

In this page you can find the example usage for java.util SortedMap entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:org.dcm4chee.archive.conf.defaults.DeepEquals.java

/**
 * Deeply compare two SortedMap instances.  This method walks the Maps in order,
 * taking advantage of the fact that they Maps are SortedMaps.
 * @param dualKey SortedMaps//ww  w  .j  a v a  2 s. c  o  m
 * @param stack add items to compare to the Stack (Stack versus recursion)
 * @param visited Set containing items that have already been compared, to prevent cycles.
 * @return false if the Maps are for certain not equals.  'true' indicates that 'on the surface' the maps
 * are equal, however, it will place the contents of the Maps on the stack for further comparisons.
 */
private static boolean compareSortedMap(DualKey dualKey, LinkedList stack, Set visited) {

    SortedMap map1 = (SortedMap) dualKey._key1;
    SortedMap map2 = (SortedMap) dualKey._key2;

    // Same instance check already performed...

    if (map1.size() != map2.size()) {
        return false;
    }

    Iterator i1 = map1.entrySet().iterator();
    Iterator i2 = map2.entrySet().iterator();

    while (i1.hasNext()) {
        Map.Entry entry1 = (Map.Entry) i1.next();
        Map.Entry entry2 = (Map.Entry) i2.next();

        // Must split the Key and Value so that Map.Entry's equals() method is not used.
        DualKey dk = new DualKey(entry1.getKey(), entry2.getKey(), dualKey);
        if (!visited.contains(dk)) { // Push Keys for further comparison
            stack.addFirst(dk);
        }

        dk = new DualKey(entry1.getValue(), entry2.getValue(), dualKey);
        if (!visited.contains(dk)) { // Push values for further comparison
            stack.addFirst(dk);
        }
    }
    return true;
}

From source file:org.opennms.netmgt.mib2events.Mib2Events.java

public static String getTrapEventDescr(MibValueSymbol trapValueSymbol) {
    String description = ((SnmpType) trapValueSymbol.getType()).getDescription();

    // FIXME There a lot of detail here (like removing the last \n) that can go away when we don't need to match mib2opennms exactly

    final String descrStartingNewlines = description.replaceAll("^", "\n<p>");

    final String descrEndingNewlines = descrStartingNewlines.replaceAll("$", "</p>\n");

    //final String descrTabbed = descrEndingNewlines.replaceAll("(?m)^", "\t");
    //final StringBuffer dbuf = new StringBuffer(descrTabbed);

    final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
        dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
    }// w  w w  .  ja v a  2 s .c o  m

    //if (dbuf.lastIndexOf("\n") != -1) {
    //    dbuf.insert(dbuf.lastIndexOf("\n") + 1, '\t');
    //}

    //final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    //dbuf.append("\n");

    dbuf.append("<table>");
    dbuf.append("\n");
    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
        dbuf.append("\t<tr><td><b>\n\n\t").append(vb.getName());
        dbuf.append("</b></td><td>\n\t%parm[#").append(vbNum).append("]%;</td><td><p>");

        SnmpObjectType snmpObjectType = ((SnmpObjectType) ((ObjectIdentifierValue) vb).getSymbol().getType());
        if (snmpObjectType.getSyntax().getClass().equals(IntegerType.class)) {
            IntegerType integerType = (IntegerType) snmpObjectType.getSyntax();

            if (integerType.getAllSymbols().length > 0) {
                SortedMap<Integer, String> map = new TreeMap<Integer, String>();
                for (MibValueSymbol sym : integerType.getAllSymbols()) {
                    map.put(new Integer(sym.getValue().toString()), sym.getName());
                }

                dbuf.append("\n");
                for (Entry<Integer, String> entry : map.entrySet()) {
                    dbuf.append("\t\t").append(entry.getValue()).append("(").append(entry.getKey())
                            .append(")\n");
                }
                dbuf.append("\t");
            }
        }

        dbuf.append("</p></td></tr>\n");
        vbNum++;
    }

    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
        dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
    }
    dbuf.append("</table>\n\t");

    return dbuf.toString();
}

From source file:wzw.util.TestUtils.java

/**
 * /*  ww w. j  a va  2s  .c  o m*/
 * <p>public?
 *       ?main??</p>
 * @author Zeven on 2008-2-1
 * @param clazz
 */
public static void testAllMethod(Class<?> clazz) {

    try {
        String[] defaultMethods = { "equals", "wait", "getClass", "notify", "hashCode", "toString", "main",
                "notifyAll" };

        SortedMap<String, String> map = new TreeMap<String, String>();
        Method[] md = clazz.getMethods();
        for (int i = 0, j = 1; i < md.length; i++) {
            if (ArrayUtils.contains(defaultMethods, md[i].getName())) {
                continue;
            }
            map.put("" + j++, md[i].getName());
        }
        map.put("q", "quit from class test.");

        //get a br
        BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
        //read characters
        Iterator<Map.Entry<String, String>> it = null;
        Map.Entry<String, String> mapen = null;
        String val = null;
        String k;
        System.out.println("please chose ...");
        it = map.entrySet().iterator();
        do {
            while (it.hasNext()) {
                mapen = it.next();
                System.out.println(mapen.getKey() + "\t" + mapen.getValue());
            }
            System.out.print("> ");
            k = br1.readLine();
            if ("q".equals(k)) {
                break;
            }
            if (map.get(k) != null) {
                val = map.get(k).toString();
                System.out.println("**************** begin *" + val + "* ...");
                clazz.getMethod(val, null).invoke(null, null);
                System.out.println("**************** *" + val + "* test success.");
                continue;
            }

            System.out.println("invalid choose,please choose again!");
            System.out.println("please chose ...");
            it = map.entrySet().iterator();

        } while (true);

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

From source file:co.cask.cdap.data.tools.ReplicationStatusTool.java

private static void checkHDFSReplicationComplete(SortedMap<String, String> masterChecksumMap)
        throws IOException {
    boolean complete;
    SortedMap<String, String> slaveChecksumMap = getClusterChecksumMap();

    // Verify that all files on Master are present on Slave. Ignore any extra files on Slave. This could
    // happen when old snapshot files are pruned by CDAP on the Master cluster.
    complete = !checkDifferences(masterChecksumMap.keySet(), slaveChecksumMap.keySet(), "File");

    for (Map.Entry<String, String> checksumEntry : masterChecksumMap.entrySet()) {
        String file = checksumEntry.getKey();
        String masterChecksum = checksumEntry.getValue();
        String slaveChecksum = slaveChecksumMap.get(file);

        if (slaveChecksum != null && !masterChecksum.equals(slaveChecksum)) {
            System.out.println("Master Checksum " + masterChecksum + " for File " + file
                    + " does not match with" + " Slave Checksum " + slaveChecksum);
            complete = false;/* ww  w.  ja  va 2s.c  o m*/
        }
    }

    if (complete) {
        // If checksums match for all files.
        System.out.println("Master and Slave Checksums match. HDFS Replication is complete.");
    } else {
        System.out.println("HDFS Replication is NOT Complete.");
    }
}

From source file:org.apache.hadoop.io.TestSequenceFile.java

private static void checkSort(FileSystem fs, int count, int seed, Path file) throws IOException {
    LOG.info("sorting " + count + " records in memory for debug");
    RandomDatum.Generator generator = new RandomDatum.Generator(seed);
    SortedMap<RandomDatum, RandomDatum> map = new TreeMap<RandomDatum, RandomDatum>();
    for (int i = 0; i < count; i++) {
        generator.next();/*from   ww w  .  j ava  2 s.co m*/
        RandomDatum key = generator.getKey();
        RandomDatum value = generator.getValue();
        map.put(key, value);
    }

    LOG.debug("checking order of " + count + " records");
    RandomDatum k = new RandomDatum();
    RandomDatum v = new RandomDatum();
    Iterator<Map.Entry<RandomDatum, RandomDatum>> iterator = map.entrySet().iterator();
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, file.suffix(".sorted"), conf);
    for (int i = 0; i < count; i++) {
        Map.Entry<RandomDatum, RandomDatum> entry = iterator.next();
        RandomDatum key = entry.getKey();
        RandomDatum value = entry.getValue();

        reader.next(k, v);

        if (!k.equals(key))
            throw new RuntimeException("wrong key at " + i);
        if (!v.equals(value))
            throw new RuntimeException("wrong value at " + i);
    }

    reader.close();
    LOG.debug("sucessfully checked " + count + " records");
}

From source file:org.onehippo.repository.documentworkflow.DocumentWorkflowTest.java

@SuppressWarnings("unchecked")
protected static Map<?, ?> sortMap(Map<?, ?> map) {
    if (!(map instanceof SortedMap)) {
        SortedMap<Object, Object> sorted = new TreeMap<>(map);
        for (Map.Entry<Object, Object> entry : sorted.entrySet()) {
            if (entry.getValue() instanceof Map) {
                entry.setValue(sortMap((Map<Object, Object>) entry.getValue()));
            }//  w ww  .  j  a v a  2 s .co  m
        }
        return sorted;
    }
    return map;
}

From source file:org.apache.http.contrib.auth.AWSScheme.java

/**
 * Returns the canonicalized AMZ headers.
 *
 * @param headers//from   w  w  w  . j  a v a  2 s  .  co  m
 *            The list of request headers.
 * @return The canonicalized AMZ headers.
 */
private static String getCanonicalizedAmzHeaders(final Header[] headers) {
    StringBuilder sb = new StringBuilder();
    Pattern spacePattern = Pattern.compile("\\s+");

    // Create a lexographically sorted list of headers that begin with x-amz
    SortedMap<String, String> amzHeaders = new TreeMap<String, String>();
    for (Header header : headers) {
        String name = header.getName().toLowerCase();

        if (name.startsWith("x-amz-")) {
            String value = "";

            if (amzHeaders.containsKey(name))
                value = amzHeaders.get(name) + "," + header.getValue();
            else
                value = header.getValue();

            // All newlines and multiple spaces must be replaced with a
            // single space character.
            Matcher m = spacePattern.matcher(value);
            value = m.replaceAll(" ");

            amzHeaders.put(name, value);
        }
    }

    // Concatenate all AMZ headers
    for (Entry<String, String> entry : amzHeaders.entrySet()) {
        sb.append(entry.getKey()).append(':').append(entry.getValue()).append("\n");
    }

    return sb.toString();
}

From source file:trendulo.web.controller.TrendsController.java

@RequestMapping(value = "/trends/{dateGranularity}/{dateString}", method = RequestMethod.GET)
public @ResponseBody Trends getTrends(@PathVariable String dateGranularity, @PathVariable String dateString) {

    log.debug("DATE GRANULARITY:" + dateGranularity + " TIMESTAMP:" + dateString);
    Trends trends = new Trends();
    trends.setDateString("March 01, 2012");
    List<Trend> trendList = new ArrayList<Trend>();
    SortedMap<Integer, String> trendMap = queryService.getTrends(dateString, 25);
    for (Entry<Integer, String> entry : trendMap.entrySet()) {
        trendList.add(0, trends.new Trend(entry.getValue(), entry.getKey()));
    }/*  w  w  w. j  a  va2s  .  com*/
    trends.setTrends(trendList);
    return trends;
}

From source file:net.footballpredictions.footballstats.swing.LeaguePositionGraph.java

/**
 * Plot league positions by date.//from w  w w  .j a  va2s.  c om
 */
public void updateGraph(Object[] teams, LeagueSeason data) {
    assert teams.length > 0 : "Must be at least one team selected.";
    TimeSeriesCollection dataSet = new TimeSeriesCollection();
    for (Object team : teams) {
        String teamName = (String) team;
        TimeSeries positionSeries = new TimeSeries(teamName);

        SortedMap<Date, Integer> positions = data.getTeam(teamName).getLeaguePositions();
        for (Map.Entry<Date, Integer> entry : positions.entrySet()) {
            positionSeries.add(new Day(entry.getKey()), entry.getValue());
        }
        dataSet.addSeries(positionSeries);
    }

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // Title
            messageResources.getString("graphs.date"),
            messageResources.getString("combo.GraphType.LEAGUE_POSITION"), dataSet, true, // Legend.
            false, // Tooltips.
            false); // URLs.
    chart.getXYPlot().getRangeAxis().setInverted(true);
    chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chart.getXYPlot().getRangeAxis().setRangeWithMargins(1, data.getTeamNames().size());
    chart.getLegend().setPosition(legendPosition);
    setChart(chart);
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsChart.java

private XYSeries createSeries(final String title, SortedMap<Double, Double> result) {
    XYSeries series = new XYSeries(title, false, true);
    for (Entry<Double, Double> entry : result.entrySet()) {
        series.add(entry.getKey(), entry.getValue());
    }/*from w w  w .ja  v  a2 s.co m*/
    return series;
}