@Test public void basicTest() { List<Integer> a = Lists.newArrayList(); a.add(100); a.add(2); a.add(92); a.add(1); a.add(0); PartialSorter.partialSort(a, Lists.newArrayList(1, 3, 4), new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.compareTo(o2); } }); assertArrayEquals(a.toArray(), new Integer[] { 100, 0, 92, 1, 2 }); }
public static <T> void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c) { List<T> temp = Lists.newLinkedList(); for (int index : items) { temp.add(list.get(index)); } Collections.sort(temp, c); for (int i = 0; i < temp.size(); ++i) { list.set(items.get(i), temp.get(i)); } }
PartialSorter { public static <T> void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c) { List<T> temp = Lists.newLinkedList(); for (int index : items) { temp.add(list.get(index)); } Collections.sort(temp, c); for (int i = 0; i < temp.size(); ++i) { list.set(items.get(i), temp.get(i)); } } }
PartialSorter { public static <T> void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c) { List<T> temp = Lists.newLinkedList(); for (int index : items) { temp.add(list.get(index)); } Collections.sort(temp, c); for (int i = 0; i < temp.size(); ++i) { list.set(items.get(i), temp.get(i)); } }  }
PartialSorter { public static <T> void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c) { List<T> temp = Lists.newLinkedList(); for (int index : items) { temp.add(list.get(index)); } Collections.sort(temp, c); for (int i = 0; i < temp.size(); ++i) { list.set(items.get(i), temp.get(i)); } }  static void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c); }
PartialSorter { public static <T> void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c) { List<T> temp = Lists.newLinkedList(); for (int index : items) { temp.add(list.get(index)); } Collections.sort(temp, c); for (int i = 0; i < temp.size(); ++i) { list.set(items.get(i), temp.get(i)); } }  static void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c);  }