public < T > CallOptions withOption ( Key < T > key , T value ) { Preconditions . checkNotNull ( key , "key" ) ; Preconditions . checkNotNull ( value , "value" ) ; CallOptions newOptions = new CallOptions ( this ) ; int existingIdx = - 1 ; for ( int i = 0 ; i < customOptions . length ; i ++ ) { if ( key . equals ( customOptions [ i ] [ 0 ] ) ) { existingIdx = i ; break ; } } newOptions . customOptions = new Object [ customOptions . length + ( existingIdx == - 1 ? 1 : 0 ) ] [ 2 ] ; System . arraycopy ( customOptions , 0 , newOptions . customOptions , 0 , customOptions . length ) ; if ( existingIdx == - 1 ) { // Add a new option newOptions . customOptions [ customOptions . length ] = new Object [ ] { key , value } ; } else { // Replace an existing option newOptions . customOptions [ existingIdx ] = new Object [ ] { key , value } ; } return newOptions ; }
Sets a custom option . Any existing value for the key is overwritten .