59
|
1 package cl.maps.duplex;
|
|
2
|
|
3
|
|
4 public class DuplexKey<A, B> {
|
|
5
|
|
6 private A aKey;
|
|
7 private B ownKey;
|
|
8
|
|
9 public DuplexKey(A aKey, B ownKey){
|
|
10 this.aKey = aKey;
|
|
11 this.ownKey = ownKey;
|
|
12 }
|
|
13
|
|
14 public boolean equalsAKey(A key){
|
|
15 if(aKey != null && key != null){
|
|
16 return aKey.equals(key);
|
|
17 }else if(aKey == null && key == null){
|
|
18 return true;
|
|
19 }
|
|
20 return false;
|
|
21 }
|
|
22
|
|
23 public boolean equalsOwnKey(B key){
|
|
24 if(ownKey != null && key != null){
|
|
25 return ownKey.equals(key);
|
|
26 }else if(ownKey == null && key == null){
|
|
27 return true;
|
|
28 }
|
|
29 return false;
|
|
30 }
|
|
31
|
|
32 public A getAKey() {
|
|
33 return aKey;
|
|
34 }
|
|
35
|
|
36 public void setAKey(A aKey) {
|
|
37 this.aKey = aKey;
|
|
38 }
|
|
39
|
|
40 public B getOwnKey() {
|
|
41 return ownKey;
|
|
42 }
|
|
43
|
|
44 public void setOwnKey(B ownKey) {
|
|
45 this.ownKey = ownKey;
|
|
46 }
|
|
47
|
|
48 @Override
|
|
49 public boolean equals(Object o){
|
|
50 if(o instanceof DuplexKey){
|
|
51 try {
|
|
52 DuplexKey<A, B> other = (DuplexKey<A, B>)o;
|
|
53
|
|
54 if(this.equalsOwnKey(other.getOwnKey()) &&
|
|
55 this.equalsAKey(other.getAKey())){
|
|
56 return true;
|
|
57 }
|
|
58 } catch (Exception e) {}
|
|
59
|
|
60 }
|
|
61 return false;
|
|
62 }
|
|
63
|
|
64 @Override
|
|
65 public int hashCode() {
|
|
66 final int prime = 31;
|
|
67 int result = 1;
|
|
68 result = prime * result + ((aKey == null) ? 0 : aKey.hashCode());
|
|
69 result = prime * result + ((ownKey == null) ? 0 : ownKey.hashCode());
|
|
70
|
|
71 return result;
|
|
72 }
|
|
73
|
|
74 @Override
|
|
75 public String toString() {
|
|
76 if (aKey == null || ownKey == null) {
|
|
77 return super.toString();
|
|
78 }
|
|
79 return "DuplexKey [" + aKey.toString() + ", " + ownKey.toString() + "]";
|
|
80 }
|
|
81 }
|