/** * Find the top limit values using given comparator and place them as in a * full array sort, in descending order. * * @param array the array. * @param offset the offset. * @param limit the limit. * @param comp the comparator. */ public static <X> void sortTopN(X[] array, int offset, int limit, Comparator<? super X> comp) { partitionTopN(array, offset, limit, comp); Arrays.sort(array, offset, (int) Math.min((long) offset + limit, array.length), comp); }