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 SummaryFieldsModifier 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 SummaryConstructorsConstructorDescriptionGenericCacheImpl(int capacity, CachePolicies<IdType, ObjectType, EntryType> policies) 
- 
Method SummaryModifier 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
- 
replacementPolicyprotected final CacheReplacementPolicy<IdType,ObjectType, replacementPolicyEntryType extends CacheEntry<ObjectType>> 
- 
slotsThe slots of this cache.
- 
indexMaps keys to slot indexes.
- 
initialPhaseCompletedprotected boolean initialPhaseCompletedIndicates that we have completed the initial cache population phase during which the cache has not yet reached its capacity.
- 
availableSlotIndexesIndexes of empty/unused slots; will be used have the initial cache population phase.
 
- 
- 
Constructor Details- 
GenericCacheImpl
 
- 
- 
Method Details- 
putDescription 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 interface- Cache<IdType,- ObjectType> 
 
- 
getDescription 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 interface- Cache<IdType,- ObjectType> 
 
- 
evictDescription 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 interface- Cache<IdType,- ObjectType> 
 
- 
evictDescription 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 interface- Cache<IdType,- ObjectType> 
 
- 
isEmptypublic boolean isEmpty()Description copied from interface:CacheReturnstrueif the cache does not contain any objects at the moment, andfalseotherwise.- Specified by:
- isEmptyin interface- Cache<IdType,- ObjectType> 
 
- 
clearpublic void clear()Description copied from interface:CacheRemoves all objects from this cache.- Specified by:
- clearin interface- Cache<IdType,- ObjectType> 
 
 
-