public class KeyValue<K,V> extends java.lang.Object implements java.lang.Comparable<KeyValue<K,V>>
org.incava.ijdk.lang.Pair, does not
require that the key and value types be Comparable, using their compareTo methods in
KeyValue#compareTo if they are subclasses of Comparable.| Constructor and Description |
|---|
KeyValue(K key,
V value)
Constructs a KeyValue.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(KeyValue<K,V> other)
Compares the given object to this one, using their
compareTo methods if the key
and/or value implement Comparable. |
boolean |
equals(java.lang.Object obj)
Returns if
obj equals this one. |
K |
getKey()
Returns the key.
|
V |
getValue()
Returns the value.
|
int |
hashCode()
Returns the hash code for the key/value pair.
|
K |
key()
Returns the key.
|
static <K,V> KeyValue<K,V> |
of(K key,
V value)
Shorter syntax than the default constructor, allowing the compiler to discern the object types.
|
java.lang.String |
toString()
Returns this key/value pair as a string, in the form "#{key} => #{value}".
|
java.lang.String |
toString(java.lang.String sep)
Returns this key/value pair as a string, using the given separator, in the form
"#{key}#{separator}#{value}".
|
V |
value()
Returns the value.
|
public static <K,V> KeyValue<K,V> of(K key, V value)
key - the keyvalue - the valuepublic K getKey()
public V getValue()
public K key()
public V value()
public boolean equals(java.lang.Object obj)
obj equals this one.equals in class java.lang.Objectobj - the object to compare to this oneobj equals this onepublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toString(java.lang.String sep)
sep - the separator to usepublic int hashCode()
hashCode in class java.lang.Object