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)
| 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) { |