59
|
1 package cl.maps.triple;
|
|
2
|
|
3 /**
|
|
4 * Unique ownKey. SrcKey and bKey not unique.
|
|
5 *
|
|
6 * @author jurzua
|
|
7 *
|
|
8 */
|
|
9 public class TripleKey<A, B, C> {
|
|
10
|
|
11 private A aKey;
|
|
12 private B bKey;
|
|
13 private C ownKey;
|
|
14
|
|
15 public TripleKey(A aKey, B label, C ownKey) {
|
|
16 this.aKey = aKey;
|
|
17 this.bKey = label;
|
|
18 this.ownKey = ownKey;
|
|
19 }
|
|
20
|
|
21 public boolean equalsAKey(A key) {
|
|
22 if (aKey != null && key != null) {
|
|
23 return aKey.equals(key);
|
|
24 } else if (aKey == null && key == null) {
|
|
25 return true;
|
|
26 }
|
|
27 return false;
|
|
28 }
|
|
29
|
|
30 public boolean equalsBKey(B key) {
|
|
31 if (bKey != null && key != null) {
|
|
32 return bKey.equals(key);
|
|
33 } else if (bKey == null && key == null) {
|
|
34 return true;
|
|
35 }
|
|
36 return false;
|
|
37 }
|
|
38
|
|
39 public boolean equalsOwnKey(C key) {
|
|
40 if (ownKey != null && key != null) {
|
|
41 return ownKey.equals(key);
|
|
42 } else if (ownKey == null && key == null) {
|
|
43 return true;
|
|
44 }
|
|
45 return false;
|
|
46 }
|
|
47
|
|
48 public A getAKey() {
|
|
49 return aKey;
|
|
50 }
|
|
51
|
|
52 public void setAKey(A aKey) {
|
|
53 this.aKey = aKey;
|
|
54 }
|
|
55
|
|
56 public B getBKey() {
|
|
57 return bKey;
|
|
58 }
|
|
59
|
|
60 public void setBKey(B bKey) {
|
|
61 this.bKey = bKey;
|
|
62 }
|
|
63
|
|
64 public C getOwnKey() {
|
|
65 return ownKey;
|
|
66 }
|
|
67
|
|
68 public void setOwnKey(C ownKey) {
|
|
69 this.ownKey = ownKey;
|
|
70 }
|
|
71
|
|
72 @Override
|
|
73 public boolean equals(Object o) {
|
|
74 if (o instanceof TripleKey) {
|
|
75 try {
|
|
76 TripleKey<A, B, C> other = (TripleKey<A, B, C>) o;
|
|
77
|
|
78 if (this.equalsOwnKey(other.getOwnKey())
|
|
79 && this.equalsAKey(other.getAKey())
|
|
80 && this.equalsBKey(other.getBKey())) {
|
|
81 return true;
|
|
82 }
|
|
83 } catch (Exception e) {
|
|
84 }
|
|
85 }
|
|
86 return false;
|
|
87 }
|
|
88
|
|
89 @Override
|
|
90 public int hashCode() {
|
|
91 final int prime = 31;
|
|
92 int result = 1;
|
|
93 result = prime * result + ((aKey == null) ? 0 : aKey.hashCode());
|
|
94 result = prime * result + ((bKey == null) ? 0 : bKey.hashCode());
|
|
95 result = prime * result + ((ownKey == null) ? 0 : ownKey.hashCode());
|
|
96
|
|
97 return result;
|
|
98 }
|
|
99
|
|
100 @Override
|
|
101 public String toString() {
|
|
102 if (aKey == null || bKey == null || ownKey == null) {
|
|
103 return super.toString();
|
|
104 }
|
|
105 return "TripleKey [" + aKey.toString() + ", " + bKey.toString() + ", "
|
|
106 + ownKey.toString() + "]";
|
|
107 }
|
|
108
|
|
109 }
|