Returns a sorted list of indices of the specified double array. Modified from: http://stackoverflow.com/questions/951848 by N.Vischer.
(double[] values)
| 296 | Modified from: http://stackoverflow.com/questions/951848 by N.Vischer. |
| 297 | */ |
| 298 | public static int[] rank(double[] values) { |
| 299 | int n = values.length; |
| 300 | final Integer[] indexes = new Integer[n]; |
| 301 | final Double[] data = new Double[n]; |
| 302 | for (int i=0; i<n; i++) { |
| 303 | indexes[i] = Integer.valueOf(i); |
| 304 | data[i] = Double.valueOf(values[i]); |
| 305 | } |
| 306 | Arrays.sort(indexes, new Comparator<Integer>() { |
| 307 | public int compare(final Integer o1, final Integer o2) { |
| 308 | return data[o1].compareTo(data[o2]); |
| 309 | } |
| 310 | }); |
| 311 | int[] indexes2 = new int[n]; |
| 312 | for (int i=0; i<n; i++) |
| 313 | indexes2[i] = indexes[i].intValue(); |
| 314 | return indexes2; |
| 315 | } |
| 316 | |
| 317 | /** Returns a sorted list of indices of the specified String array. */ |
| 318 | public static int[] rank(final String[] data) { |
no test coverage detected