01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.util;
05:
06: import com.tc.object.SerializationUtil;
07: import com.tc.object.bytecode.ManagerUtil;
08:
09: import java.util.List;
10: import java.util.ListIterator;
11:
12: public class ListIteratorWrapper implements ListIterator {
13:
14: private final List list;
15: private final ListIterator realIterator;
16: private Object current;
17: private int currentIndex;
18:
19: public ListIteratorWrapper(List list, ListIterator realIterator) {
20: this .list = list;
21: this .realIterator = realIterator;
22: this .currentIndex = -1;
23: }
24:
25: public void add(Object arg0) {
26: ManagerUtil.checkWriteAccess(list);
27: currentIndex = nextIndex();
28: realIterator.add(arg0);
29: current = arg0;
30: ManagerUtil.logicalInvoke(list,
31: SerializationUtil.ADD_AT_SIGNATURE, new Object[] {
32: new Integer(currentIndex), arg0 });
33: }
34:
35: public boolean hasNext() {
36: return realIterator.hasNext();
37: }
38:
39: public boolean hasPrevious() {
40: return realIterator.hasPrevious();
41: }
42:
43: public Object next() {
44: currentIndex = nextIndex();
45: current = realIterator.next();
46: return current;
47: }
48:
49: public int nextIndex() {
50: return realIterator.nextIndex();
51: }
52:
53: public Object previous() {
54: currentIndex = previousIndex();
55: current = realIterator.previous();
56: return current;
57: }
58:
59: public int previousIndex() {
60: return realIterator.previousIndex();
61: }
62:
63: public void remove() {
64: ManagerUtil.checkWriteAccess(list);
65: realIterator.remove();
66: ManagerUtil.logicalInvoke(list,
67: SerializationUtil.REMOVE_AT_SIGNATURE,
68: new Object[] { new Integer(currentIndex) });
69: }
70:
71: public void set(Object arg0) {
72: ManagerUtil.checkWriteAccess(list);
73: realIterator.set(arg0);
74: current = arg0;
75: ManagerUtil.logicalInvoke(list,
76: SerializationUtil.SET_SIGNATURE, new Object[] {
77: new Integer(currentIndex), current });
78: }
79:
80: }
|