Package net.dermetfan.utils
Class Pair<K,V>
java.lang.Object
net.dermetfan.utils.Pair<K,V>
- Type Parameters:
K- the type of the keyV- the type of the value
public class Pair<K,V>
extends java.lang.Object
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidclear()setskeyandvalueto nullvoidclearKey()setskeynullvoidclearValue()setsvaluenullbooleanequals(java.lang.Object obj)if the given object is aPairinstance,equalscomparison will be used on key and valueKgetKey()VgetValue()inthashCode()booleanhasKey()booleanhasValue()booleanisEmpty()booleanisFull()Pair<K,V>set(K key, V value)Pair<K,V>set(Pair<K,V> pair)voidsetKey(K key)voidsetValue(V value)voidswap()swaps key and valuejava.lang.StringtoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Pair
public Pair()creates an empty pair (keyandvaluearenull) -
Pair
- Parameters:
key- thekeyvalue- thevalue
-
Pair
- Parameters:
pair- thePairto copy
-
-
Method Details
-
set
- Parameters:
pair- the Pair whichkeyandvalueto use- Returns:
- this Pair for chaining
-
set
- Parameters:
key- thekeyto setvalue- thevalueto set- Returns:
- this Pair for chaining
-
clear
public void clear()setskeyandvalueto null -
clearKey
public void clearKey()setskeynull -
clearValue
public void clearValue()setsvaluenull -
isEmpty
public boolean isEmpty()- Returns:
- if
keyorvalueis notnull
-
isFull
public boolean isFull()- Returns:
- if
keyandvalueare both notnull
-
hasKey
public boolean hasKey()- Returns:
- if
keyis not null
-
hasValue
public boolean hasValue()- Returns:
- if
valueis not null
-
swap
public void swap() throws java.lang.IllegalStateExceptionswaps key and value- Throws:
java.lang.IllegalStateException- if the classes ofkeyandvalueare notassignablefrom each other
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)if the given object is aPairinstance,equalscomparison will be used on key and value- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object- Returns:
- [
key&value]
-
getKey
- Returns:
- the
key
-
setKey
- Parameters:
key- thekeyto set
-
getValue
- Returns:
- the
value
-
setValue
- Parameters:
value- thevalueto set
-