View Javadoc

1   package org.lsst.ccs.utilities.structs;
2   
3   import java.io.Serializable;
4   import java.util.Map;
5   
6   /**
7    * A simple tuple with two immutable values. can be used as a Map.Entry
8    * @author bamade
9    */
10  // Date: 17/11/12
11  
12  public class UniquePair<K, V> implements Map.Entry<K, V>, Serializable {
13      public final K key;
14      public final V value;
15  
16      public UniquePair(K key, V value) {
17          this.key = key;
18          this.value = value;
19      }
20  
21      @Override
22      public K getKey() {
23          return key;
24      }
25  
26      @Override
27      public V getValue() {
28          return value;
29      }
30  
31      @Override
32      public V setValue(V v) {
33          throw new UnsupportedOperationException("no set on value");
34      }
35  
36      @Override
37      public String toString() {
38          return "[" + key + "," + value + "]";
39      }
40  
41      @Override
42      public boolean equals(Object o) {
43          if (this == o) return true;
44          if (!(o instanceof UniquePair)) return false;
45  
46          UniquePair that = (UniquePair) o;
47  
48          if (key != null ? !key.equals(that.key) : that.key != null) return false;
49  
50          return true;
51      }
52  
53      @Override
54      public int hashCode() {
55          return key != null ? key.hashCode() : 0;
56      }
57  }