Class GenericCacheImpl<IdType,ObjectType,EntryType extends CacheEntry<ObjectType>>  
java.lang.Object
se.liu.ida.hefquin.base.datastructures.impl.cache.GenericCacheImpl<IdType,ObjectType,EntryType>  
- All Implemented Interfaces:
 Cache<IdType,ObjectType> 
public class GenericCacheImpl<IdType,ObjectType,EntryType extends CacheEntry<ObjectType>>  
extends Object
implements Cache<IdType,ObjectType> 
A generic, thread-safe implementation of 
Cache.- 
Field Summary
FieldsModifier and TypeFieldDescriptionIndexes of empty/unused slots; will be used have the initial cache population phase.Maps keys to slot indexes.protected booleanIndicates that we have completed the initial cache population phase during which the cache has not yet reached its capacity.protected final CachePolicies<IdType, ObjectType, EntryType> protected final CacheReplacementPolicy<IdType, ObjectType, EntryType> The slots of this cache. - 
Constructor Summary
ConstructorsConstructorDescriptionGenericCacheImpl(int capacity, CachePolicies<IdType, ObjectType, EntryType> policies)  - 
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all objects from this cache.booleanIf the cache contains an object that is associated with the given ID, then this object is evicted from the cache and the method returnstrue.booleanevict(IdType id, ObjectType obj) If an object equivalent to the given one is associated with the given ID in this cache, then this object is evicted from the cache and the method returnstrue.Returns the object associated with the given ID in this cache, ornullif there is no such object in the cache.booleanisEmpty()Returnstrueif the cache does not contain any objects at the moment, andfalseotherwise.voidput(IdType id, ObjectType obj) Adds the given object to this cache, associated with the given ID. 
- 
Field Details
- 
policies
 - 
replacementPolicy
protected final CacheReplacementPolicy<IdType,ObjectType, replacementPolicyEntryType extends CacheEntry<ObjectType>>  - 
slots
The slots of this cache. - 
index
 - 
initialPhaseCompleted
protected boolean initialPhaseCompletedIndicates that we have completed the initial cache population phase during which the cache has not yet reached its capacity. - 
availableSlotIndexes
 
 - 
 - 
Constructor Details
- 
GenericCacheImpl
 
 - 
 - 
Method Details
- 
put
Description copied from interface:CacheAdds the given object to this cache, associated with the given ID. If there is another object currently associated with the given ID, that object will be replaced by the given one. Updating the cache may also lead to the eviction of other cached objects, depending on whether the cache has reached its capacity. In such a case, the object(s) that are evicted are determined based on the cache replacement policy of this cache.- Specified by:
 putin interfaceCache<IdType,ObjectType> 
 - 
get
Description copied from interface:CacheReturns the object associated with the given ID in this cache, ornullif there is no such object in the cache. Implementations may also returnnulleven if there is such an object but that object is not valid anymore, according to a cache invalidation policy employed by the cache. In such a case, the object may also be evicted altogether from the cache.- Specified by:
 getin interfaceCache<IdType,ObjectType> 
 - 
evict
Description copied from interface:CacheIf the cache contains an object that is associated with the given ID, then this object is evicted from the cache and the method returnstrue. If there is no such cached object, the method returnsfalse. Calling this method may also have the side effect that other objects are evicted from the cache, depending on the invalidation policy of this cache.- Specified by:
 evictin interfaceCache<IdType,ObjectType> 
 - 
evict
Description copied from interface:CacheIf an object equivalent to the given one is associated with the given ID in this cache, then this object is evicted from the cache and the method returnstrue. If there is another object associated with the ID, or none at all, the method returnsfalse. Calling this method may also have the side effect that other objects are evicted from the cache, depending on the invalidation policy of this cache.- Specified by:
 evictin interfaceCache<IdType,ObjectType> 
 - 
isEmpty
public boolean isEmpty()Description copied from interface:CacheReturnstrueif the cache does not contain any objects at the moment, andfalseotherwise.- Specified by:
 isEmptyin interfaceCache<IdType,ObjectType> 
 - 
clear
public void clear()Description copied from interface:CacheRemoves all objects from this cache.- Specified by:
 clearin interfaceCache<IdType,ObjectType> 
 
 -