org.pojomatic.internal
Class SelfPopulatingMap<K,V>

java.lang.Object
  extended by org.pojomatic.internal.SelfPopulatingMap<K,V>

public abstract class SelfPopulatingMap<K,V>
extends java.lang.Object

A thread-safe "map" which generates values on demand, with the guarantee that no more than one value will be auto-created for a given key. Classes extending this class should override create(Object).


Constructor Summary
SelfPopulatingMap()
           
 
Method Summary
protected abstract  V create(K key)
          Create a value for a key.
 V get(K key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelfPopulatingMap

public SelfPopulatingMap()
Method Detail

get

public V get(K key)

create

protected abstract V create(K key)
Create a value for a key. This will be called by get(Object) when there is not already an existing value, and no other thread is already creating a value for that key. The value returned must not be null.

Parameters:
key - the key to create the value for
Returns:
the value


Copyright © 2008-2009. All Rights Reserved.