Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8257199

Collections.sort(), Arrays.sort() and List.sort() with function pointer

    XMLWordPrintable

    Details

      Description

      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()!


        Attachments

          Activity

            People

            Assignee:
            smarks Stuart Marks
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: