• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kit-data-manager / pit-service / #474

29 Jan 2025 04:42PM UTC coverage: 77.85%. First build
#474

Pull #271

github

web-flow
Merge 76236f5ae into 4c17b004d
Pull Request #271: Separate resolver from the configured system

83 of 116 new or added lines in 6 files covered. (71.55%)

956 of 1228 relevant lines covered (77.85%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/handle/HandleDiff.java
1
package edu.kit.datamanager.pit.pidsystem.impl.handle;
2

3
import edu.kit.datamanager.pit.common.PidUpdateException;
4
import net.handle.hdllib.HandleValue;
5

6
import java.util.ArrayList;
7
import java.util.Collection;
8
import java.util.Map;
9

10
/**
11
 * Given two Value Maps, it splits the values in those which have been added,
12
 * updated or removed.
13
 * Using this lists, an update can be applied to the old record, to bring it to
14
 * the state of the new record.
15
 */
16
class HandleDiff {
17
    private final Collection<HandleValue> toAdd = new ArrayList<>();
1✔
18
    private final Collection<HandleValue> toUpdate = new ArrayList<>();
1✔
19
    private final Collection<HandleValue> toRemove = new ArrayList<>();
1✔
20

21
    HandleDiff(
22
            final Map<Integer, HandleValue> recordOld,
23
            final Map<Integer, HandleValue> recordNew
24
    ) throws PidUpdateException {
1✔
25
        for (Map.Entry<Integer, HandleValue> old : recordOld.entrySet()) {
1✔
26
            boolean wasRemoved = !recordNew.containsKey(old.getKey());
1✔
27
            if (wasRemoved) {
1✔
28
                // if a row in the record is not available anymore, we need to delete it
29
                toRemove.add(old.getValue());
1✔
30
            } else {
31
                // otherwise, we should go and update it.
32
                // we could also check for equality, but this is the safe and easy way.
33
                // (the handlevalue classes can be complicated and we'd have to check their
34
                // equality implementation)
35
                toUpdate.add(recordNew.get(old.getKey()));
1✔
36
            }
37
        }
1✔
38
        for (Map.Entry<Integer, HandleValue> e : recordNew.entrySet()) {
1✔
39
            boolean isNew = !recordOld.containsKey(e.getKey());
1✔
40
            if (isNew) {
1✔
41
                // if there is a record which is not in the oldRecord, we need to add it.
42
                toAdd.add(e.getValue());
1✔
43
            }
44
        }
1✔
45

46
        // runtime testing to avoid messing up record states.
47
        String exceptionMsg = "DIFF NOT VALID. Type: %s. Value: %s";
1✔
48
        for (HandleValue v : toRemove) {
1✔
49
            boolean valid = recordOld.containsValue(v) && !recordNew.containsKey(v.getIndex());
1✔
50
            if (!valid) {
1✔
NEW
51
                String message = String.format(exceptionMsg, "Remove", v.toString());
×
NEW
52
                throw new PidUpdateException(message);
×
53
            }
54
        }
1✔
55
        for (HandleValue v : toAdd) {
1✔
56
            boolean valid = !recordOld.containsKey(v.getIndex()) && recordNew.containsValue(v);
1✔
57
            if (!valid) {
1✔
NEW
58
                String message = String.format(exceptionMsg, "Add", v);
×
NEW
59
                throw new PidUpdateException(message);
×
60
            }
61
        }
1✔
62
        for (HandleValue v : toUpdate) {
1✔
63
            boolean valid = recordOld.containsKey(v.getIndex()) && recordNew.containsValue(v);
1✔
64
            if (!valid) {
1✔
NEW
65
                String message = String.format(exceptionMsg, "Update", v);
×
NEW
66
                throw new PidUpdateException(message);
×
67
            }
68
        }
1✔
69
    }
1✔
70

71
    public HandleValue[] added() {
72
        return this.toAdd.toArray(new HandleValue[] {});
1✔
73
    }
74

75
    public HandleValue[] updated() {
76
        return this.toUpdate.toArray(new HandleValue[] {});
1✔
77
    }
78

79
    public HandleValue[] removed() {
80
        return this.toRemove.toArray(new HandleValue[] {});
1✔
81
    }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc