protected Collection < Method > sortMethods ( Collection < Method > methods ) { List < Method > list = new ArrayList <> ( methods ) ; Collections . sort ( list , ( m1 , m2 ) -> { int o1 = Integer . MAX_VALUE ; Order order1 = ClassUtil . getAnnotation ( m1 , Order . class ) ; if ( order1 != null ) { o1 = order1 . value ( ) ; } int o2 = Integer . MAX_VALUE ; Order order2 = ClassUtil . getAnnotation ( m2 , Order . class ) ; if ( order2 != null ) { o2 = order2 . value ( ) ; } if ( o1 == o2 ) { // same or unsorted, compare controller+method String s1 = Util . toString ( m1 ) ; String s2 = Util . toString ( m2 ) ; return s1 . compareTo ( s2 ) ; } if ( o1 < o2 ) { return - 1 ; } else { return 1 ; } } ) ; return list ; }
Sort the methods by their preferred order if specified .