Skip to content

Package: ObjectChangeSetImpl

ObjectChangeSetImpl

nameinstructionbranchcomplexitylinemethod
ObjectChangeSetImpl(Object, Object, Descriptor)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
addChangeRecord(ChangeRecord)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getChangedObject()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getChanges()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getCloneObject()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getEntityContext()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getEntityDescriptor()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getObjectClass()
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%
hasChanges()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isNew()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setNew(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2020 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.sessions.change;
14:
15: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
16: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
17: import cz.cvut.kbss.jopa.sessions.ChangeRecord;
18: import cz.cvut.kbss.jopa.sessions.ObjectChangeSet;
19:
20: import java.net.URI;
21: import java.util.*;
22:
23: public class ObjectChangeSetImpl implements ObjectChangeSet {
24:
25: // The object the changes are bound to
26: private final Object changedObject;
27:
28: // Reference to the clone
29: private final Object cloneObject;
30:
31: // A map of attributeName-ChangeRecord pairs to easily find the attributes to change
32: private final Map<FieldSpecification<?, ?>, ChangeRecord> attributesToChange = new HashMap<>();
33:
34: // Does this change set represent a new object
35: private boolean isNew;
36:
37: private final Descriptor descriptor;
38:
39: public ObjectChangeSetImpl(Object changedObject, Object cloneObject, Descriptor descriptor) {
40: this.changedObject = Objects.requireNonNull(changedObject);
41: this.cloneObject = Objects.requireNonNull(cloneObject);
42: this.descriptor = Objects.requireNonNull(descriptor);
43: }
44:
45: @Override
46: public void addChangeRecord(ChangeRecord record) {
47: Objects.requireNonNull(record);
48: attributesToChange.put(record.getAttribute(), record);
49: }
50:
51: @Override
52: public Set<ChangeRecord> getChanges() {
53: return new HashSet<>(attributesToChange.values());
54: }
55:
56: @Override
57: public boolean hasChanges() {
58:• return !attributesToChange.isEmpty();
59: }
60:
61: @Override
62: public Class<?> getObjectClass() {
63: return cloneObject.getClass();
64: }
65:
66: @Override
67: public Object getChangedObject() {
68: return changedObject;
69: }
70:
71: @Override
72: public Object getCloneObject() {
73: return cloneObject;
74: }
75:
76: @Override
77: public void setNew(boolean isNew) {
78: this.isNew = isNew;
79: }
80:
81: @Override
82: public boolean isNew() {
83: return isNew;
84: }
85:
86: @Override
87: public URI getEntityContext() {
88: return descriptor.getSingleContext().orElse(null);
89: }
90:
91: @Override
92: public Descriptor getEntityDescriptor() {
93: return descriptor;
94: }
95: }