sclass SynchronizedList extends SynchronizedCollection implements List { final List list; SynchronizedList(List list) { super(list); this.list = list; } SynchronizedList(List list, Object mutex) { super(list, mutex); this.list = list; } public boolean equals(Object o) { if (this == o) return true; synchronized (mutex) {return list.equals(o);} } public int hashCode() { synchronized (mutex) {return list.hashCode();} } public E get(int index) { synchronized (mutex) {return list.get(index);} } public E set(int index, E element) { synchronized (mutex) {return list.set(index, element);} } public void add(int index, E element) { synchronized (mutex) {list.add(index, element);} } public E remove(int index) { synchronized (mutex) {return list.remove(index);} } public int indexOf(Object o) { synchronized (mutex) {return list.indexOf(o);} } public int lastIndexOf(Object o) { synchronized (mutex) {return list.lastIndexOf(o);} } public boolean addAll(int index, Collection c) { synchronized (mutex) {return list.addAll(index, c);} } public ListIterator listIterator() { return list.listIterator(); // Must be manually synched by user } public ListIterator listIterator(int index) { return list.listIterator(index); // Must be manually synched by user } public List subList(int fromIndex, int toIndex) { synchronized (mutex) { return new SynchronizedList<>(list.subList(fromIndex, toIndex), mutex); } } /*public void replaceAll(UnaryOperator operator) { synchronized (mutex) {list.replaceAll(operator);} }*/ public void sort(Comparator c) { synchronized (mutex) {list.sort(c);} } }