org.fjank.jcache.collection
Class MapAdapter

java.lang.Object
  extended by org.fjank.jcache.collection.MapAdapter
All Implemented Interfaces:
Map, CacheMap

public class MapAdapter
extends Object
implements CacheMap

A Map based implementation of CacheAccess.

Author:
Frank Karlstrøm

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
MapAdapter(CacheAccessImpl2 originalAccess)
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(Object value)
           
 void defineObject(Object name, Attributes attributes)
          is used to specify the attributes to associate with an object when it is loaded.
 Set entrySet()
           
 Object get(Object key)
          Returns the value to which this map maps the specified key.
 Object get(Object name, Object arguments)
          Gets the object from the cache.
 Attributes getAttributes()
          Will return an attribute object describing the current attributes associated for the region for this CacheAccess.
 Attributes getAttributes(Object name)
          will return an attribute object describing the current attributes associated with the object name.
 boolean isEmpty()
           
 Set keySet()
           
 Object put(Object key, Object value)
           
 Object put(Object key, String group, Object value)
          Puts a object into the cache, and attach it to a group.
 void putAll(Map t)
          Adds all elements in th map into FKache.
 Object remove(Object key)
          Removes an object from this map.
 Object remove(Object key, String group)
          Removes an object from a group.
 int size()
          Returns the current number of objects (Raw objects and groups) in this region.
 Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

MapAdapter

public MapAdapter(CacheAccessImpl2 originalAccess)
Method Detail

size

public int size()
Returns the current number of objects (Raw objects and groups) in this region. this method is not recursive across the groups, so any objects under the groups ini the region root is not accounted for.

Specified by:
size in interface Map
See Also:
Map.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map

containsKey

public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains at a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)

Specified by:
containsKey in interface Map
Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.
Throws:
NullPointerException - if the key is null.
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map

get

public Object get(Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.

More formally, if this map contains a mapping from a key k to a value v such that (key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

Specified by:
get in interface Map
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
Throws:
ClassCastException - if an attempt is mad to retrieve a group.
NullPointerException - key is null.
See Also:
Map.get(java.lang.Object)

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map
Throws:
IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
See Also:
javax.util.jcache.CacheAccess#put(java.lang.Object, java.lang.Object), Map.put(java.lang.Object, java.lang.Object)

put

public Object put(Object key,
                  String group,
                  Object value)
Description copied from interface: CacheMap
Puts a object into the cache, and attach it to a group. If the group does not exist, this method will fail. If an object with the specified name, in the specified group already exists, this object is repleaced with the new object, and the old object is returned. Otherwise null is returned.

Specified by:
put in interface CacheMap
Parameters:
key - the key of the object
group - the group to put it in to.
value - the actual object to put into the cache.
Returns:
if an object already was in the cache in the specified group, this object is returned.
Throws:
IllegalArgumentException - if some aspect of this key, group or value prevents it from being stored in this map.
See Also:
javax.util.jcache.CacheAccess#put(Object, String, Object), CacheMap.put(Object, String, Object)

remove

public Object remove(Object key)
Removes an object from this map. The removed object is returned. if the object does not exist in the cache, null is returned.

Specified by:
remove in interface Map
Parameters:
key - the object to remove.
Returns:
the removed object, or null if the object does not exist in FKache.
See Also:
Map.remove(java.lang.Object)

remove

public Object remove(Object key,
                     String group)
Description copied from interface: CacheMap
Removes an object from a group.

Specified by:
remove in interface CacheMap
Parameters:
key - The object to remove.
group - The group to remove the object from.
Returns:
The removed object if any.

putAll

public void putAll(Map t)
Adds all elements in th map into FKache.

Specified by:
putAll in interface Map
Parameters:
t - the map which contains the elements to add.
Throws:
IllegalArgumentException - if some aspect of the map prevents this operation to complete.
NullPointerException - if the map is null, a key is null, or any value is null.
See Also:
Map.putAll(java.util.Map)

clear

public void clear()
Specified by:
clear in interface Map

keySet

public Set keySet()
Specified by:
keySet in interface Map

values

public Collection values()
Specified by:
values in interface Map

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map

getAttributes

public Attributes getAttributes()
Description copied from interface: CacheMap
Will return an attribute object describing the current attributes associated for the region for this CacheAccess.

Specified by:
getAttributes in interface CacheMap
Returns:
an Attributes object for the region of this CacheAccess.

getAttributes

public Attributes getAttributes(Object name)
                         throws CacheException
Description copied from interface: CacheMap
will return an attribute object describing the current attributes associated with the object name.

Specified by:
getAttributes in interface CacheMap
Parameters:
name - the name of the object to get the attributes for.
Returns:
an Attributes object for the named object.
Throws:
CacheException - if an error occurs.

get

public Object get(Object name,
                  Object arguments)
Description copied from interface: CacheMap
Gets the object from the cache. If the object is not currently in the cache and a loader object has been registered, the object will be loaded into the cache with the arguments specified.

Specified by:
get in interface CacheMap
Parameters:
name - the name of the object to get.
arguments - the arguments wich is passed to the load method of the CacheLoader, if registered.
Returns:
a reference to a shared object.

defineObject

public void defineObject(Object name,
                         Attributes attributes)
Description copied from interface: CacheMap
is used to specify the attributes to associate with an object when it is loaded. This can include the loader object, cache event handlers, and spesific attributes for the object such as distribute, spool, etc. Attributes (with the exception of the CacheLoader object itself) can also be specified within the load method of the CacheLoader object using the setAttributes method, if the attributes for an object are not defined, the attributes of the region will be used.

Specified by:
defineObject in interface CacheMap
Parameters:
name - the name of the object to associate the attributes with.
attributes - the attributes to associate.


Copyright © 2002-2009 Hosted by SourceForge. All Rights Reserved.