1/**
2 * @author Jack Waller <jw309@st-andrews.ac.uk>
3 * @version 1.1
4 * @since 2020-03-28
5 * A implementation of Map.Entry.
6 */
7public final class Pair<K, V> implements Map.Entry<K, V> {
8
9 //variables
10 private final K key;
11 private V value;
12
13 //constructor
14 public Pair(K key, V value) {
15 this.key = key;
16 this.value = value;
17 }
18
19 //methods
20
21 /**
22 * Returns the key.
23 * @return K
24 */
25 @Override
26 public K getKey() {
27 return key;
28 }
29
30 /**
31 * Returns the value.
32 * @return V
33 */
34 @Override
35 public V getValue() {
36 return value;
37 }
38
39 /**
40 * Sets the value, returns the old value
41 * @param v value to set
42 * @return V
43 */
44 @Override
45 public V setValue(V v) {
46 V old = this.value;
47 this.value = v;
48 return old;
49 }
50}