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 01b6f48

Browse files
remove(Object key, Object value) tests + doc
1 parent 9488578 commit 01b6f48

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ it with the given value and returns null, else returns the current value.
5555

5656
_Remark_: `map.putIfAbsent(1, null);` is OK
5757

58-
* `default boolean remove(Object key, Object value)`
58+
* `default boolean remove(Object key, Object value)` - Removes the entry
59+
for the specified key only if it is currently mapped to the specified value.
60+
5961
* `default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)`
6062
* `default boolean replace(K key, V oldValue, V newValue)`
6163
* `default V replace(K key, V value)`

‎src/test/java/MapModifyingTest.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import static org.hamcrest.CoreMatchers.is;
77
import static org.hamcrest.MatcherAssert.assertThat;
8+
import static org.junit.Assert.assertTrue;
89

910
/**
1011
* Created by mtumilowicz on 2018年11月09日.
@@ -41,4 +42,26 @@ public void putIfAbsent_mappedToNull() {
4142

4243
assertThat(map.get(1), is("1"));
4344
}
45+
46+
@Test
47+
public void remove_sameKey_differentValue() {
48+
Map<Integer, String> map = new HashMap<>();
49+
50+
map.put(1, "1");
51+
52+
map.remove(1, "2");
53+
54+
assertThat(map.get(1), is("1"));
55+
}
56+
57+
@Test
58+
public void remove_sameKey_sameValue() {
59+
Map<Integer, String> map = new HashMap<>();
60+
61+
map.put(1, "1");
62+
63+
map.remove(1, "1");
64+
65+
assertTrue(map.isEmpty());
66+
}
4467
}

0 commit comments

Comments
(0)

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