1 package de.dlr.shepard.util;
2
3 import com.fasterxml.jackson.annotation.JsonIgnore;
4 import java.util.List;
5
6 @FunctionalInterface
7 public interface HasId {
8
9
10
11
12
13 @JsonIgnore
14 String getUniqueId();
15
16
17
18
19
20
21
22
23
24
25 static boolean equalsHelper(List<? extends HasId> a, List<? extends HasId> b) {
26 if (a == null && b == null) return true;
27 if (a == null || b == null) return false;
28 if (a.size() != b.size()) return false;
29
30 for (int i = 0; i < a.size(); i++) {
31 if (!equalsHelper(a.get(i), b.get(i))) return false;
32 }
33 return true;
34 }
35
36
37
38
39
40
41
42
43
44 static boolean equalsHelper(HasId a, HasId b) {
45 if (a == null && b == null) return true;
46 if (a == null || b == null) return false;
47 return a.getUniqueId().equals(b.getUniqueId());
48 }
49
50
51
52
53
54
55
56
57 static int hashcodeHelper(List<? extends HasId> a) {
58 if (a == null) return 0;
59 final int prime = 31;
60 int result = 1;
61 for (HasId element : a) {
62 result = prime * result + hashcodeHelper(element);
63 }
64 return result;
65 }
66
67
68
69
70
71
72
73
74 static int hashcodeHelper(HasId a) {
75 if (a == null) return 0;
76 return a.getUniqueId().hashCode();
77 }
78 }