public abstract class Pair<K,V> extends Object
This class has no constructor. Rather, it has several different factory methods that instantiate
internal implementations of the Pair. For most intents and purposes, one would use the mutable[XXX]()
factory methods, depending on the context of usage.
Modifier and Type | Method and Description |
---|---|
static <K,V> Pair<K,V> |
immutable(K key,
V value)
Creates a new immutable pair with the given arguments
|
boolean |
isImmutable()
Checks this pair in order to ensure whether it is immutable or not
|
abstract K |
key()
Obtains the key in this pair
|
static <K,V> Pair<K,V> |
mutable()
Creates a new mutable pair
|
static <K,V> Pair<K,V> |
mutable(K key,
V value)
Creates a new mutable pair with the given start arguments
|
void |
read(java.util.function.BiConsumer<K,V> consumer)
Processes the pair
|
<T> T |
read(java.util.function.BiFunction<K,V,T> func)
Reads both key and value and returns a result
|
void |
set(K key,
V val)
Sets both the key and values of this pair
|
abstract void |
setKey(K key)
Sets the key of this pair
|
abstract void |
setVal(V val)
Sets the value of this pair
|
static <K,V> Pair<K,V> |
threadSafe()
Creates a new thread safe pair
|
static <K,V> Pair<K,V> |
threadSafe(K key,
V value)
Creates a new thread safe pair with the given start arguments
|
void |
transfer(Pair<K,V> pair)
Copies the key and value of the current pair to another pair
|
abstract V |
val()
Obtains the value in this pair
|
public static <K,V> Pair<K,V> mutable()
K
- the key typeV
- the value typepublic static <K,V> Pair<K,V> mutable(K key, V value)
K
- the key typeV
- the value typekey
- the key initial valuevalue
- the value initial valuepublic static <K,V> Pair<K,V> threadSafe()
K
- the key typeV
- the value typepublic static <K,V> Pair<K,V> threadSafe(K key, V value)
K
- the key typeV
- the value typekey
- the key initial valuevalue
- the value initial valuepublic static <K,V> Pair<K,V> immutable(K key, V value)
K
- the key typeV
- the value typekey
- the key valuevalue
- the value valuepublic void read(java.util.function.BiConsumer<K,V> consumer)
consumer
- the key-value readerpublic <T> T read(java.util.function.BiFunction<K,V,T> func)
T
- the type to be returnedfunc
- the readerpublic void transfer(Pair<K,V> pair)
pair
- the pair to transfer toUnsupportedOperationException
- if the given pair is immutablepublic abstract void setKey(K key)
key
- the key to setUnsupportedOperationException
- if the pair is immutablepublic abstract void setVal(V val)
val
- the value to setUnsupportedOperationException
- if the pair is immutablepublic void set(K key, V val)
key
- the key to setval
- the value to setUnsupportedOperationException
- if the pair is immutablepublic boolean isImmutable()
true
if the pair is immutable, false
if notCopyright © 2016. All rights reserved.