public static < T > Operator < T > createUnionCascade ( Operator < T > input1 , Operator < T > ... input2 ) { // return cases where we don't need a union if ( input2 == null || input2 . length == 0 ) { return input1 ; } else if ( input2 . length == 1 && input1 == null ) { return input2 [ 0 ] ; } TypeInformation < T > type = null ; if ( input1 != null ) { type = input1 . getOperatorInfo ( ) . getOutputType ( ) ; } else if ( input2 . length > 0 && input2 [ 0 ] != null ) { type = input2 [ 0 ] . getOperatorInfo ( ) . getOutputType ( ) ; } else { throw new IllegalArgumentException ( "Could not determine type information from inputs." ) ; } // Otherwise construct union cascade Union < T > lastUnion = new Union < T > ( new BinaryOperatorInformation < T , T , T > ( type , type , type ) ) ; int i ; if ( input2 [ 0 ] == null ) { throw new IllegalArgumentException ( "The input may not contain null elements." ) ; } lastUnion . setFirstInput ( input2 [ 0 ] ) ; if ( input1 != null ) { lastUnion . setSecondInput ( input1 ) ; i = 1 ; } else { if ( input2 [ 1 ] == null ) { throw new IllegalArgumentException ( "The input may not contain null elements." ) ; } lastUnion . setSecondInput ( input2 [ 1 ] ) ; i = 2 ; } for ( ; i < input2 . length ; i ++ ) { Union < T > tmpUnion = new Union < T > ( new BinaryOperatorInformation < T , T , T > ( type , type , type ) ) ; tmpUnion . setSecondInput ( lastUnion ) ; if ( input2 [ i ] == null ) { throw new IllegalArgumentException ( "The input may not contain null elements." ) ; } tmpUnion . setFirstInput ( input2 [ i ] ) ; lastUnion = tmpUnion ; } return lastUnion ; }
Takes a single Operator and a list of operators and creates a cascade of unions of this inputs if needed . If not needed there was only one operator as input then this operator is returned .