Beispiel #1
0
  public LinkedHashMap sortHashMapByValues(HashMap map) {
    List mapKeys = new ArrayList(map.keySet());
    List mapValues = new ArrayList(map.values());
    Collections.sort(mapValues);
    Collections.sort(mapKeys);

    LinkedHashMap sortedMap = new LinkedHashMap();

    Iterator valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
      Object val = valueIt.next();
      Iterator keyIt = mapKeys.iterator();

      while (keyIt.hasNext()) {
        Object key = keyIt.next();
        Object keyVal = map.get(key);
        if (keyVal == val) {
          sortedMap.put(key, keyVal);
        }
      }
    }
    return sortedMap;
  }
Beispiel #2
0
 public int defineStringLiteral(String s) {
   if (strings.containsKey(s)) return strings.get(s);
   else strings.put(s, ++strIndex);
   return strIndex;
 }