1 | |
package org.apache.ojb.odmg.collections; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import java.util.ListIterator; |
19 | |
|
20 | |
import org.apache.ojb.odmg.TransactionImpl; |
21 | |
import org.apache.ojb.odmg.RuntimeObject; |
22 | |
import org.odmg.Transaction; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
class DListIterator implements ListIterator |
30 | |
{ |
31 | |
protected ListIterator iter; |
32 | |
private DListImpl dlist; |
33 | |
private DListEntry currentEntry = null; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public DListIterator(DListImpl list) |
39 | |
{ |
40 | |
this.dlist = list; |
41 | |
this.iter = list.getElements().listIterator(); |
42 | |
} |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public DListIterator(DListImpl list, int index) |
48 | |
{ |
49 | |
this.dlist = list; |
50 | |
this.iter = list.getElements().listIterator(index); |
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public void add(Object obj) |
57 | |
{ |
58 | |
DListEntry entry = new DListEntry(this.dlist, obj); |
59 | |
entry.setPosition(this.nextIndex() - 1); |
60 | |
iter.add(entry); |
61 | |
|
62 | |
TransactionImpl tx = dlist.getTransaction(); |
63 | |
if (tx != null) |
64 | |
{ |
65 | |
RuntimeObject rt = new RuntimeObject(entry, tx, true); |
66 | |
tx.lockAndRegister(rt, Transaction.WRITE, false, tx.getRegistrationList()); |
67 | |
} |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public boolean hasNext() |
74 | |
{ |
75 | |
return iter.hasNext(); |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public boolean hasPrevious() |
82 | |
{ |
83 | |
return iter.hasPrevious(); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public Object next() |
90 | |
{ |
91 | |
currentEntry = ((DListEntry) iter.next()); |
92 | |
return currentEntry.getRealSubject(); |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public int nextIndex() |
99 | |
{ |
100 | |
return iter.nextIndex(); |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public Object previous() |
107 | |
{ |
108 | |
currentEntry = ((DListEntry) iter.previous()); |
109 | |
return currentEntry.getRealSubject(); |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public int previousIndex() |
116 | |
{ |
117 | |
return iter.previousIndex(); |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public void remove() |
124 | |
{ |
125 | |
iter.remove(); |
126 | |
TransactionImpl tx = dlist.getTransaction(); |
127 | |
if (tx != null) |
128 | |
{ |
129 | |
tx.markDelete(currentEntry); |
130 | |
} |
131 | |
currentEntry = null; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public void set(Object o) |
138 | |
{ |
139 | |
throw new UnsupportedOperationException("Method is not supported"); |
140 | |
|
141 | |
} |
142 | |
|
143 | |
} |