net.sourceforge.wurfl.core.cache
Class HashMapCacheProvider

java.lang.Object
  extended by net.sourceforge.wurfl.core.cache.HashMapCacheProvider
All Implemented Interfaces:
CacheProvider

public class HashMapCacheProvider
extends Object
implements CacheProvider

CacheProvider HashMap implementation.

The items are cached by mean of HashMap, they never evict.

Version:
$Id: HashMapCacheProvider.java 432 2010-05-06 12:12:53Z filippo.deluca $
Author:
Fantayeneh Asres Gizaw, Filippo De Luca

Constructor Summary
HashMapCacheProvider()
          Default constructor
HashMapCacheProvider(int initialCapacity)
          Constructor by the initial capacity.
HashMapCacheProvider(int initialCapacity, float loadFactor)
          Constructor by the initial capacity and load factor.
HashMapCacheProvider(int initialCapacity, float loadFactor, int concurrentWrites)
          Constructor by the initial capacity, loadFactor and maximum concurrent writes
 
Method Summary
 void clear()
          Remove all items from cache.
protected  Map createCache()
          Factory method to create cache Map.
 Object get(Object key)
          Returns the cached item.
 int getConcurrentWrites()
          Return the maximum threads can write the cache.
 int getInitialCapacity()
          Return the initial capacity of the hashMap.
 float getLoadFactor()
          Return the hashMap load factor.
 void put(Object key, Object target)
          Put an item in cache associated to a key.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HashMapCacheProvider

public HashMapCacheProvider()
Default constructor


HashMapCacheProvider

public HashMapCacheProvider(int initialCapacity)
Constructor by the initial capacity.

Parameters:
The - initial capacity of HashMap.
See Also:
ConcurrentHashMap.ConcurrentHashMap(int).

HashMapCacheProvider

public HashMapCacheProvider(int initialCapacity,
                            float loadFactor)
Constructor by the initial capacity and load factor.

Parameters:
initialCapacity - The hashMap initial capacity.
loadFactor - The hashMap load factor.
See Also:
ConcurrentHashMap.ConcurrentHashMap(int, float).

HashMapCacheProvider

public HashMapCacheProvider(int initialCapacity,
                            float loadFactor,
                            int concurrentWrites)
Constructor by the initial capacity, loadFactor and maximum concurrent writes

Parameters:
initialCapacity - The hashMap initial capacity.
loadFactor - The hashMap load factor.
concurrentWrites - The maximum thread can write the cache.
See Also:
ConcurrentHashMap.ConcurrentHashMap(int, float, int).
Method Detail

getInitialCapacity

public int getInitialCapacity()
Return the initial capacity of the hashMap.

Returns:
the initial capacity of the hashMap.
See Also:
ConcurrentHashMap.ConcurrentHashMap(int, float, int)

getLoadFactor

public float getLoadFactor()
Return the hashMap load factor.

Returns:
the hashMap load factor.
See Also:
ConcurrentHashMap.ConcurrentHashMap(int, float, int)

getConcurrentWrites

public int getConcurrentWrites()
Return the maximum threads can write the cache.

Returns:
a int representing the maximum thread can write the cache.
See Also:
ConcurrentHashMap.ConcurrentHashMap(int, float, int)

clear

public void clear()
Remove all items from cache.

Specified by:
clear in interface CacheProvider

get

public Object get(Object key)
Returns the cached item.

Specified by:
get in interface CacheProvider
Parameters:
key - The cached item key.
Returns:
Cached Object, null if this cache does not contain it.

put

public void put(Object key,
                Object target)
Put an item in cache associated to a key.

Specified by:
put in interface CacheProvider
Parameters:
key - The caching item key.
target - The caching item.

createCache

protected Map createCache()
Factory method to create cache Map. Subclass can override this method to change the backing HashMap implementation.


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 WURFL-Pro srl. All Rights Reserved.