Package cpsc331.collections
Class KeyValuePair<K,V>
- java.lang.Object
-
- cpsc331.collections.KeyValuePair<K,V>
-
public class KeyValuePair<K,V> extends java.lang.Object
Implements a key-value pair of keys with type K and values with type V
KeyValuePair Invariant:
- key has type K
- value has type V
-
-
Constructor Summary
Constructors Constructor Description KeyValuePair()
Constructs a key-value pair such that the key and value are both null.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(KeyValuePair<K,V> pair)
Implements a test for equality, based on key values.K
getKey()
Reports the key of this KeyValuePair.V
getValue()
Reports the value of this KeyValuePair.void
setKey(K k)
Sets the key to be the input received.void
setValue(V v)
Sets the value to be the input received.
-
-
-
Method Detail
-
getKey
public K getKey()
Reports the key of this KeyValuePair.- Returns:
- the key of this KeyValuePair
-
setKey
public void setKey(K k)
Sets the key to be the input received.- Parameters:
k
- the new key to be stored in this KeyValuePair
-
getValue
public V getValue()
Reports the value of this KeyValuePair.- Returns:
- the value of this KeyValuePair
-
setValue
public void setValue(V v)
Sets the value to be the input received.- Parameters:
v
- the new value to be stored in this KeyValuePair
-
equals
public boolean equals(KeyValuePair<K,V> pair)
Implements a test for equality, based on key values.- Parameters:
pair
- the key-value pair whose key is to be compared to this one’s- Returns:
- true if the input KeyValuePair stores the same key as this one, and false otherwise.
-
-