public static < T extends CatalogType > List < T > getSortedCatalogItems ( CatalogMap < T > items , String sortFieldName ) { assert ( items != null ) ; assert ( sortFieldName != null ) ; // build a treemap based on the field value TreeMap < Object , T > map = new TreeMap <> ( ) ; boolean hasField = false ; for ( T item : items ) { // check the first time through for the field if ( hasField == false ) { hasField = ArrayUtils . contains ( item . getFields ( ) , sortFieldName ) ; } assert ( hasField == true ) ; map . put ( item . getField ( sortFieldName ) , item ) ; } // create a sorted list from the map ArrayList < T > retval = new ArrayList <> ( ) ; for ( T item : map . values ( ) ) { retval . add ( item ) ; } return retval ; }
Given a set of catalog items return a sorted list of them sorted by the value of a specified field . The field is specified by name . If the field doesn t exist trip an assertion . This is primarily used to sort a table s columns or a procedure s parameters .