public static < ComponentT > Map < String , ComponentT > buildFromConfigProfiles ( InternalDriverContext context , DriverOption rootOption , Class < ComponentT > expectedSuperType , String ... defaultPackages ) { // Find out how many distinct configurations we have ListMultimap < Object , String > profilesByConfig = MultimapBuilder . hashKeys ( ) . arrayListValues ( ) . build ( ) ; for ( DriverExecutionProfile profile : context . getConfig ( ) . getProfiles ( ) . values ( ) ) { profilesByConfig . put ( profile . getComparisonKey ( rootOption ) , profile . getName ( ) ) ; } // Instantiate each distinct configuration, and associate it with the corresponding profiles ImmutableMap . Builder < String , ComponentT > result = ImmutableMap . builder ( ) ; for ( Collection < String > profiles : profilesByConfig . asMap ( ) . values ( ) ) { // Since all profiles use the same config, we can use any of them String profileName = profiles . iterator ( ) . next ( ) ; ComponentT policy = buildFromConfig ( context , profileName , classOption ( rootOption ) , expectedSuperType , defaultPackages ) . orElseThrow ( ( ) -> new IllegalArgumentException ( String . format ( "Missing configuration for %s in profile %s" , rootOption . getPath ( ) , profileName ) ) ) ; for ( String profile : profiles ) { result . put ( profile , policy ) ; } } return result . build ( ) ; }
Tries to create multiple instances of a class given options defined in the driver configuration and possibly overridden in profiles .