21 |
|
|
22 |
package nongnu.cashews.commons; |
package nongnu.cashews.commons; |
23 |
|
|
24 |
|
import java.io.Serializable; |
25 |
|
|
26 |
/** |
/** |
27 |
* A small helper class to pair up two arbitrary heterogenously-typed |
* A small helper class to pair up two arbitrary heterogenously-typed |
28 |
* values. This is where we wish we had a tuple data type. |
* values. This is where we wish we had a tuple data type. |
30 |
* @author Andrew John Hughes (gnu_andrew@member.fsf.org) |
* @author Andrew John Hughes (gnu_andrew@member.fsf.org) |
31 |
*/ |
*/ |
32 |
public class Pair<A,B> |
public class Pair<A,B> |
33 |
|
implements Serializable |
34 |
{ |
{ |
35 |
|
|
36 |
/** |
/** |
37 |
|
* Serialization ID. |
38 |
|
*/ |
39 |
|
private static final long serialVersionUID = -1924824870778608765L; |
40 |
|
|
41 |
|
/** |
42 |
* The left-hand value. |
* The left-hand value. |
43 |
|
* |
44 |
|
* @serial the left-hand value. |
45 |
*/ |
*/ |
46 |
private A left; |
private A left; |
47 |
|
|
48 |
/** |
/** |
49 |
* The right-hand value. |
* The right-hand value. |
50 |
|
* |
51 |
|
* @serial the right-hand value. |
52 |
*/ |
*/ |
53 |
private B right; |
private B right; |
54 |
|
|
55 |
/** |
/** |
56 |
* Constructs a new pair using the values specified. |
* Constructs a new pair using the values specified. |
57 |
* |
* |
58 |
* @param a the left-hand value. |
* @param left the left-hand value. |
59 |
* @param b the right-hand value. |
* @param right the right-hand value. |
60 |
*/ |
*/ |
61 |
public Pair(A left, B right) |
public Pair(A left, B right) |
62 |
{ |
{ |
108 |
* Returns true if the supplied object is also a pair, with equivalent |
* Returns true if the supplied object is also a pair, with equivalent |
109 |
* left and right-hand values. |
* left and right-hand values. |
110 |
* |
* |
111 |
* @param object the object to compare. |
* @param obj the object to compare. |
112 |
*/ |
*/ |
113 |
public boolean equals(Object obj) |
public boolean equals(Object obj) |
114 |
{ |
{ |
137 |
+ 17 * right.hashCode(); |
+ 17 * right.hashCode(); |
138 |
} |
} |
139 |
|
|
140 |
|
/** |
141 |
|
* Returns a <code>String</code> representation of the pair. |
142 |
|
* |
143 |
|
* @return a <code>String</code> representation. |
144 |
|
*/ |
145 |
|
public String toString() |
146 |
|
{ |
147 |
|
return "(" + left + "," + right + ")"; |
148 |
|
} |
149 |
|
|
150 |
} |
} |