MCPcopy Create free account
hub / github.com/grpc/grpc-java / remove

Method remove

api/src/main/java/io/grpc/Metadata.java:378–399  ·  view source on GitHub ↗

Removes the first occurrence of value for key. @param key key for value @param value value @return true if value removed; false if value was not present @throws NullPointerException if key or value is null

(Key<T> key, T value)

Source from the content-addressed store, hash-verified

376 * @throws NullPointerException if {@code key} or {@code value} is null
377 */
378 public <T> boolean remove(Key<T> key, T value) {
379 Preconditions.checkNotNull(key, "key");
380 Preconditions.checkNotNull(value, "value");
381 for (int i = 0; i < size; i++) {
382 if (!bytesEqual(key.asciiName(), name(i))) {
383 continue;
384 }
385 T stored = valueAsT(i, key);
386 if (!value.equals(stored)) {
387 continue;
388 }
389 int writeIdx = i * 2;
390 int readIdx = (i + 1) * 2;
391 int readLen = len() - readIdx;
392 System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen);
393 size -= 1;
394 name(size, null);
395 value(size, (byte[]) null);
396 return true;
397 }
398 return false;
399 }
400
401 /** Remove all values for the given key. If there were no values, {@code null} is returned. */
402 public <T> Iterable<T> removeAll(Key<T> key) {

Callers 2

testMutationsMethod · 0.95

Calls 8

bytesEqualMethod · 0.95
nameMethod · 0.95
valueAsTMethod · 0.95
lenMethod · 0.95
valueMethod · 0.95
checkNotNullMethod · 0.80
asciiNameMethod · 0.80
equalsMethod · 0.45

Tested by 2

testMutationsMethod · 0.76