org.clazzes.util.lifecycle
Interface Cacheable<T>

Type Parameters:
T - The Class used as an id for the cacheable objects. Has to be identical to the Class used by the corresponding Cache.
All Superinterfaces:
ObjectCreatable<T>

public interface Cacheable<T>
extends ObjectCreatable<T>

Interface to manage the life cycle of objects in combination with a Cache. All objects which are to be added to a Cache must implement this interface.

The object's id is used to discern different entities internally, therefore it is vital for the correct functioning of the Cache that every distinct Cacheable has a unique id.

Author:
jpayr

Method Summary
 T getId()
           
 void merge(Cacheable<T> object)
          Merges (replace values of this with values of object) the values of two Cacheable objects if possible.
 void setId(T id)
          Sets the id of this object.
 
Methods inherited from interface org.clazzes.util.lifecycle.ObjectCreatable
setObjectFactory
 

Method Detail

setId

void setId(T id)
Sets the id of this object.

Parameters:
id - The id to set.

getId

T getId()
Returns:
the id of this object.

merge

void merge(Cacheable<T> object)
           throws java.lang.UnsupportedOperationException
Merges (replace values of this with values of object) the values of two Cacheable objects if possible. Throws an UnsupportedOperationException if the objects can not be merged (e.g. are not of the same class).
This method is called whenever a Cacheable is added to a Cache in which another Cacheable with the same id is already present.

Parameters:
object - the object with which the current instance will be merged.
Throws:
java.lang.UnsupportedOperationException - if the current instance can not be merged with the given object.


Copyright © 2010. All Rights Reserved.