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