net.ontopia.utils
Class CachedStringifier<T>

java.lang.Object
  extended by net.ontopia.utils.CachedStringifier<T>
All Implemented Interfaces:
CachedIF, StringifierIF<T>

public class CachedStringifier<T>
extends Object
implements StringifierIF<T>, CachedIF

INTERNAL: Stringifier that maintains a cache of previously stringified objects. It works with any implementation of StringifierIF.

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


Field Summary
protected  Map<T,String> cache
           
protected  StringifierIF<? super T> stringifier
           
 
Constructor Summary
CachedStringifier(StringifierIF<? super T> stringifier)
           
 
Method Summary
 StringifierIF<? super T> getStringifier()
          Gets the stringifier that is to be cached.
 void refresh()
          Refreshes the cache.
 void setStringifier(StringifierIF<? super T> stringifier)
          Sets the stringifier that is to be cached.
 String toString(T object)
          Returns a stringified version of the object, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stringifier

protected StringifierIF<? super T> stringifier

cache

protected Map<T,String> cache
Constructor Detail

CachedStringifier

public CachedStringifier(StringifierIF<? super T> stringifier)
Method Detail

getStringifier

public StringifierIF<? super T> getStringifier()
Gets the stringifier that is to be cached.


setStringifier

public void setStringifier(StringifierIF<? super T> stringifier)
Sets the stringifier that is to be cached.


toString

public String toString(T object)
Description copied from interface: StringifierIF
Returns a stringified version of the object, i.e. a string representation of that object.

Specified by:
toString in interface StringifierIF<T>
Parameters:
object - the object that is to be made a string representation of.
Returns:
a string representation of the object argument.

refresh

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

Specified by:
refresh in interface CachedIF


Copyright © 2000-2012 Ontopia.