public static void sort ( List list , String sortBy , boolean ascending , boolean nullsFirst ) { if ( list == null || list . size ( ) == 0 ) { return ; } if ( sortBy . equals ( "this" ) ) { Collections . sort ( list , thisUniversalComparator ( ascending , nullsFirst ) ) ; return ; } Iterator iterator = list . iterator ( ) ; Object object = iterator . next ( ) ; Map < String , FieldAccess > fields = null ; if ( object != null ) { fields = BeanUtils . getFieldsFromObject ( object ) ; } else { while ( iterator . hasNext ( ) ) { object = iterator . next ( ) ; if ( object != null ) { fields = BeanUtils . getFieldsFromObject ( object ) ; break ; } } } if ( fields != null ) { final FieldAccess field = fields . get ( sortBy ) ; if ( field != null ) { Collections . sort ( list , Sorting . universalComparator ( field , ascending , nullsFirst ) ) ; } } }
Sort a list .