KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > ListIteratorWrapper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util;
5
6 import com.tc.object.SerializationUtil;
7 import com.tc.object.bytecode.ManagerUtil;
8
9 import java.util.List JavaDoc;
10 import java.util.ListIterator JavaDoc;
11
12 public class ListIteratorWrapper implements ListIterator JavaDoc {
13
14   private final List JavaDoc list;
15   private final ListIterator JavaDoc realIterator;
16   private Object JavaDoc current;
17   private int currentIndex;
18
19   public ListIteratorWrapper(List JavaDoc list, ListIterator JavaDoc realIterator) {
20     this.list = list;
21     this.realIterator = realIterator;
22     this.currentIndex = -1;
23   }
24
25   public void add(Object JavaDoc arg0) {
26     ManagerUtil.checkWriteAccess(list);
27     currentIndex = nextIndex();
28     realIterator.add(arg0);
29     current = arg0;
30     ManagerUtil.logicalInvoke(list, SerializationUtil.ADD_AT_SIGNATURE,
31                               new Object JavaDoc[] { new Integer JavaDoc(currentIndex), arg0 });
32   }
33
34   public boolean hasNext() {
35     return realIterator.hasNext();
36   }
37
38   public boolean hasPrevious() {
39     return realIterator.hasPrevious();
40   }
41
42   public Object JavaDoc next() {
43     currentIndex = nextIndex();
44     current = realIterator.next();
45     return current;
46   }
47
48   public int nextIndex() {
49     return realIterator.nextIndex();
50   }
51
52   public Object JavaDoc previous() {
53     currentIndex = previousIndex();
54     current = realIterator.previous();
55     return current;
56   }
57
58   public int previousIndex() {
59     return realIterator.previousIndex();
60   }
61
62   public void remove() {
63     ManagerUtil.checkWriteAccess(list);
64     realIterator.remove();
65     ManagerUtil.logicalInvoke(list, SerializationUtil.REMOVE_AT_SIGNATURE, new Object JavaDoc[] { new Integer JavaDoc(currentIndex) });
66   }
67
68   public void set(Object JavaDoc arg0) {
69     ManagerUtil.checkWriteAccess(list);
70     realIterator.set(arg0);
71     current = arg0;
72     ManagerUtil.logicalInvoke(list, SerializationUtil.SET_SIGNATURE,
73                               new Object JavaDoc[] { new Integer JavaDoc(currentIndex), current });
74   }
75
76 }
77
Popular Tags