public abstract class SingletonMap<K,V> extends Object
Constructor and Description |
---|
SingletonMap() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the map.
|
boolean |
createSingleton(K key)
Initialize a value object for this key and return true, if this is the first time this key has been seen,
otherwise return false.
|
V |
get(K key)
Get the singleton for a given key.
|
V |
getOrCreateSingleton(K key)
Check if the given key is in the map, and if so, return it.
|
abstract V |
newInstance(K key)
Construct a new singleton instance.
|
List<V> |
values()
Get all singletons in the map.
|
public boolean createSingleton(K key) throws Exception
Exception
- if newInstance(key) throws an exception.IllegalArgumentException
- if newInstance(key) returns null.public V getOrCreateSingleton(K key) throws Exception
Exception
- if newInstance(key) throws an exception.IllegalArgumentException
- if newInstance(key) returns null.public abstract V newInstance(K key) throws Exception
Exception
public V get(K key) throws InterruptedException
InterruptedException
public List<V> values() throws InterruptedException
InterruptedException
public void clear()
Copyright © 2017. All rights reserved.