-
Notifications
You must be signed in to change notification settings - Fork 24
/
KVPair.java
77 lines (65 loc) · 1.5 KB
/
KVPair.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Simple, immutable, key/value pairs
*/
public class KVPair<K,V> {
// +--------+------------------------------------------------------
// | Fields |
// +--------+
/**
* The key. May not be null.
*/
private K key;
/**
* The associated value.
*/
private V value;
// +--------------+------------------------------------------------
// | Constructors |
// +--------------+
/**
* Create a new key/value pair.
*/
public KVPair(K key, V value) {
this.key = key;
this.value = value;
} // KVPair(K,V)
// +------------------+--------------------------------------------
// | Standard methods |
// +------------------+
/**
* Compare for equality.
*/
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object other) {
return ((other instanceof KVPair) && (this.equals((KVPair<K,V>) other)));
} // equals(Object)
/**
* Compare for equality.
*/
public boolean equals(KVPair<K,V> other) {
return ((this.key.equals(other.key)) && (this.value.equals(other.value)));
} // equals(KVPair<K,V>)
/**
* Convert to string form.
*/
@Override
public String toString() {
return "<" + key + ":" + value + ">";
} // toString()
// +---------+-----------------------------------------------------
// | Methods |
// +---------+
/**
* Get the key.
*/
public K key() {
return this.key;
} // key()
/**
* Get the value.
*/
public V value() {
return this.value;
} // value()
} // KVPair<K,V>