org.javaruntype.cache
Class ConcurrentCache<K,V>

Object
  extended by org.javaruntype.cache.ConcurrentCache<K,V>
Type Parameters:
K - key type
V - value type

public final class ConcurrentCache<K,V>
extends Object

Base synchronized cache for *Registry objects.

Do not use this class directly.

This class is thread-safe.

Since:
1.0
Author:
Daniel Fernández

Constructor Summary
ConcurrentCache()
           Create a new synchronized cache.
ConcurrentCache(int maxElements)
           Create a new synchronized cache specifying a maximum size for the cache
 
Method Summary
 void clear()
           Clear the cache.
 V computeAndGet(K key, V value)
           Puts a value into the cache and returns it.
 V get(K key)
           Get the value for a specific key
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentCache

public ConcurrentCache()

Create a new synchronized cache.


ConcurrentCache

public ConcurrentCache(int maxElements)

Create a new synchronized cache specifying a maximum size for the cache

Method Detail

clear

public void clear()

Clear the cache.


get

public V get(K key)

Get the value for a specific key

Parameters:
key - the key
Returns:
the value, or null if not found

computeAndGet

public V computeAndGet(K key,
                       V value)

Puts a value into the cache and returns it. If a value already existed for the same key, the existing value is not modified and is returned instead of the one passed as parameter. This ensures only one object for each key exists at a time.

Parameters:
key - the key to which the value will be assigned
value - the value which will be added to the map
Returns:
the value added to the map (or the one already existing at the map)


Copyright © 2012 The JAVARUNTYPE team. All Rights Reserved.