1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package fulmine.util.reference;
17
18 import static fulmine.util.Utils.nullCheck;
19
20
21
22
23
24
25
26
27
28
29 public class DualValue<FIRST, SECOND>
30 {
31
32 protected Values values;
33
34 public DualValue(FIRST first, SECOND second)
35 {
36 this(new Values(first, second));
37 }
38
39 protected DualValue(Values values)
40 {
41 nullCheck(values, "No values provided");
42 this.values = values;
43 }
44
45
46
47
48
49
50 @SuppressWarnings("unchecked")
51 public FIRST getFirst()
52 {
53 return (FIRST) this.values.get(0);
54 }
55
56
57
58
59
60
61 @SuppressWarnings("unchecked")
62 public SECOND getSecond()
63 {
64 return (SECOND) this.values.get(1);
65 }
66
67 @Override
68 public final String toString()
69 {
70 return this.values.toString();
71 }
72
73 @Override
74 public final int hashCode()
75 {
76 final int prime = 31;
77 int result = 1;
78 result = prime * result + ((values == null) ? 0 : values.hashCode());
79 return result;
80 }
81
82 @SuppressWarnings("unchecked")
83 @Override
84 public final boolean equals(Object obj)
85 {
86 if (is.same(this, obj))
87 {
88 return true;
89 }
90 if (is.differentClass(this, obj))
91 {
92 return false;
93 }
94 final DualValue other = (DualValue) obj;
95 return is.eq(values, other.values);
96 }
97
98 }