sclass SynchronizedCollection implements Collection {
Collection c; // Backing Collection
Object mutex; // Object on which to synchronize
*() {} // for persistence
*(Collection c) {
this.c = Objects.requireNonNull(c);
mutex = this;
}
*(Collection c, Object mutex) {
this.c = Objects.requireNonNull(c);
this.mutex = Objects.requireNonNull(mutex);
}
public int size() {
synchronized (mutex) {return c.size();}
}
public boolean isEmpty() {
synchronized (mutex) {return c.isEmpty();}
}
public boolean contains(Object o) {
synchronized (mutex) {return c.contains(o);}
}
public Object[] toArray() {
synchronized (mutex) {return c.toArray();}
}
public T[] toArray(T[] a) {
synchronized (mutex) {return c.toArray(a);}
}
public Iterator iterator() {
return c.iterator(); // Must be manually synched by user!
}
public boolean add(A A) {
synchronized (mutex) {return c.add(A);}
}
public boolean remove(Object o) {
synchronized (mutex) {return c.remove(o);}
}
public boolean containsAll(Collection> coll) {
synchronized (mutex) {return c.containsAll(coll);}
}
public boolean addAll(Collection extends A> coll) {
synchronized (mutex) {return c.addAll(coll);}
}
public boolean removeAll(Collection> coll) {
synchronized (mutex) {return c.removeAll(coll);}
}
public boolean retainAll(Collection> coll) {
synchronized (mutex) {return c.retainAll(coll);}
}
public void clear() {
synchronized (mutex) {c.clear();}
}
public String toString() {
synchronized (mutex) {return c.toString();}
}
/*public void forEach(Consumer super A> consumer) {
synchronized (mutex) {c.forEach(consumer);}
}*/
/*public boolean removeIf(Predicate super A> filter) {
synchronized (mutex) {return c.removeIf(filter);}
}*/
@Override
public Spliterator spliterator() {
return c.spliterator(); // Must be manually synched by user!
}
/*public Stream stream() {
return c.stream(); // Must be manually synched by user!
}*/
/*public Stream parallelStream() {
return c.parallelStream(); // Must be manually synched by user!
}*/
}