org.opensha.commons.data.siteData
Class CachedSiteDataWrapper<Element>

java.lang.Object
  extended by org.opensha.commons.data.siteData.CachedSiteDataWrapper<Element>
Type Parameters:
Element -
All Implemented Interfaces:
java.util.EventListener, Named, SiteData<Element>, XMLSaveable, ParameterChangeListener

public class CachedSiteDataWrapper<Element>
extends java.lang.Object
implements SiteData<Element>, ParameterChangeListener

This is a class that takes and SiteDataAPI class and wraps it to add a cache for faster retrieval of data in situations where the same location may be requested often.

Author:
Kevin Milner

Field Summary
protected static boolean D
          If true print out debug statements.
 
Fields inherited from interface org.opensha.commons.data.siteData.SiteData
TYPE_DEPTH_TO_1_0, TYPE_DEPTH_TO_2_5, TYPE_ELEVATION, TYPE_FLAG_INFERRED, TYPE_FLAG_MEASURED, TYPE_TOPOGRAPHIC_SLOPE, TYPE_VS30, TYPE_WILLS_CLASS, XML_METADATA_NAME
 
Constructor Summary
CachedSiteDataWrapper(SiteData<Element> provider)
           
CachedSiteDataWrapper(SiteData<Element> provider, int cacheSize)
           
 
Method Summary
 void clearCache()
          Clear the cache.
 ParameterList getAdjustableParameterList()
          Returns a list of adjustable parameters.
 SiteDataValue<Element> getAnnotatedValue(Location loc)
          Get the value, with metadata, at the closest location
 SiteDataValueList<Element> getAnnotatedValues(LocationList locs)
          Get the values, with metadata, at the closest locations
 Region getApplicableRegion()
          This gives the applicable region for this data set.
 Location getClosestDataLocation(Location loc)
          Get the location of the closest data point
 java.lang.String getDataMeasurementType()
          Get the measurement type for this data, such as "Measured" or "Inferred"
 java.lang.String getDataType()
          Get the data type of this dataset
 java.lang.String getMetadata()
          Returns the metadata for this dataset.
 java.lang.String getName()
          Get the name of this dataset
 ParameterListEditor getParameterListEditor()
          Returns an editor for the parameter list.
 double getResolution()
          This gives the resolution of the dataset in degrees, or 0 for infinite resolution.
 java.lang.String getShortName()
          Get the short name of this dataset
 Element getValue(Location loc)
          Returns the value from the underlying site data object, keeping track of the value in the cache.
 java.util.ArrayList<Element> getValues(LocationList locs)
          Get the value for each location in the given location list
 boolean hasDataForLocation(Location loc, boolean checkValid)
          Returns true if there is data for the given site
 boolean isValueValid(Element el)
          Returns true if the value is valid, and not NaN, N/A, or equivelant for the data type
 void parameterChange(ParameterChangeEvent event)
          Function that must be implemented by all Listeners for ParameterChangeEvents.
 Element toXMLMetadata(Element root)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

D

protected static final boolean D
If true print out debug statements.

See Also:
Constant Field Values
Constructor Detail

CachedSiteDataWrapper

public CachedSiteDataWrapper(SiteData<Element> provider)

CachedSiteDataWrapper

public CachedSiteDataWrapper(SiteData<Element> provider,
                             int cacheSize)
Method Detail

getAnnotatedValue

public SiteDataValue<Element> getAnnotatedValue(Location loc)
                                         throws java.io.IOException
Description copied from interface: SiteData
Get the value, with metadata, at the closest location

Specified by:
getAnnotatedValue in interface SiteData<Element>
Returns:
Throws:
java.io.IOException

getValue

public Element getValue(Location loc)
                 throws java.io.IOException
Returns the value from the underlying site data object, keeping track of the value in the cache. If the value is already in the cache, then just use that value.

Specified by:
getValue in interface SiteData<Element>
Returns:
Throws:
java.io.IOException

clearCache

public void clearCache()
Clear the cache. This is called if parameters are updated.


