/
Pair.java
42 lines (37 loc) · 930 Bytes
/
Pair.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
package net.ME1312.Galaxi.Library.Container;
/**
* Key-Value Pair Container
*
* @param <K> Key Type
* @param <V> Value Type
*/
public abstract class Pair<K, V> extends Value<V> {
/**
* Get the Key
*
* @return Key
*/
public abstract K key();
/**
* Set the Key
*
* @param key Key
*/
public abstract K key(K key);
@Override
public String toString() {
return '[' + String.valueOf(key()) + ", " + String.valueOf(value()) + ')';
}
@Override
public boolean equals(Object object) {
if (object instanceof Pair) {
if (key() == null || ((Pair) object).key() == null) {
return key() == ((Pair) object).key() && super.equals(object);
} else {
return key().equals(((Pair) object).key()) && super.equals(object);
}
} else {
return false;
}
}
}