@Test public void removeIgnoresMissingValue() { Metadata m = new Metadata(); Key<String> key = GrpcUtil.USER_AGENT_KEY; boolean success = m.remove(key, "agent"); assertFalse(success); }
public <T> boolean remove(Key<T> key, T value) { Preconditions.checkNotNull(key, "key"); Preconditions.checkNotNull(value, "value"); for (int i = 0; i < size; i++) { if (!bytesEqual(key.asciiName(), name(i))) { continue; } @SuppressWarnings("unchecked") T stored = key.parseBytes(value(i)); if (!value.equals(stored)) { continue; } int writeIdx = i * 2; int readIdx = (i + 1) * 2; int readLen = len() - readIdx; System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen); size -= 1; name(size, null); value(size, null); return true; } return false; }
Metadata { public <T> boolean remove(Key<T> key, T value) { Preconditions.checkNotNull(key, "key"); Preconditions.checkNotNull(value, "value"); for (int i = 0; i < size; i++) { if (!bytesEqual(key.asciiName(), name(i))) { continue; } @SuppressWarnings("unchecked") T stored = key.parseBytes(value(i)); if (!value.equals(stored)) { continue; } int writeIdx = i * 2; int readIdx = (i + 1) * 2; int readLen = len() - readIdx; System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen); size -= 1; name(size, null); value(size, null); return true; } return false; } }
Metadata { public <T> boolean remove(Key<T> key, T value) { Preconditions.checkNotNull(key, "key"); Preconditions.checkNotNull(value, "value"); for (int i = 0; i < size; i++) { if (!bytesEqual(key.asciiName(), name(i))) { continue; } @SuppressWarnings("unchecked") T stored = key.parseBytes(value(i)); if (!value.equals(stored)) { continue; } int writeIdx = i * 2; int readIdx = (i + 1) * 2; int readLen = len() - readIdx; System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen); size -= 1; name(size, null); value(size, null); return true; } return false; } Metadata(byte[]... binaryValues);   Metadata(int usedNames, byte[]... binaryValues);  Metadata(); }
Metadata { public <T> boolean remove(Key<T> key, T value) { Preconditions.checkNotNull(key, "key"); Preconditions.checkNotNull(value, "value"); for (int i = 0; i < size; i++) { if (!bytesEqual(key.asciiName(), name(i))) { continue; } @SuppressWarnings("unchecked") T stored = key.parseBytes(value(i)); if (!value.equals(stored)) { continue; } int writeIdx = i * 2; int readIdx = (i + 1) * 2; int readLen = len() - readIdx; System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen); size -= 1; name(size, null); value(size, null); return true; } return false; } Metadata(byte[]... binaryValues);   Metadata(int usedNames, byte[]... binaryValues);  Metadata(); boolean containsKey(Key<?> key); @Nullable T get(Key<T> key); @Nullable Iterable<T> getAll(final Key<T> key); @SuppressWarnings("deprecation") // The String ctor is deprecated, but fast. Set<String> keys(); void put(Key<T> key, T value); boolean remove(Key<T> key, T value); Iterable<T> removeAll(Key<T> key); @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4691") void discardAll(Key<T> key); void merge(Metadata other); void merge(Metadata other, Set<Key<?>> keys); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 @Override String toString(); }
Metadata { public <T> boolean remove(Key<T> key, T value) { Preconditions.checkNotNull(key, "key"); Preconditions.checkNotNull(value, "value"); for (int i = 0; i < size; i++) { if (!bytesEqual(key.asciiName(), name(i))) { continue; } @SuppressWarnings("unchecked") T stored = key.parseBytes(value(i)); if (!value.equals(stored)) { continue; } int writeIdx = i * 2; int readIdx = (i + 1) * 2; int readLen = len() - readIdx; System.arraycopy(namesAndValues, readIdx, namesAndValues, writeIdx, readLen); size -= 1; name(size, null); value(size, null); return true; } return false; } Metadata(byte[]... binaryValues);   Metadata(int usedNames, byte[]... binaryValues);  Metadata(); boolean containsKey(Key<?> key); @Nullable T get(Key<T> key); @Nullable Iterable<T> getAll(final Key<T> key); @SuppressWarnings("deprecation") // The String ctor is deprecated, but fast. Set<String> keys(); void put(Key<T> key, T value); boolean remove(Key<T> key, T value); Iterable<T> removeAll(Key<T> key); @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4691") void discardAll(Key<T> key); void merge(Metadata other); void merge(Metadata other, Set<Key<?>> keys); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 @Override String toString(); static final String BINARY_HEADER_SUFFIX; static final BinaryMarshaller<byte[]> BINARY_BYTE_MARSHALLER; static final AsciiMarshaller<String> ASCII_STRING_MARSHALLER; }