create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / util / Pair.java
1 package net.sf.openrocket.util;
2
3 /**
4  * Storage for a pair of objects.
5  * 
6  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
7  * @param <U>   the first object type.
8  * @param <V>   the second object type.
9  */
10 public class Pair<U,V> {
11
12         private final U u;
13         private final V v;
14         
15         
16         public Pair(U u, V v) {
17                 this.u = u;
18                 this.v = v;
19         }
20         
21         public U getU() {
22                 return u;
23         }
24         
25         public V getV() {
26                 return v;
27         }
28         
29         
30         /**
31          * Compare both components of the Pair to another object.
32          * The pair is equal iff both items are equal (or null).
33          */
34         @SuppressWarnings("unchecked")
35         @Override
36         public boolean equals(Object other) {
37                 if (!(other instanceof Pair))
38                         return false;
39                 Object otherU = ((Pair)other).getU();
40                 Object otherV = ((Pair)other).getV();
41                 
42                 if (otherU == null) {
43                         if (this.u != null)
44                                 return false;
45                 } else {
46                         if (!otherU.equals(this.u))
47                                 return false;
48                 }
49
50                 if (otherV == null) {
51                         if (this.v != null)
52                                 return false;
53                 } else {
54                         if (!otherV.equals(this.v))
55                                 return false;
56                 }
57                 return true;
58         }
59         
60         @Override
61         public int hashCode() {
62                 return ((u != null) ? u.hashCode() : 0) + ((v != null) ? v.hashCode() : 0);
63         }
64         
65         
66         @Override
67         public String toString() {
68                 return "[" + u + ";" + v + "]";
69         }
70         
71 }