@ SafeVarargs private final List < BaseInvoker > union ( List < BaseInvoker > ... theInvokersLists ) { List < BaseInvoker > haveOne = null ; boolean haveMultiple = false ; for ( List < BaseInvoker > nextInvokerList : theInvokersLists ) { if ( nextInvokerList == null || nextInvokerList . isEmpty ( ) ) { continue ; } if ( haveOne == null ) { haveOne = nextInvokerList ; } else { haveMultiple = true ; } } if ( haveOne == null ) { return Collections . emptyList ( ) ; } List < BaseInvoker > retVal ; if ( haveMultiple == false ) { // The global list doesn't need to be sorted every time since it's sorted on // insertion each time. Doing so is a waste of cycles.. if ( haveOne == theInvokersLists [ 0 ] ) { retVal = haveOne ; } else { retVal = new ArrayList <> ( haveOne ) ; retVal . sort ( Comparator . naturalOrder ( ) ) ; } } else { retVal = Arrays . stream ( theInvokersLists ) . filter ( t -> t != null ) . flatMap ( t -> t . stream ( ) ) . sorted ( ) . collect ( Collectors . toList ( ) ) ; } return retVal ; }
First argument must be the global invoker list!!