Skip to content

Package: MapChangeDetector

MapChangeDetector

nameinstructionbranchcomplexitylinemethod
MapChangeDetector(ChangeDetector)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
hasChanges(Object, Object)
M: 10 C: 54
84%
M: 4 C: 8
67%
M: 4 C: 3
43%
M: 1 C: 16
94%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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 java.util.Iterator;
18: import java.util.Map;
19:
20: class MapChangeDetector implements ChangeDetector {
21:
22: private final ChangeDetector changeDetector;
23:
24: MapChangeDetector(ChangeDetector changeDetector) {
25: this.changeDetector = changeDetector;
26: }
27:
28: @Override
29: public boolean hasChanges(Object clone, Object original) {
30:• assert clone != null;
31:• assert original != null;
32:
33: final Map<?, ?> cl = (Map<?, ?>) clone;
34: final Map<?, ?> orig = (Map<?, ?>) original;
35:• if (orig.size() != cl.size()) {
36: return true;
37: }
38: boolean changes = false;
39: final Iterator<?> it = orig.keySet().iterator();
40:• while (it.hasNext() && !changes) {
41: final Object origKey = it.next();
42:• if (!cl.containsKey(origKey)) {
43: return true;
44: }
45: final Object origVal = orig.get(origKey);
46: Object clVal = cl.get(origKey);
47:
48: changes = changeDetector.hasChanges(origVal, clVal);
49: }
50: return changes;
51: }
52: }