Skip to content

Package: IndirectList$IndirectListIterator

IndirectList$IndirectListIterator

nameinstructionbranchcomplexitylinemethod
IndirectList.IndirectListIterator(IndirectList, ListIterator)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
add(Object)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
hasNext()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasPrevious()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
next()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
nextIndex()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
previous()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
previousIndex()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
remove()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
set(Object)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

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