protected List < Command > buildCommandChain ( Config rootConfig , String configKey , Command finalChild , boolean ignoreNotifications ) { Preconditions . checkNotNull ( rootConfig ) ; Preconditions . checkNotNull ( configKey ) ; Preconditions . checkNotNull ( finalChild ) ; List < ? extends Config > commandConfigs = new Configs ( ) . getConfigList ( rootConfig , configKey , Collections . < Config > emptyList ( ) ) ; List < Command > commands = Lists . newArrayList ( ) ; Command currentParent = this ; Connector lastConnector = null ; for ( int i = 0 ; i < commandConfigs . size ( ) ; i ++ ) { boolean isLast = ( i == commandConfigs . size ( ) - 1 ) ; Connector connector = new Connector ( ignoreNotifications && isLast ) ; if ( isLast ) { connector . setChild ( finalChild ) ; } Config cmdConfig = commandConfigs . get ( i ) ; Command cmd = buildCommand ( cmdConfig , currentParent , connector ) ; commands . add ( cmd ) ; if ( i > 0 ) { lastConnector . setChild ( cmd ) ; } connector . setParent ( cmd ) ; currentParent = connector ; lastConnector = connector ; } return commands ; }
Factory method to create the chain of commands rooted at the given rootConfig . The last command in the chain will feed records into finalChild .