public static SortedMap < PackageDoc , SortedSet < ClassDoc > > sortClassesPerPackage ( final ClassDoc ... classDocs ) { final SortedMap < PackageDoc , SortedSet < ClassDoc > > toReturn = new TreeMap <> ( Comparators . PACKAGE_NAME_COMPARATOR ) ; if ( classDocs != null ) { Arrays . stream ( classDocs ) . forEach ( current -> { // Retrieve (or create) the SortedSet of ClassDocs for the current PackageDocs. final SortedSet < ClassDoc > classDocsForCurrentPackage = toReturn . computeIfAbsent ( current . containingPackage ( ) , k -> new TreeSet <> ( Comparators . CLASS_NAME_COMPARATOR ) ) ; // Add the current ClassDoc to the SortedSet. classDocsForCurrentPackage . add ( current ) ; } ) ; } // All Done. return toReturn ; }
Sorts all given ClassDocs into a SortedMap keyed by their respective PackageDocs .