Skip to content

Package: ChangeTrackingIndirectSet$IndirectSetIterator

ChangeTrackingIndirectSet$IndirectSetIterator

nameinstructionbranchcomplexitylinemethod
ChangeTrackingIndirectSet.IndirectSetIterator(ChangeTrackingIndirectSet, Iterator)
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%
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%
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%
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%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 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.proxy.change;
19:
20: import cz.cvut.kbss.jopa.sessions.UnitOfWork;
21:
22: import java.lang.reflect.Field;
23: import java.util.Collection;
24: import java.util.Iterator;
25: import java.util.Objects;
26: import java.util.Set;
27:
28: public class ChangeTrackingIndirectSet<E> extends ChangeTrackingIndirectCollection<Set<E>> implements Set<E> {
29:
30: private final Set<E> internalSet;
31:
32: public ChangeTrackingIndirectSet(Object owner, Field f, UnitOfWork uow, Set<E> referencedSet) {
33: super(owner, f, uow);
34: this.internalSet = Objects.requireNonNull(referencedSet);
35: }
36:
37: @Override
38: public int size() {
39: return internalSet.size();
40: }
41:
42: @Override
43: public boolean isEmpty() {
44: return internalSet.isEmpty();
45: }
46:
47: @Override
48: public boolean contains(Object o) {
49: return internalSet.contains(o);
50: }
51:
52: @Override
53: public Iterator<E> iterator() {
54: return new IndirectSetIterator<>(internalSet.iterator());
55: }
56:
57: @Override
58: public Object[] toArray() {
59: return internalSet.toArray();
60: }
61:
62: @Override
63: public <T> T[] toArray(T[] a) {
64: return internalSet.toArray(a);
65: }
66:
67: @Override
68: public boolean add(E e) {
69: boolean res = internalSet.add(e);
70: if (res) {
71: persistChange();
72: }
73: return res;
74: }
75:
76: @Override
77: public boolean remove(Object o) {
78: boolean res = internalSet.remove(o);
79: if (res) {
80: persistChange();
81: }
82: return res;
83: }
84:
85: @Override
86: public boolean containsAll(Collection<?> c) {
87: return internalSet.containsAll(c);
88: }
89:
90: @Override
91:
92: public boolean addAll(Collection<? extends E> c) {
93: boolean res = internalSet.addAll(c);
94: if (res) {
95: persistChange();
96: }
97: return res;
98: }
99:
100: @Override
101: public boolean retainAll(Collection<?> c) {
102: boolean res = internalSet.retainAll(c);
103: if (res) {
104: persistChange();
105: }
106: return res;
107: }
108:
109: @Override
110: public boolean removeAll(Collection<?> c) {
111: boolean res = internalSet.removeAll(c);
112: if (res) {
113: persistChange();
114: }
115: return res;
116: }
117:
118: @Override
119: public void clear() {
120: internalSet.clear();
121: persistChange();
122: }
123:
124: private class IndirectSetIterator<T> implements Iterator<T> {
125:
126: private final Iterator<T> iterator;
127:
128: private IndirectSetIterator(Iterator<T> iterator) {
129: this.iterator = iterator;
130: }
131:
132: @Override
133: public boolean hasNext() {
134: return iterator.hasNext();
135: }
136:
137: @Override
138: public T next() {
139: return iterator.next();
140: }
141:
142: @Override
143: public void remove() {
144: iterator.remove();
145: ChangeTrackingIndirectSet.this.persistChange();
146: }
147: }
148:
149: @Override
150: public Set<E> unwrap() {
151: return internalSet;
152: }
153:
154: @Override
155: public boolean equals(Object o) {
156: if (o instanceof Set) {
157: if (o instanceof ChangeTrackingIndirectSet) {
158: return internalSet.equals(((ChangeTrackingIndirectSet) o).internalSet);
159: }
160: return internalSet.equals(o);
161: }
162: return false;
163: }
164:
165: @Override
166: public int hashCode() {
167: return internalSet.hashCode();
168: }
169:
170: @Override
171: public String toString() {
172: return internalSet.toString();
173: }
174: }