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 void
clear()
setskey
andvalue
to nullvoid
clearKey()
setskey
nullvoid
clearValue()
setsvalue
nullboolean
equals(java.lang.Object obj)
if the given object is aPair
instance,equals
comparison will be used on key and valueK
getKey()
V
getValue()
int
hashCode()
boolean
hasKey()
boolean
hasValue()
boolean
isEmpty()
boolean
isFull()
Pair<K,V>
set(K key, V value)
Pair<K,V>
set(Pair<K,V> pair)
void
setKey(K key)
void
setValue(V value)
void
swap()
swaps key and valuejava.lang.String
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Pair
public Pair()creates an empty pair (key
andvalue
arenull
) -
Pair
- Parameters:
key
- thekey
value
- thevalue
-
Pair
- Parameters:
pair
- thePair
to copy
-
-
Method Details
-
set
- Parameters:
pair
- the Pair whichkey
andvalue
to use- Returns:
- this Pair for chaining
-
set
- Parameters:
key
- thekey
to setvalue
- thevalue
to set- Returns:
- this Pair for chaining
-
clear
public void clear()setskey
andvalue
to null -
clearKey
public void clearKey()setskey
null -
clearValue
public void clearValue()setsvalue
null -
isEmpty
public boolean isEmpty()- Returns:
- if
key
orvalue
is notnull
-
isFull
public boolean isFull()- Returns:
- if
key
andvalue
are both notnull
-
hasKey
public boolean hasKey()- Returns:
- if
key
is not null
-
hasValue
public boolean hasValue()- Returns:
- if
value
is not null
-
swap
public void swap() throws java.lang.IllegalStateExceptionswaps key and value- Throws:
java.lang.IllegalStateException
- if the classes ofkey
andvalue
are notassignable
from each other
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)if the given object is aPair
instance,equals
comparison will be used on key and value- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
- Returns:
- [
key
&value
]
-
getKey
- Returns:
- the
key
-
setKey
- Parameters:
key
- thekey
to set
-
getValue
- Returns:
- the
value
-
setValue
- Parameters:
value
- thevalue
to set
-