Package: MapChangeDetector
MapChangeDetector
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MapChangeDetector(ChangeDetector) |
|
|
|
|
|
||||||||||||||||||||
hasChanges(Object, Object) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
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.sessions.change;
19:
20: import java.util.Iterator;
21: import java.util.Map;
22:
23: class MapChangeDetector implements ChangeDetector {
24:
25: private final ChangeDetector changeDetector;
26:
27: MapChangeDetector(ChangeDetector changeDetector) {
28: this.changeDetector = changeDetector;
29: }
30:
31: @Override
32: public boolean hasChanges(Object clone, Object original) {
33:• assert clone != null;
34:• assert original != null;
35:
36: final Map<?, ?> cl = (Map<?, ?>) clone;
37: final Map<?, ?> orig = (Map<?, ?>) original;
38:• if (orig.size() != cl.size()) {
39: return true;
40: }
41: boolean changes = false;
42: final Iterator<?> it = orig.keySet().iterator();
43:• while (it.hasNext() && !changes) {
44: final Object origKey = it.next();
45:• if (!cl.containsKey(origKey)) {
46: return true;
47: }
48: final Object origVal = orig.get(origKey);
49: Object clVal = cl.get(origKey);
50:
51: changes = changeDetector.hasChanges(origVal, clVal);
52: }
53: return changes;
54: }
55: }