Skip to content

Package: ChangeDetectors

ChangeDetectors

nameinstructionbranchcomplexitylinemethod
ChangeDetectors(MetamodelProvider)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
hasChanges(Object, Object)
M: 0 C: 52
100%
M: 0 C: 18
100%
M: 0 C: 10
100%
M: 0 C: 11
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.sessions.change;
16:
17: import cz.cvut.kbss.jopa.sessions.MetamodelProvider;
18:
19: import java.util.Collection;
20: import java.util.Map;
21:
22: class ChangeDetectors implements ChangeDetector {
23:
24: private final MetamodelProvider metamodelProvider;
25:
26: private final ChangeDetector mapChangeDetector;
27: private final ChangeDetector collectionChangeDetector;
28: private final ChangeDetector managedTypeDector;
29:
30: ChangeDetectors(MetamodelProvider metamodelProvider) {
31: this.metamodelProvider = metamodelProvider;
32: this.mapChangeDetector = new MapChangeDetector(this);
33: this.collectionChangeDetector = new CollectionChangeDetector(this, metamodelProvider);
34: this.managedTypeDector = new ManagedTypeChangeDetector(metamodelProvider);
35: }
36:
37: @Override
38: public boolean hasChanges(Object clone, Object original) {
39:• if ((clone == null && original != null) || (clone != null && original == null)) {
40: return true;
41: }
42:• if (clone == null) {
43: return false;
44: }
45:
46:• if (metamodelProvider.isEntityType(clone.getClass())) {
47: return managedTypeDector.hasChanges(clone, original);
48:• } else if (clone instanceof Collection) {
49: return collectionChangeDetector.hasChanges(clone, original);
50:• } else if (clone instanceof Map) {
51: return mapChangeDetector.hasChanges(clone, original);
52: }
53:• return !clone.equals(original);
54: }
55: }