Last active
December 15, 2015 05:29
-
-
Save tckb/5209400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Map sortByComparator(Map singleCutTable) { | |
List list = new LinkedList(singleCutTable.entrySet()); | |
// sort list based on comparator | |
Collections.sort(list, new Comparator() { | |
public int compare(Object o1, Object o2) { | |
Map.Entry obj1Entry = (Map.Entry) o1.getValue(); | |
Map.Entry obj2Entry = (Map.Entry) o2.getValue(); | |
HashSet<CoreFragment> set1 = Ob1Entry.value(); | |
HashSet<CoreFragment> set2 = Ob2Entry.value(); | |
// Now compare set1 and set2 | |
// check if at least one element in set1 matches with set2 | |
int result; | |
if (!Collections.disjoint(set1, set2) ){ | |
result = 0; | |
else{ | |
result =1; | |
} | |
} | |
return result; | |
} | |
}); | |
// put sorted list into map again | |
//LinkedHashMap make sure order in which keys were inserted | |
Map sortedMap = new LinkedHashMap(); | |
for (java.util.Iterator it = list.iterator(); it.hasNext();) { | |
Map.Entry entry = (Map.Entry) it.next(); | |
sortedMap.put(entry.getKey(), entry.getValue()); | |
} | |
return sortedMap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment