@Override
        public int compare(Integer i1, Integer i2) {
            SortNode n1 = countMap.get(i1);
            SortNode n2 = countMap.get(i2);
            if(n1.count > n2.count){
                return -1;
            }else if(n1.count < n2.count){
                return 1;
            }else{
                return n1.firstIndex < n2.firstIndex ? -1 : 1;
            }
        }
http://www.geeksforgeeks.org/sort-elements-by-frequency/
src/com/interview/sort/SortArrayByFrequence.java