package dblog; /** * Description: des * Author: zsx * CreateDate: 2020/4/16 20:54 */ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; class WrapList implements List { private LogList root; private List wrapped; public WrapList(LogList root, List wrapped) { this.root = root; this.wrapped = wrapped; } protected void beforeChange() { this.root.beforeChange(); } protected void afterAdd(E add) { this.root.afterAdd(add); } protected void beforeRemove(E remove) { this.root.beforeRemove(remove); } protected List getWrapped() { return this.wrapped; } public boolean add(E e) { this.beforeChange(); if (this.wrapped.add(e)) { this.afterAdd(e); return true; } else { return false; } } public void add(int index, E element) { this.beforeChange(); this.wrapped.add(index, element); this.afterAdd(element); } public boolean addAll(Collection c) { this.beforeChange(); if (!this.wrapped.addAll(c)) { return false; } else { Iterator var2 = c.iterator(); while(var2.hasNext()) { E e = (E)var2.next(); this.afterAdd(e); } return true; } } public boolean addAll(int index, Collection c) { this.beforeChange(); if (!this.wrapped.addAll(index, c)) { return false; } else { Iterator var3 = c.iterator(); while(var3.hasNext()) { E e = (E)var3.next(); this.afterAdd(e); } return true; } } public void clear() { this.beforeChange(); Iterator var1 = this.wrapped.iterator(); while(var1.hasNext()) { E e = (E)var1.next(); this.beforeRemove(e); } this.wrapped.clear(); } public boolean contains(Object o) { return this.wrapped.contains(o); } public boolean containsAll(Collection c) { return this.wrapped.containsAll(c); } public boolean equals(Object obj) { return this.wrapped.equals(obj); } public E get(int index) { E v = this.wrapped.get(index); return v; } public int hashCode() { return this.wrapped.hashCode(); } public int indexOf(Object o) { return this.wrapped.indexOf(o); } public boolean isEmpty() { return this.wrapped.isEmpty(); } public Iterator iterator() { return new WrapList.WrapIt(); } public int lastIndexOf(Object o) { return this.wrapped.lastIndexOf(o); } public ListIterator listIterator() { return new WrapList.WrapListIt(); } public ListIterator listIterator(int index) { return new WrapList.WrapListIt(index); } public E remove(int index) { this.beforeChange(); E removed = this.wrapped.remove(index); this.beforeRemove(removed); return removed; } public boolean remove(Object o) { int index = this.indexOf(o); if (index < 0) { return false; } else { this.remove(index); return true; } } public boolean removeAll(Collection c) { boolean modified = false; Iterator e = this.iterator(); while(e.hasNext()) { if (c.contains(e.next())) { e.remove(); modified = true; } } return modified; } public boolean retainAll(Collection c) { boolean modified = false; Iterator e = this.iterator(); while(e.hasNext()) { if (!c.contains(e.next())) { e.remove(); modified = true; } } return modified; } public E set(int index, E element) { this.beforeChange(); E removed = this.wrapped.set(index, element); this.beforeRemove(removed); this.afterAdd(element); return removed; } public int size() { return this.wrapped.size(); } public List subList(int fromIndex, int toIndex) { return new WrapList(this.root, this.wrapped.subList(fromIndex, toIndex)); } public Object[] toArray() { return this.wrapped.toArray(); } public X[] toArray(X[] a) { return this.wrapped.toArray(a); } public String toString() { return this.wrapped.toString(); } private class WrapListIt implements ListIterator { private ListIterator it; private E current; WrapListIt() { this.it = WrapList.this.wrapped.listIterator(); } WrapListIt(int index) { this.it = WrapList.this.wrapped.listIterator(index); } public void add(E e) { WrapList.this.beforeChange(); this.it.add(e); WrapList.this.afterAdd(e); } public boolean hasNext() { return this.it.hasNext(); } public boolean hasPrevious() { return this.it.hasPrevious(); } public E next() { return this.current = this.it.next(); } public int nextIndex() { return this.it.nextIndex(); } public E previous() { return this.current = this.it.previous(); } public int previousIndex() { return this.it.previousIndex(); } public void remove() { WrapList.this.beforeChange(); WrapList.this.beforeRemove(this.current); this.it.remove(); } public void set(E e) { WrapList.this.beforeChange(); WrapList.this.beforeRemove(this.current); this.it.set(e); WrapList.this.afterAdd(e); } } private class WrapIt implements Iterator { private Iterator it; private E current; private WrapIt() { this.it = WrapList.this.wrapped.iterator(); } public boolean hasNext() { return this.it.hasNext(); } public E next() { return this.current = this.it.next(); } public void remove() { WrapList.this.beforeChange(); WrapList.this.beforeRemove(this.current); this.it.remove(); } } }