Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected static void incrementValue(Map<Long, Integer> counters, Long toAdd) {
- Integer currValue = counters.get(toAdd);
- if (currValue == null)
- counters.put(toAdd, 1);
- else
- counters.put(toAdd, currValue+1);
- }
- static List sortByValue(Map map) {
- List list = new LinkedList(map.entrySet());
- Collections.sort(list, new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
- }
- });
- Map result = new LinkedHashMap();
- for (Iterator it = list.iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry)it.next();
- result.put(entry.getKey(), entry.getValue());
- }
- Collections.reverse(list);
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement