Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c554cb

Browse files
replaceAll + docs
1 parent 01b6f48 commit 4c554cb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ it with the given value and returns null, else returns the current value.
5858
* `default boolean remove(Object key, Object value)` - Removes the entry
5959
for the specified key only if it is currently mapped to the specified value.
6060

61-
* `default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)`
61+
* `default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)` -
62+
Replaces each entry's value with the result of invoking the given
63+
function on that entry until all entries have been processed or the
64+
function throws an exception
65+
6266
* `default boolean replace(K key, V oldValue, V newValue)`
6367
* `default V replace(K key, V value)`
6468
* `default V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction)`

‎src/test/java/MapModifyingTest.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,19 @@ public void remove_sameKey_sameValue() {
6464

6565
assertTrue(map.isEmpty());
6666
}
67+
68+
@Test
69+
public void replaceAll() {
70+
Map<Integer, String> map = new HashMap<>();
71+
72+
map.put(1, "1");
73+
map.put(2, "2");
74+
map.put(3, "3");
75+
76+
map.replaceAll((k, v) -> v + "-updated");
77+
78+
assertThat(map.get(1), is("1-updated"));
79+
assertThat(map.get(2), is("2-updated"));
80+
assertThat(map.get(3), is("3-updated"));
81+
}
6782
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /