Added method addAll to interface Map

This commit is contained in:
Eric Scharff
2007-09-26 09:19:21 -06:00
parent b02b98609e
commit 876b02f641
3 changed files with 18 additions and 3 deletions

View File

@ -33,8 +33,8 @@ public class Collections {
} }
static class SynchronizedCollection<T> implements Collection<T> { static class SynchronizedCollection<T> implements Collection<T> {
private final Object lock; protected final Object lock;
private final Collection<T> collection; protected final Collection<T> collection;
public SynchronizedCollection(Object lock, Collection<T> collection) { public SynchronizedCollection(Object lock, Collection<T> collection) {
this.lock = lock; this.lock = lock;
@ -73,6 +73,11 @@ public class Collections {
public SynchronizedSet(Object lock, Set<T> set) { public SynchronizedSet(Object lock, Set<T> set) {
super(lock, set); super(lock, set);
} }
public void addAll(Collection<T> c) {
synchronized (lock) { ((Set<T>)collection).addAll(c); }
}
} }
static class SynchronizedIterator<T> implements Iterator<T> { static class SynchronizedIterator<T> implements Iterator<T> {

View File

@ -286,6 +286,10 @@ public class HashMap<K, V> implements Map<K, V> {
return HashMap.this.size(); return HashMap.this.size();
} }
public void addAll(Collection<Entry<K, V>> c) {
throw new UnsupportedOperationException();
}
public boolean contains(Entry<K, V> e) { public boolean contains(Entry<K, V> e) {
return containsKey(e.getKey()); return containsKey(e.getKey());
} }
@ -316,6 +320,10 @@ public class HashMap<K, V> implements Map<K, V> {
return containsKey(key); return containsKey(key);
} }
public void addAll(Collection<K> c) {
throw new UnsupportedOperationException();
}
public boolean add(K key) { public boolean add(K key) {
return putCell(key, null) != null; return putCell(key, null) != null;
} }

View File

@ -1,3 +1,5 @@
package java.util; package java.util;
public interface Set<T> extends Collection<T> { } public interface Set<T> extends Collection<T> {
public void addAll(Collection<T> c);
}