org.omnaest.utils.structure.element
Class CachedElement<T>

java.lang.Object
  extended by org.omnaest.utils.structure.element.CachedElement<T>

public class CachedElement<T>
extends Object

A CachedElement provides an abstract cache mechanism around a given value. The value is initially resolved once from a given CachedElement.ValueResolver.

Author:
Omnaest

Nested Class Summary
static interface CachedElement.ValueResolver<T>
           
static class CachedElement.ValueResolverSimple<T>
          Simple CachedElement.ValueResolver which returns the object initially given to the constructor.
 
Field Summary
protected  T cachedValue
           
protected  CachedElement.ValueResolver<T> valueResolver
           
 
Constructor Summary
CachedElement(CachedElement.ValueResolver<T> valueFactory)
           
CachedElement(T value)
           
 
Method Summary
 CachedElement<T> clearCache()
          Clears the cached value, so the next call to getValue() will resolve the value once again from the underlying CachedElement.ValueResolver.
 T getCachedValue()
          Returns the cached value and does not resolve the value if the cached value is null.
 T getValue()
          Returns the value from the cache or resolves it from the underlying factory.
 CachedElement.ValueResolver<T> getValueResolver()
           
 boolean hasValueResolved()
          Returns true, if the cache has resolved a value from the underlying CachedElement.ValueResolver instance.
 void setValueResolver(CachedElement.ValueResolver<T> valueResolver)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cachedValue

protected T cachedValue

valueResolver

protected CachedElement.ValueResolver<T> valueResolver
Constructor Detail

CachedElement

public CachedElement(CachedElement.ValueResolver<T> valueFactory)
Parameters:
valueResolver -
See Also:
CachedElement, CachedElement.ValueResolver

CachedElement

public CachedElement(T value)
Parameters:
valueResolver -
See Also:
CachedElement, CachedElement.ValueResolver, CachedElement.ValueResolverSimple
Method Detail

getValue

public T getValue()
Returns the value from the cache or resolves it from the underlying factory.


getCachedValue

public T getCachedValue()
Returns the cached value and does not resolve the value if the cached value is null.

Returns:

hasValueResolved

public boolean hasValueResolved()
Returns true, if the cache has resolved a value from the underlying CachedElement.ValueResolver instance.

Returns:

setValueResolver

public void setValueResolver(CachedElement.ValueResolver<T> valueResolver)

getValueResolver

public CachedElement.ValueResolver<T> getValueResolver()

clearCache

public CachedElement<T> clearCache()
Clears the cached value, so the next call to getValue() will resolve the value once again from the underlying CachedElement.ValueResolver.

Returns:
this


Copyright © 2011. All Rights Reserved.