public static long [ ] sortAndFilterThreadIdsByValue ( LongObjectMap map , int threadLimit ) { int max = Math . min ( threadLimit , map . size ( ) ) ; List < Map . Entry > list = new LinkedList ( map . entrySet ( ) ) ; Collections . sort ( list , new Comparator ( ) { @ Override public int compare ( Object o1 , Object o2 ) { return ( ( Comparable ) ( ( Map . Entry ) ( o2 ) ) . getValue ( ) ) . compareTo ( ( ( Map . Entry ) ( o1 ) ) . getValue ( ) ) ; } } ) ; long [ ] topTidArray = new long [ max ] ; int i = 0 ; for ( Map . Entry entry : list ) { topTidArray [ i ] = ( Long ) entry . getKey ( ) ; if ( ++ i >= max ) { break ; } } return topTidArray ; }
Sorts a Map by its values using natural ordering .