net.ontopia.utils
Class CachedGrabber<O,G>

java.lang.Object
  extended by net.ontopia.utils.CachedGrabber<O,G>
All Implemented Interfaces:
CachedIF, GrabberIF<O,G>

public class CachedGrabber<O,G>
extends java.lang.Object
implements GrabberIF<O,G>, CachedIF

INTERNAL: Grabber that maintains a cache of previously grabbed objects. It works with any implementation of GrabberIF.

The cache is first checked to see if a grabbed version already exists. Otherwise the object is grabbed and the cache is updated.

If the underlying grabber is modified or replaced, the cache is not refreshed automatically. This has to be done explicitly.


Field Summary
protected  java.util.Map<O,G> cache
           
protected  GrabberIF<O,G> grabber
           
 
Constructor Summary
CachedGrabber(GrabberIF<O,G> grabber)
           
 
Method Summary
 GrabberIF<O,G> getGrabber()
          Gets the grabber that is being cached.
 G grab(O object)
          Returns an object that is somehow extracted from the given object.
 void refresh()
          Refreshes the cache.
 void setGrabber(GrabberIF<O,G> grabber)
          Sets the grabber that is to be cached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

grabber

protected GrabberIF<O,G> grabber

cache

protected java.util.Map<O,G> cache
Constructor Detail

CachedGrabber

public CachedGrabber(GrabberIF<O,G> grabber)
Method Detail

getGrabber

public GrabberIF<O,G> getGrabber()
Gets the grabber that is being cached.


setGrabber

public void setGrabber(GrabberIF<O,G> grabber)
Sets the grabber that is to be cached. Note that the cache is not refreshed. If the cache is to be cleared call the refresh() method explicitly.


grab

public G grab(O object)
Description copied from interface: GrabberIF
Returns an object that is somehow extracted from the given object.

Specified by:
grab in interface GrabberIF<O,G>

refresh

public void refresh()
Description copied from interface: CachedIF
Refreshes the cache.

Specified by:
refresh in interface CachedIF


Copyright © 2000-2012 Ontopia.