Package: IndirectList$IndirectListIterator
IndirectList$IndirectListIterator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
IndirectList.IndirectListIterator(IndirectList, ListIterator) |
|
|
|
|
|
||||||||||||||||||||
add(Object) |
|
|
|
|
|
||||||||||||||||||||
hasNext() |
|
|
|
|
|
||||||||||||||||||||
hasPrevious() |
|
|
|
|
|
||||||||||||||||||||
next() |
|
|
|
|
|
||||||||||||||||||||
nextIndex() |
|
|
|
|
|
||||||||||||||||||||
previous() |
|
|
|
|
|
||||||||||||||||||||
previousIndex() |
|
|
|
|
|
||||||||||||||||||||
remove() |
|
|
|
|
|
||||||||||||||||||||
set(Object) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.adapters;
14:
15: import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
16:
17: import java.lang.reflect.Field;
18: import java.util.*;
19:
20: public class IndirectList<E> extends IndirectCollection<List<E>> implements List<E> {
21:
22: private final List<E> internalList;
23:
24: /**
25: * No-arg constructor to allow clone building.
26: */
27: IndirectList() {
28: this.internalList = new ArrayList<>();
29: }
30:
31: /**
32: * Create new indirect list backed by the specified referenced list.
33: *
34: * @param owner Owner of the list
35: * @param f The field holding this list
36: * @param uow Persistence context the owner belongs to
37: * @param referencedList The list to reference
38: * @throws NullPointerException If the {@code referencedList} is null
39: */
40: public IndirectList(Object owner, Field f, UnitOfWorkImpl uow, List<E> referencedList) {
41: super(owner, f, uow);
42: this.internalList = Objects.requireNonNull(referencedList);
43: }
44:
45: @Override
46: public boolean add(E arg0) {
47: final boolean res = internalList.add(arg0);
48: persistChange(); // There is always a change
49: return res;
50: }
51:
52: @Override
53: public void add(int arg0, E arg1) {
54: internalList.add(arg0, arg1);
55: persistChange();
56: }
57:
58: @Override
59: public boolean addAll(Collection<? extends E> c) {
60: boolean res = internalList.addAll(c);
61: if (res) {
62: persistChange();
63: }
64: return res;
65: }
66:
67: @Override
68: public boolean addAll(int index, Collection<? extends E> c) {
69: boolean res = internalList.addAll(index, c);
70: if (res) {
71: persistChange();
72: }
73: return res;
74: }
75:
76: @Override
77: public void clear() {
78: internalList.clear();
79: persistChange();
80: }
81:
82: @Override
83: public boolean contains(Object arg0) {
84: return internalList.contains(arg0);
85: }
86:
87: @Override
88: public boolean containsAll(Collection<?> arg0) {
89: return internalList.containsAll(arg0);
90: }
91:
92: @Override
93: public E get(int arg0) {
94: return internalList.get(arg0);
95: }
96:
97: @Override
98: public int indexOf(Object arg0) {
99: return internalList.indexOf(arg0);
100: }
101:
102: @Override
103: public boolean isEmpty() {
104: return internalList.isEmpty();
105: }
106:
107: @Override
108: public Iterator<E> iterator() {
109: return new IndirectIterator(internalList.iterator());
110: }
111:
112: @Override
113: public int lastIndexOf(Object arg0) {
114: return internalList.lastIndexOf(arg0);
115: }
116:
117: @Override
118: public ListIterator<E> listIterator() {
119: return new IndirectListIterator(internalList.listIterator());
120: }
121:
122: @Override
123: public ListIterator<E> listIterator(int arg0) {
124: return new IndirectListIterator(internalList.listIterator(arg0));
125: }
126:
127: @Override
128: public boolean remove(Object arg0) {
129: boolean res = internalList.remove(arg0);
130: if (res) {
131: persistChange();
132: }
133: return res;
134: }
135:
136: @Override
137: public E remove(int arg0) {
138: E elem = internalList.remove(arg0);
139: persistChange();
140: return elem;
141: }
142:
143: @Override
144: public boolean removeAll(Collection<?> arg0) {
145: boolean res = internalList.removeAll(arg0);
146: if (res) {
147: persistChange();
148: }
149: return res;
150: }
151:
152: @Override
153: public boolean retainAll(Collection<?> arg0) {
154: boolean res = internalList.retainAll(arg0);
155: if (res) {
156: persistChange();
157: }
158: return res;
159: }
160:
161: @Override
162: public E set(int arg0, E arg1) {
163: E elem = internalList.set(arg0, arg1);
164: persistChange();
165: return elem;
166: }
167:
168: @Override
169: public int size() {
170: return internalList.size();
171: }
172:
173: @Override
174: public List<E> subList(int fromIndex, int toIndex) {
175: return new IndirectList<>(owner, field, persistenceContext, internalList.subList(fromIndex, toIndex));
176: }
177:
178: @Override
179: public Object[] toArray() {
180: return internalList.toArray();
181: }
182:
183: @Override
184: public <T> T[] toArray(T[] arg0) {
185: return internalList.toArray(arg0);
186: }
187:
188: @Override
189: public List<E> getReferencedCollection() {
190: return internalList;
191: }
192:
193: @Override
194: public boolean equals(Object o) {
195: if (o instanceof List) {
196: if (o instanceof IndirectList) {
197: return internalList.equals(((IndirectList) o).internalList);
198: }
199: return internalList.equals(o);
200: }
201: return false;
202: }
203:
204: @Override
205: public int hashCode() {
206: return internalList.hashCode();
207: }
208:
209: @Override
210: public String toString() {
211: return internalList.toString();
212: }
213:
214: private class IndirectIterator implements Iterator<E> {
215:
216: private final Iterator<E> it;
217:
218: private IndirectIterator(Iterator<E> it) {
219: this.it = it;
220: }
221:
222: @Override
223: public boolean hasNext() {
224: return it.hasNext();
225: }
226:
227: @Override
228: public E next() {
229: return it.next();
230: }
231:
232: @Override
233: public void remove() {
234: it.remove();
235: IndirectList.this.persistChange();
236: }
237: }
238:
239: private class IndirectListIterator implements ListIterator<E> {
240:
241: private final ListIterator<E> lit;
242:
243: private IndirectListIterator(ListIterator<E> lit) {
244: this.lit = lit;
245: }
246:
247: @Override
248: public boolean hasNext() {
249: return lit.hasNext();
250: }
251:
252: @Override
253: public E next() {
254: return lit.next();
255: }
256:
257: @Override
258: public boolean hasPrevious() {
259: return lit.hasPrevious();
260: }
261:
262: @Override
263: public E previous() {
264: return lit.previous();
265: }
266:
267: @Override
268: public int nextIndex() {
269: return lit.nextIndex();
270: }
271:
272: @Override
273: public int previousIndex() {
274: return lit.previousIndex();
275: }
276:
277: @Override
278: public void remove() {
279: lit.remove();
280: IndirectList.this.persistChange();
281: }
282:
283: @Override
284: public void set(E e) {
285: lit.set(e);
286: IndirectList.this.persistChange();
287: }
288:
289: @Override
290: public void add(E e) {
291: lit.add(e);
292: IndirectList.this.persistChange();
293: }
294: }
295: }