List<String> () { if (pathIndex != null && pathIndex.size() == myMacroMap.size()) { return pathIndex; } List<Map.Entry<String, String>> entries = new ArrayList<>(myMacroMap.entrySet()); Object2IntMap<String> weights = new Object2IntOpenHashMap<>(entries.size()); for (Map.Entry<String, String> entry : entries) { weights.put(entry.getKey(), getIndex(entry.getValue()) * 512 + stripPrefix(entry.getKey())); } entries.sort((o1, o2) -> weights.getInt(o2.getKey()) - weights.getInt(o1.getKey())); pathIndex = ContainerUtil.map(entries, entry -> entry.getKey()); return pathIndex; }