-
Type:
Enhancement
-
Status: New
-
Priority:
P4
-
Resolution: Unresolved
-
Affects Version/s: 16
-
Fix Version/s: None
-
Component/s: core-libs
-
Labels:
-
Subcomponent:
-
CPU:generic
-
OS:generic
A DESCRIPTION OF THE PROBLEM :
Collections.sort(), Arrays.sort() and List.sort() should be overloaded to accept a function pointer like this:
public static <T, D> void sort(List<T> list, Function<? super T, D> detailGetter) {
if (detailGetter == null)
throw new IllegalArgumentException("detailGetter must not be null.");
Comparator< ? super D > comparator = (Comparator< ? super D >) Comparator.naturalOrder();
sort(list, (o1, i2) -> {
D detail1 = (o1 != null) ? detailGetter.apply(o1) : null;
D detail2 = (o2 != null) ? detailGetter.apply(o2) : null;
return comparator.compare(detail1, detail2);
} );
}
Similar for Arrays.sort() and List.sort()!
Collections.sort(), Arrays.sort() and List.sort() should be overloaded to accept a function pointer like this:
public static <T, D> void sort(List<T> list, Function<? super T, D> detailGetter) {
if (detailGetter == null)
throw new IllegalArgumentException("detailGetter must not be null.");
Comparator< ? super D > comparator = (Comparator< ? super D >) Comparator.naturalOrder();
sort(list, (o1, i2) -> {
D detail1 = (o1 != null) ? detailGetter.apply(o1) : null;
D detail2 = (o2 != null) ? detailGetter.apply(o2) : null;
return comparator.compare(detail1, detail2);
} );
}
Similar for Arrays.sort() and List.sort()!