/** * Remove the first value mapped to the given key. * * @param key the key * @return the value * @throws IndexOutOfBoundsException if there are no values for the given key */ default String removeFirst(String key) { return remove(key, 0); }
public boolean remove(final Object o) { return o instanceof String && Attributes.this.remove((String) o); }
/** * Remove all the values for the given key between the {@code from} index (inclusive) and the {@code to} index * (exclusive). * * @param key the key * @param from the start index (inclusive) * @param to the end index (exclusive) * @throws IndexOutOfBoundsException if {@code idx} is less than 0 or greater than or equal to {@code size(key)} */ default void removeRange(String key, int from, int to) { for (int i = to - 1; i >= from; i --) { remove(key, i); } }
public String remove(final int index) { return attributes.remove(key, index); }
public void clear() { attributes.remove(key); }
/** * Remove the first occurrence of the given value under the given key, if any. * * @param key the key * @param value the value to remove * @return {@code true} if the value was found and removed, {@code false} otherwise */ default boolean removeFirst(String key, String value) { final int idx = indexOf(key, value); return idx >= 0 && remove(key, idx, value); }
/** * Remove the last value mapped to the given key. * * @param key the key * @return the value * @throws IndexOutOfBoundsException if there are no values for the given key */ default String removeLast(String key) { return remove(key, size(key) - 1); }
/** * Remove the last occurrence of the given value under the given key, if any. * * @param key the key * @param value the value to remove * @return {@code true} if the value was found and removed, {@code false} otherwise */ default boolean removeLast(String key, String value) { final int idx = lastIndexOf(key, value); return idx >= 0 && remove(key, idx, value); }
/** * Remove the mapping for the given key at the given position if it matches the given existing value. All later * entries for that key are shifted up to fill in the gap left by the removed element. * * @param key the key * @param idx the index * @param value the expected previous mapping value * @return {@code true} if the value matched and was removed, {@code false} otherwise * @throws IndexOutOfBoundsException if {@code idx} is less than 0 or greater than or equal to {@code size(key)} */ default boolean remove(String key, int idx, String value) { if (get(key, idx).equals(value)) { remove(key, idx); return true; } else { return false; } }
/** * Remove all values for the given key from this collection, copying the values into a list which is returned. * * @param key the key * @return the values as a list (not {@code null}) */ default List<String> copyAndRemove(String key) { final Entry values = get(key); List<String> copy = values.isEmpty() ? Collections.emptyList() : new ArrayList<>(values); remove(key); return copy; }
/** * Remove the all occurrences of the given value under the given key, if any. * * @param key the key * @param value the value to remove * @return {@code true} if the value was found and removed, {@code false} otherwise */ default boolean removeAll(String key, String value) { int idx = lastIndexOf(key, value); if (idx == -1) return false; while (idx >= 0) { remove(key, idx, value); idx = lastIndexOf(key, value); } return true; }
/** * Remove the first value mapped to the given key. * * @param key the key * @return the value * @throws IndexOutOfBoundsException if there are no values for the given key */ default String removeFirst(String key) { return remove(key, 0); }
/** * Remove the last value mapped to the given key. * * @param key the key * @return the value * @throws IndexOutOfBoundsException if there are no values for the given key */ default String removeLast(String key) { return remove(key, size(key) - 1); }
/** * Remove the last occurrence of the given value under the given key, if any. * * @param key the key * @param value the value to remove * @return {@code true} if the value was found and removed, {@code false} otherwise */ default boolean removeLast(String key, String value) { final int idx = lastIndexOf(key, value); return idx >= 0 && remove(key, idx, value); }
/** * Remove the first occurrence of the given value under the given key, if any. * * @param key the key * @param value the value to remove * @return {@code true} if the value was found and removed, {@code false} otherwise */ default boolean removeFirst(String key, String value) { final int idx = indexOf(key, value); return idx >= 0 && remove(key, idx, value); }
/** * Remove the last occurrence of the given value under the given key, if any. * * @param key the key * @param value the value to remove * @return {@code true} if the value was found and removed, {@code false} otherwise */ default boolean removeLast(String key, String value) { final int idx = lastIndexOf(key, value); return idx >= 0 && remove(key, idx, value); }
/** * Remove the last value mapped to the given key. * * @param key the key * @return the value * @throws IndexOutOfBoundsException if there are no values for the given key */ default String removeLast(String key) { return remove(key, size(key) - 1); }
/** * Remove all values for the given key from this collection, copying the values into a list which is returned. * * @param key the key * @return the values as a list (not {@code null}) */ default List<String> copyAndRemove(String key) { final Entry values = get(key); List<String> copy = values.isEmpty() ? Collections.emptyList() : new ArrayList<>(values); remove(key); return copy; }
/** * Remove all values for the given key from this collection, copying the values into a list which is returned. * * @param key the key * @return the values as a list (not {@code null}) */ default List<String> copyAndRemove(String key) { final Entry values = get(key); List<String> copy = values.isEmpty() ? Collections.emptyList() : new ArrayList<>(values); remove(key); return copy; }
/** * Remove all values for the given key from this collection, copying the values into a list which is returned. * * @param key the key * @return the values as a list (not {@code null}) */ default List<String> copyAndRemove(String key) { final Entry values = get(key); List<String> copy = values.isEmpty() ? Collections.emptyList() : new ArrayList<>(values); remove(key); return copy; }