getValues

public java.util.ArrayList<Element> getValues(LocationList locs)
                                       throws java.io.IOException
Description copied from interface: SiteData
Get the value for each location in the given location list

Specified by:
getValues in interface SiteData<Element>
Returns:
Throws:
java.io.IOException

getAdjustableParameterList

public ParameterList getAdjustableParameterList()
Description copied from interface: SiteData
Returns a list of adjustable parameters. For many types of site data, this will be empty, but for more complex ones like WaldGlobalVs2007, it's more complicated.

Specified by:
getAdjustableParameterList in interface SiteData<Element>
Returns:

getApplicableRegion

public Region getApplicableRegion()
Description copied from interface: SiteData
This gives the applicable region for this data set.

Specified by:
getApplicableRegion in interface SiteData<Element>
Returns:
Region

getClosestDataLocation

public Location getClosestDataLocation(Location loc)
                                throws java.io.IOException
Description copied from interface: SiteData
Get the location of the closest data point

Specified by:
getClosestDataLocation in interface SiteData<Element>
Returns:
Throws:
java.io.IOException

getMetadata

public java.lang.String getMetadata()
Description copied from interface: SiteData
Returns the metadata for this dataset.

Specified by:
getMetadata in interface SiteData<Element>
Returns:

getName

public java.lang.String getName()
Description copied from interface: SiteData
Get the name of this dataset

Specified by:
getName in interface Named
Specified by:
getName in interface SiteData<Element>

getParameterListEditor

public ParameterListEditor getParameterListEditor()
Description copied from interface: SiteData
Returns an editor for the parameter list. This is required because some data providers might have more complex parameters schemes that require direct access to the parameter editor (such as for enabling or disabling of parameters).

Specified by:
getParameterListEditor in interface SiteData<Element>
Returns:

getResolution

public double getResolution()
Description copied from interface: SiteData
This gives the resolution of the dataset in degrees, or 0 for infinite resolution. We could possibly add a 'units' field to allow for resolution in KM

Specified by:
getResolution in interface SiteData<Element>
Returns:

getShortName

public java.lang.String getShortName()
Description copied from interface: SiteData
Get the short name of this dataset

Specified by:
getShortName in interface SiteData<Element>
Returns:

getDataType

public java.lang.String getDataType()
Description copied from interface: SiteData
Get the data type of this dataset

Specified by:
getDataType in interface SiteData<Element>
Returns:

getDataMeasurementType

public java.lang.String getDataMeasurementType()
Description copied from interface: SiteData
Get the measurement type for this data, such as "Measured" or "Inferred"

Specified by:
getDataMeasurementType in interface SiteData<Element>
Returns:

hasDataForLocation

public boolean hasDataForLocation(Location loc,
                                  boolean checkValid)
Description copied from interface: SiteData
Returns true if there is data for the given site

Specified by:
hasDataForLocation in interface SiteData<Element>
Parameters:
loc - - The location
checkValid - - Boolean for checking the validity of the value at the specified location
Returns:

isValueValid

public boolean isValueValid(Element el)
Description copied from interface: SiteData
Returns true if the value is valid, and not NaN, N/A, or equivelant for the data type

Specified by:
isValueValid in interface SiteData<Element>
Returns:

toXMLMetadata

public Element toXMLMetadata(Element root)
Specified by:
toXMLMetadata in interface XMLSaveable

getAnnotatedValues

public SiteDataValueList<Element> getAnnotatedValues(LocationList locs)
                                              throws java.io.IOException
Description copied from interface: SiteData
Get the values, with metadata, at the closest locations

Specified by:
getAnnotatedValues in interface SiteData<Element>
Returns:
Throws:
java.io.IOException

parameterChange

public void parameterChange(ParameterChangeEvent event)
Description copied from interface: ParameterChangeListener
Function that must be implemented by all Listeners for ParameterChangeEvents.

Specified by:
parameterChange in interface ParameterChangeListener
Parameters:
event - The Event which triggered this function call