| 93 | } |
| 94 | |
| 95 | public List<E> sortByValue() { |
| 96 | List<Map.Entry<E, HistogramEntry>> list = new Vector<Map.Entry<E, HistogramEntry>>( |
| 97 | map.entrySet()); |
| 98 | |
| 99 | // Sort the list using an annonymous inner class implementing Comparator for |
| 100 | // the compare method |
| 101 | java.util.Collections.sort(list, |
| 102 | new Comparator<Map.Entry<E, HistogramEntry>>() { |
| 103 | public int compare(Map.Entry<E, HistogramEntry> entry, |
| 104 | Map.Entry<E, HistogramEntry> entry1) { |
| 105 | return (entry.getValue().equals(entry1.getValue()) ? 0 : (entry |
| 106 | .getValue().value > entry1.getValue().value ? 1 : -1)); |
| 107 | } |
| 108 | }); |
| 109 | List<E> list2 = new Vector<E>(); |
| 110 | for (Map.Entry<E, HistogramEntry> entry : list) { |
| 111 | list2.add(entry.getKey()); |
| 112 | } |
| 113 | return list2; |
| 114 | } |
| 115 | |
| 116 | public String toString(List<E> items) { |
| 117 | StringBuilder strBuilder = new StringBuilder(); |