/** * Generically hold a key, value pair * @author gtowell * Created: Jul 2021 */ public class KeyValue { /** The key */ private final U key; /** the value */ private V value; /** * Create a key, value pair * @param key the Key * @param value the value */ public KeyValue(U key, V value) { this.key = key; this.value = value; } public U getKey() { return key; } public V getValue() { return value; } public void setValue(V v) { this.value = v; } @Override @SuppressWarnings("unchecked") public boolean equals(Object other) { if (other instanceof KeyValue) { return key.equals(((KeyValue) other).key); } else { return super.equals(other); } } @Override public String toString() { return "<" + key + ", " + value + ">"; } public static void main(String[] args) { KeyValue ksvi = new KeyValue<>("key", 1); KeyValue kdvsb = new KeyValue<>(3.1415, new StringBuffer("Now is the time")); System.out.println(ksvi); System.out.println(kdvsb); } }