public static class CachingDictionary.ItemCache extends Object implements ICachingDictionary.IItemCache
IHasLifecycle.LifecycleState, IHasLifecycle.ObjectClosedException, IHasLifecycle.ObjectOpenException| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY |
static float |
DEFAULT_LOAD_FACTOR |
static int |
DEFAULT_MAXIMUM_CAPACITY |
protected Map<IItemID<?>,IItem<?>> |
itemCache |
protected Map<ISenseKey,IWord> |
keyCache |
protected Lock |
lifecycleLock |
protected Map<ISenseKey,ISenseEntry> |
senseCache |
| Constructor and Description |
|---|
ItemCache()
Default constructor that initializes the dictionary with caching enabled.
|
ItemCache(int initialCapacity,
int maxCapacity,
boolean enabled)
Caller can specify both the initial size, maximum size, and the
initial state of caching.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cacheItem(IItem<?> item)
Caches the specified item, if this cache is enabled.
|
void |
cacheSenseEntry(ISenseEntry entry)
Caches the specified entry.
|
void |
cacheWordByKey(IWord word)
Caches the specified word, indexed by its sense key.
|
protected void |
checkOpen()
An internal method for assuring compliance with the dictionary
interface that says that methods will throw
ObjectClosedExceptions if the dictionary has not yet been
opened. |
void |
clear()
Removes all entries from the cache.
|
void |
close()
This closes the object by disposing of data backing objects or
connections.
|
int |
getInitialCapacity()
Returns the initial capacity of this cache.
|
int |
getMaximumCapacity()
Returns the maximum capacity of this cache.
|
boolean |
isEnabled()
Returns
true if this cache is enabled;
false otherwise. |
boolean |
isOpen()
Returns
true if the dictionary is open, that is, ready to
accept queries; returns false otherwise |
protected <K,V> Map<K,V> |
makeCache(int initialCapacity)
Creates the map that backs this cache.
|
boolean |
open()
This opens the object by performing any required initialization steps.
|
protected void |
reduceCacheSize(Map<?,?> cache)
Brings the map size into line with the specified maximum capacity of
this cache.
|
<T extends IItem<D>,D extends IItemID<T>> |
retrieveItem(D id)
Retrieves the item identified by the specified id.
|
ISenseEntry |
retrieveSenseEntry(ISenseKey key)
Retrieves the sense entry identified by the specified sense key.
|
IWord |
retrieveWord(ISenseKey key)
Retrieves the word identified by the specified sense key.
|
void |
setEnabled(boolean isEnabled)
Enables (
true) or disables (false) caching. |
void |
setInitialCapacity(int capacity)
Sets the initial capacity of the cache
|
void |
setMaximumCapacity(int capacity)
Sets the maximum capacity of the cache
|
int |
size()
Returns the number of items in the cache.
|
public static final int DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_MAXIMUM_CAPACITY
public static final float DEFAULT_LOAD_FACTOR
protected Lock lifecycleLock
protected Map<ISenseKey,ISenseEntry> senseCache
public ItemCache()
public ItemCache(int initialCapacity,
int maxCapacity,
boolean enabled)
initialCapacity - the initial capacity of the cachemaxCapacity - the maximum capacity of the cacheenabled - whether the cache starts out enabledpublic boolean open()
throws IOException
IHasLifecyclefalse, then subsequent calls to
IHasLifecycle.isOpen() will return false.open in interface IHasLifecycletrue if there were no errors in initialization;
false otherwise.IOException - if there was IO error while performing initializataionprotected <K,V> Map<K,V> makeCache(int initialCapacity)
K - the key typeV - the value typeinitialCapacity - the initial capacitypublic boolean isOpen()
IHasLifecycletrue if the dictionary is open, that is, ready to
accept queries; returns false otherwiseisOpen in interface IHasLifecycletrue if the object is open; false
otherwiseprotected void checkOpen()
ObjectClosedExceptions if the dictionary has not yet been
opened.ObjectClosedException - if the dictionary is closed.public void close()
IClosablepublic void clear()
ICachingDictionary.IItemCacheclear in interface ICachingDictionary.IItemCachepublic boolean isEnabled()
ICachingDictionary.IItemCachetrue if this cache is enabled;
false otherwise. If a cache is enabled, it will cache an
item passed to its cache methods.isEnabled in interface ICachingDictionary.IItemCachetrue if this cache is enabled;
false otherwisepublic void setEnabled(boolean isEnabled)
ICachingDictionary.IItemCachetrue) or disables (false) caching.setEnabled in interface ICachingDictionary.IItemCacheisEnabled - if true, caching is enabled; if
false, caching is disabled.public int getInitialCapacity()
public void setInitialCapacity(int capacity)
capacity - the initial capacitypublic int getMaximumCapacity()
ICachingDictionary.IItemCachegetMaximumCapacity in interface ICachingDictionary.IItemCachepublic void setMaximumCapacity(int capacity)
ICachingDictionary.IItemCachesetMaximumCapacity in interface ICachingDictionary.IItemCachecapacity - the maximum capacitypublic int size()
ICachingDictionary.IItemCachesize in interface ICachingDictionary.IItemCachepublic void cacheItem(IItem<?> item)
ICachingDictionary.IItemCachecacheItem in interface ICachingDictionary.IItemCacheitem - the item to be cached; may not be nullpublic void cacheWordByKey(IWord word)
ICachingDictionary.IItemCachecacheWordByKey in interface ICachingDictionary.IItemCacheword - the word to be cached; may not be nullpublic void cacheSenseEntry(ISenseEntry entry)
ICachingDictionary.IItemCachecacheSenseEntry in interface ICachingDictionary.IItemCacheentry - the entry to be cached; may not be nullprotected void reduceCacheSize(Map<?,?> cache)
cache - the map to be trimmedpublic <T extends IItem<D>,D extends IItemID<T>> T retrieveItem(D id)
ICachingDictionary.IItemCacheretrieveItem in interface ICachingDictionary.IItemCacheT - the type of the itemD - the type of the item idid - the id for the requested itemnull if not
present in the cachepublic IWord retrieveWord(ISenseKey key)
ICachingDictionary.IItemCacheretrieveWord in interface ICachingDictionary.IItemCachekey - the sense key for the requested wordnull if not
present in the cachepublic ISenseEntry retrieveSenseEntry(ISenseKey key)
ICachingDictionary.IItemCacheretrieveSenseEntry in interface ICachingDictionary.IItemCachekey - the sense key for the requested sense entrynull if not
present in the cacheCopyright © 2018. All rights reserved.