Skip to content

Commit

Permalink
[COLLECTIONS-663] Update AbstractMultiValuedMap asMap()
Browse files Browse the repository at this point in the history
  • Loading branch information
dota17 committed Nov 6, 2019
1 parent 188c771 commit 84a2460
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ class AsMapEntrySetIterator extends AbstractIteratorDecorator<Map.Entry<K, Colle
public Map.Entry<K, Collection<V>> next() {
final Map.Entry<K, Collection<V>> entry = super.next();
final K key = entry.getKey();
return new UnmodifiableMapEntry<>(key, wrappedCollection(key));
final Collection<V> value = entry.getValue();
return new UnmodifiableMapEntry<>(key, value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,49 @@ public void testAsMapRemove() {
assertEquals(4, getMap().size());
}

public void testAsMapValues() {
if(!isAddSupported() || isHashSetValue()){
return;
}
final MultiValuedMap<K, V> multiMap = makeObject();
multiMap.put((K) "A", (V) "W");
multiMap.put((K) "A", (V) "X");
multiMap.put((K) "A", (V) "F");
multiMap.put((K) "B", (V) "Q");
multiMap.put((K) "B", (V) "Q");
multiMap.put((K) "B", (V) "L");
assertEquals("{A=[W, X, F], B=[Q, Q, L]}", multiMap.toString());
for(Collection<V> list : multiMap.asMap().values()){
for(Iterator<V> it = list.iterator(); it.hasNext(); ){
V i = it.next();
it.remove();
}
}
assertEquals("{A=[], B=[]}", multiMap.toString());
}

public void testAsMapEntrySet() {
if(!isAddSupported() || isHashSetValue()){
return;
}
final MultiValuedMap<K, V> multiMap = makeObject();
multiMap.put((K) "A", (V) "W");
multiMap.put((K) "A", (V) "X");
multiMap.put((K) "A", (V) "F");
multiMap.put((K) "B", (V) "Q");
multiMap.put((K) "B", (V) "Q");
multiMap.put((K) "B", (V) "L");
assertEquals("{A=[W, X, F], B=[Q, Q, L]}", multiMap.toString());
Map<K, Collection<V>> asMap = multiMap.asMap();
for(Map.Entry<K, Collection<V>> entry : asMap.entrySet()){
for(Iterator<V> it = entry.getValue().iterator(); it.hasNext(); ){
V str = it.next();
it.remove();
}
}
assertEquals("{A=[], B=[]}", multiMap.toString());
}

public void testMapIterator() {
resetEmpty();
MapIterator<K, V> mapIt = getMap().mapIterator();
Expand Down

0 comments on commit 84a2460

Please sign in to comment.