public static < T extends CreateOptions > CreateOptions [ ] setOpt ( T newValue , CreateOptions ... opts ) { boolean alreadyInOpts = false ; if ( opts != null ) { for ( int i = 0 ; i < opts . length ; ++ i ) { if ( opts [ i ] . getClass ( ) == newValue . getClass ( ) ) { if ( alreadyInOpts ) throw new IllegalArgumentException ( "Multiple args with type " + newValue . getClass ( ) ) ; alreadyInOpts = true ; opts [ i ] = newValue ; } } } CreateOptions [ ] resultOpt = opts ; if ( ! alreadyInOpts ) { // no newValue in opt CreateOptions [ ] newOpts = new CreateOptions [ opts . length + 1 ] ; System . arraycopy ( opts , 0 , newOpts , 0 , opts . length ) ; newOpts [ opts . length ] = newValue ; resultOpt = newOpts ; } return resultOpt ; }
set an option