Package adams.gui.selection
Class AbstractFieldCacheItem
- java.lang.Object
-
- adams.gui.selection.AbstractFieldCacheItem
-
- All Implemented Interfaces:
DatabaseConnectionProvider,DatabaseConnectionUser,Serializable
public abstract class AbstractFieldCacheItem extends Object implements Serializable, DatabaseConnectionProvider
For caching fields per database connection.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Hashtable<FieldType,HashSet<FieldCacheUpdateListener>>m_CacheListenersthe listeners.protected FieldProviderm_Providerthe field provider to use.protected Hashtable<FieldType,List<AbstractField>>m_Valuesthe actual cache.
-
Constructor Summary
Constructors Constructor Description AbstractFieldCacheItem(FieldProvider provider)Initializes the cache.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddCacheListener(FieldType fieldtype, FieldCacheUpdateListener l)Adds a cache listener.voidclear()Clears the cache.AbstractDatabaseConnectiongetDatabaseConnection()Returns the database connection of this cache item.FieldProvidergetFieldProvider()Returns the underlying field provider.Hashtable<FieldType,List<AbstractField>>getValues()Returns the cached values.List<AbstractField>getValues(FieldType fieldType)Returns the cached values for the specified field type.List<AbstractField>getValues(FieldType fieldType, DataType dataType)Returns the cached values for the specified field/data type.protected voidinitCache()Initializes the cache, if necessary (i.e., m_Cache is null).booleanisInitialized()Checks whether the cache is initialized.protected Hashtable<FieldType,List<AbstractField>>newCache()Returns an initialized, but empty cache.protected abstract AbstractFieldnewField(AbstractField field)Creates a new field.protected abstract AbstractFieldnewPrefixField(AbstractField field)Creates a new prefix field.protected abstract AbstractFieldnewSuffixField(AbstractField field)Creates a new suffix field.voidremoveCacheListener(FieldType fieldtype, FieldCacheUpdateListener l)Removes a cache listener.voidremoveCacheListeners()Removes all cache listeners.
-
-
-
Field Detail
-
m_Provider
protected FieldProvider m_Provider
the field provider to use.
-
m_Values
protected Hashtable<FieldType,List<AbstractField>> m_Values
the actual cache.
-
m_CacheListeners
protected Hashtable<FieldType,HashSet<FieldCacheUpdateListener>> m_CacheListeners
the listeners.
-
-
Constructor Detail
-
AbstractFieldCacheItem
public AbstractFieldCacheItem(FieldProvider provider)
Initializes the cache.- Parameters:
provider- the field provider
-
-
Method Detail
-
getFieldProvider
public FieldProvider getFieldProvider()
Returns the underlying field provider.- Returns:
- the field provider
-
getDatabaseConnection
public AbstractDatabaseConnection getDatabaseConnection()
Returns the database connection of this cache item.- Specified by:
getDatabaseConnectionin interfaceDatabaseConnectionProvider- Returns:
- the database connection
-
clear
public void clear()
Clears the cache.
-
isInitialized
public boolean isInitialized()
Checks whether the cache is initialized.- Returns:
- true if initialized
-
getValues
public Hashtable<FieldType,List<AbstractField>> getValues()
Returns the cached values.- Returns:
- the cached values
-
getValues
public List<AbstractField> getValues(FieldType fieldType)
Returns the cached values for the specified field type.- Parameters:
fieldType- the field type to get the values for- Returns:
- the cached values
-
getValues
public List<AbstractField> getValues(FieldType fieldType, DataType dataType)
Returns the cached values for the specified field/data type.- Parameters:
fieldType- the field type to get the values fordataType- the data type to get the values for- Returns:
- the cached values
-
newCache
protected Hashtable<FieldType,List<AbstractField>> newCache()
Returns an initialized, but empty cache.- Returns:
- the empty cache
-
newField
protected abstract AbstractField newField(AbstractField field)
Creates a new field.- Parameters:
field- the field to transform- Returns:
- the transformed field
-
newSuffixField
protected abstract AbstractField newSuffixField(AbstractField field)
Creates a new suffix field.- Parameters:
field- the field to transform- Returns:
- the suffix field
-
newPrefixField
protected abstract AbstractField newPrefixField(AbstractField field)
Creates a new prefix field.- Parameters:
field- the field to transform- Returns:
- the prefix field
-
initCache
protected void initCache()
Initializes the cache, if necessary (i.e., m_Cache is null). Notifies all listeners about the update.
-
addCacheListener
public void addCacheListener(FieldType fieldtype, FieldCacheUpdateListener l)
Adds a cache listener.- Parameters:
fieldtype- the fieldtype to register the listener forl- the listener to add
-
removeCacheListener
public void removeCacheListener(FieldType fieldtype, FieldCacheUpdateListener l)
Removes a cache listener.- Parameters:
fieldtype- the fieldtype to unregister the listener forl- the listener to remove
-
removeCacheListeners
public void removeCacheListeners()
Removes all cache listeners.
-
-