private void sortMethods ( ) { List < Method > methodList = new ArrayList <> ( methods ) ; Collections . sort ( methodList , new Comparator < Method > ( ) { @ Override public int compare ( Method m1 , Method m2 ) { int o1 = Integer . MAX_VALUE ; if ( m1 . isAnnotationPresent ( Order . class ) ) { Order order = m1 . getAnnotation ( Order . class ) ; o1 = order . value ( ) ; } int o2 = Integer . MAX_VALUE ; if ( m2 . isAnnotationPresent ( Order . class ) ) { Order order = m2 . getAnnotation ( Order . class ) ; o2 = order . value ( ) ; } if ( o1 == o2 ) { // same or unsorted, compare controller+method String s1 = m1 . getDeclaringClass ( ) . getName ( ) + "." + m1 . getName ( ) ; String s2 = m2 . getDeclaringClass ( ) . getName ( ) + "." + m2 . getName ( ) ; return s1 . compareTo ( s2 ) ; } if ( o1 < o2 ) { return - 1 ; } else { return 1 ; } } } ) ; methods = new LinkedHashSet <> ( methodList ) ; }
Sorts the methods into registration order