net.agmodel.physical
Class StoreImpl

java.lang.Object
  |
  +--net.agmodel.physical.StoreImpl
All Implemented Interfaces:
Cloneable, Sequence, Serializable, Store
Direct Known Subclasses:
SynchronousStoreImpl

public abstract class StoreImpl
extends Object
implements Store, Serializable, Cloneable

Stores a time series of data collected during the partial interval (start,end] In the case of data measured over a subinterval the endpoint of the subinterval must lie in (start,end]
If interval straddles both start and end then it is also included.
Used by domain specific wrappers like net.agmodel.weatherData

interval data

   start______________end
     v                 v
 ----|=====       =====|----
  |=====|           |-----|
  |=======================|

 ==== included data
 ---- excluded data
 
point data
   start______________end
     v                 v
   . . OOOOOO         OO...
 OOO included data
 ... excluded data
 

See Also:
Serialized Form

Field Summary
protected  Interval dateRange
           
protected  SummaryHistory history
           
protected  String name
           
 
Constructor Summary
StoreImpl(Interval dateRange, SummaryHistory history, String name)
          Creates a new store covering the period of interest with history details.
 
Method Summary
 Store averageStore(Duration newResolution)
          Creates a new store with data averaged to a lower temporal resolution.
 Store averageStore(Duration newResolution, String newName)
          Creates a new store with data averaged to a lower temporal resolution.
 Object clone()
           
 Store extendStore(Date newEnd)
          Creates a new store with a copy of the same data covering a longer period.
 Store extendStore(Interval interval)
          Creates a new store at the same resolution as this one but covering a different DateRange.
abstract  JigsawQuantity getAverage(Interval interval)
          Returns the average value of the time series over the interval.
 String getColumnHeading()
          Returned a localized label for the Sequence
abstract  float[] getCoverage()
          Creates an array representing the coverage of the data returned by getData().
 Duration getCurrentResolution()
          Returns the current resolution of data in the sequence (eg daily);
abstract  double[] getData()
          Creates an array containing the data from the store.
 Interval getDateRange()
          Returns the date range for which data can be stored in the sequence
abstract  JigsawQuantity getInstant(Date time)
          Returns the instantaneous value of the time series at a particular point in time.
abstract  JigsawQuantity getMaximum(Interval interval)
          Returns the maximum value of the time series over the interval.
abstract  JigsawQuantity getMinimum(Interval interval)
          Returns the minimum value of the time series over the interval.
 String getName()
          Returns a language independent name for the Sequence This name is typically used as a resourceBundle key or to identify the Sequence programmatically.
 Duration getResolution()
          Returns the current resolution of data in the sequence (eg daily);
 SummaryHistory getSummaryHistory()
          Returns the summary history for the data stored in the sequence
 SummaryKind getSummaryKind()
          Returns the current summarykind of data in the sequence (eg averaged);
abstract  JigsawQuantity getTotal(Interval interval)
          Returns the total value of the sequence over the interval.
protected abstract  Store makeExtendedStore(Interval interval)
          Creates a new store at the same resolution as this one but covering a different DateRange.
protected abstract  Store makeSummarizedStore(Duration newResolution, SummaryKind summaryType, String newName)
          Creates a new, empty store at a lower temporal resolution covering the same dateRange.
 Store maximumStore(Duration newResolution)
          Creates a new store containing data summarised by finding the maximum of each subrange.
 Store maximumStore(Duration newResolution, String newName)
          Creates a new store containing data summarised by finding the maximum of each subrange.
 Store minimumStore(Duration newResolution)
          Creates a new store containing data summarised by finding the minimum of each subrange.
 Store minimumStore(Duration newResolution, String newName)
          Creates a new store containing data summarised by finding the minimum of each subrange.
abstract  void putInstantValue(Date time, double value)
          Records the instantaneous value of the time series at a particular time
abstract  void putValueOverInterval(Interval interval, double value)
          Records the value of the timeseries over some subinterval.
abstract  void putValueOverInterval(Interval interval, JigsawQuantity value)
          Records the value of the timeseries over some subinterval, its coverage, and the extent to which it was interpolated.
 Store sampleStore(Duration newResolution)
          Creates a new store with data sampled to a lower temporal resolution.
 Store sampleStore(Duration newResolution, String newName)
          Creates a new store with data sampled to a lower temporal resolution.
 void setColumnHeading(String aHeading)
          Set the localized label for the Sequence
 void setName(String aName)
          Sets the language independent name for the Sequence This name is typically used as a resourceBundle key or to identify the Sequence programmatically.
 Store totalStore(Duration newResolution)
          Creates a new store with data totalled to a lower temporal resolution.
 Store totalStore(Duration newResolution, String newName)
          Creates a new store with data totalled to a lower temporal resolution.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.agmodel.physical.Store
getNumberOfValues
 
Methods inherited from interface net.agmodel.physical.Sequence
dumpSequence, getContentsAsString, getNumberOfSubComponents, getSequenceHeading, getSubHeading, getUnitsHeading
 

Field Detail

name

protected String name

dateRange

protected Interval dateRange

history

protected SummaryHistory history
Constructor Detail

StoreImpl

public StoreImpl(Interval dateRange,
                 SummaryHistory history,
                 String name)
Creates a new store covering the period of interest with history details. May allocate memory for storage at this point.

Parameters:
dateRange - the date range over which data can be stored.
history - how the data in the store has been summarised.
Method Detail

getDateRange

public Interval getDateRange()
Description copied from interface: Sequence
Returns the date range for which data can be stored in the sequence

Specified by:
getDateRange in interface Sequence
Returns:
the date range

getSummaryHistory

public SummaryHistory getSummaryHistory()
Description copied from interface: Store
Returns the summary history for the data stored in the sequence

Specified by:
getSummaryHistory in interface Store
Returns:
the composition

getResolution

public Duration getResolution()
Description copied from interface: Sequence
Returns the current resolution of data in the sequence (eg daily);

Specified by:
getResolution in interface Sequence

getSummaryKind

public SummaryKind getSummaryKind()
Description copied from interface: Sequence
Returns the current summarykind of data in the sequence (eg averaged);

Specified by:
getSummaryKind in interface Sequence

getCurrentResolution

public Duration getCurrentResolution()
Description copied from interface: Sequence
Returns the current resolution of data in the sequence (eg daily);

Specified by:
getCurrentResolution in interface Sequence

getName

public String getName()
Description copied from interface: Sequence
Returns a language independent name for the Sequence This name is typically used as a resourceBundle key or to identify the Sequence programmatically. It should be localized before presentation to users.

Specified by:
getName in interface Sequence

setName

public void setName(String aName)
Description copied from interface: Sequence
Sets the language independent name for the Sequence This name is typically used as a resourceBundle key or to identify the Sequence programmatically. It should be localized before presentation to users.

Specified by:
setName in interface Sequence
Parameters:
aName - the new heading

getColumnHeading

public String getColumnHeading()
Deprecated. use getName() instead

Description copied from interface: Sequence
Returned a localized label for the Sequence

Specified by:
getColumnHeading in interface Sequence

setColumnHeading

public void setColumnHeading(String aHeading)
Deprecated. use setName(String) instead

Description copied from interface: Sequence
Set the localized label for the Sequence

Specified by:
setColumnHeading in interface Sequence
Parameters:
aHeading - the new heading

putInstantValue

public abstract void putInstantValue(Date time,
                                     double value)
Description copied from interface: Store
Records the instantaneous value of the time series at a particular time

Specified by:
putInstantValue in interface Store
Parameters:
time - the point in time
value - the value of the time series at that time

putValueOverInterval

public abstract void putValueOverInterval(Interval interval,
                                          double value)
Description copied from interface: Store
Records the value of the timeseries over some subinterval. It is assumed that the subinterval coverage is complete (ie there is no missing data in the subinterval) and that no interpolation took place.
If the store contains totalled data, and interval>currentResolution, then the data will be evenly distributed between the "cells" of the store.

Specified by:
putValueOverInterval in interface Store
Parameters:
interval - the period of time over which the measurement was taken. Interval duration must a postive integer multiple of store resolution, and the interval must align with the store "cells".
value - the value of the time series over that interval

putValueOverInterval

public abstract void putValueOverInterval(Interval interval,
                                          JigsawQuantity value)
Description copied from interface: Store
Records the value of the timeseries over some subinterval, its coverage, and the extent to which it was interpolated. If the store contains totalled data, and interval>currentResolution, then the data will be evenly distributed between the "cells" of the store.

Specified by:
putValueOverInterval in interface Store
Parameters:
interval - the period of time over which the measurement was taken. Interval duration must a positive integer multiple of store resolution, and the interval must align with the store "cells".
value - the value of the time series over that interval as a JigsawQuantity

getInstant

public abstract JigsawQuantity getInstant(Date time)
Description copied from interface: Store
Returns the instantaneous value of the time series at a particular point in time. If interpolation is requested, the value may be spatially and/or temporally interpolated from other data.

Specified by:
getInstant in interface Store
Returns:
the instantaneous value

getAverage

public abstract JigsawQuantity getAverage(Interval interval)
Description copied from interface: Store
Returns the average value of the time series over the interval. Sequence values at either end of the interval are included by weighting their values according to the proportion of their duration that lies in the period of interest.

Specified by:
getAverage in interface Store
Returns:
the average value

getMinimum

public abstract JigsawQuantity getMinimum(Interval interval)
Description copied from interface: Store
Returns the minimum value of the time series over the interval. Sequence values at either end of the interval are included in the comparison if more than 50% of their duration lies within the interval of interest. If exactly 50% of their duration lies within the interval, then the first measurement is omitted and the last measurement is included

Specified by:
getMinimum in interface Store
Returns:
the minimum value

getMaximum

public abstract JigsawQuantity getMaximum(Interval interval)
Description copied from interface: Store
Returns the maximum value of the time series over the interval. Sequence values at either end of the interval are included in the comparison if more than 50% of their duration lies within the interval of interest. If exactly 50% of their duration lies within the interval, then the first measurement is omitted and the last measurement is included

Specified by:
getMaximum in interface Store
Returns:
the maximum value

getTotal

public abstract JigsawQuantity getTotal(Interval interval)
Description copied from interface: Store
Returns the total value of the sequence over the interval. Weighted contributions from sequence values at either end of the interval are included based on the extent to which they "fall into" the interval. Point measurements are interpreted as if they represented an interval ending at the sample time. If data is missing, the total returned is just the total of the available data; the returned value not scaled up in any way. This ensures that, for example, rainfall for the current day is not overestimated.

Specified by:
getTotal in interface Store
Returns:
the total value

totalStore

public Store totalStore(Duration newResolution)
Description copied from interface: Store
Creates a new store with data totalled to a lower temporal resolution. eg total hourly data into daily data.
The new store's default name is provided by SummaryKind.TOTAL.getName().

Specified by:
totalStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
Returns:
a new sequence of totals at the requested resolution

totalStore

public Store totalStore(Duration newResolution,
                        String newName)
Description copied from interface: Store
Creates a new store with data totalled to a lower temporal resolution. eg total hourly data into daily data.

Specified by:
totalStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
newName - the new name for the store
Returns:
a new sequence of totals at the requested resolution

averageStore

public Store averageStore(Duration newResolution)
Description copied from interface: Store
Creates a new store with data averaged to a lower temporal resolution. eg average hourly data into daily data. The new store's default name is provided by SummaryKind.AVERAGE.getName(). See Store.totalStore(Duration) for information on how the first data value is handled.

Specified by:
averageStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
Returns:
a new sequence of averages at the requested resolution

averageStore

public Store averageStore(Duration newResolution,
                          String newName)
Description copied from interface: Store
Creates a new store with data averaged to a lower temporal resolution. eg average hourly data into daily data. See Store.totalStore(Duration) for information on how the first data value is handled.

Specified by:
averageStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
newName - the new name for the store
Returns:
a new sequence of averages at the requested resolution

minimumStore

public Store minimumStore(Duration newResolution)
Description copied from interface: Store
Creates a new store containing data summarised by finding the minimum of each subrange. The new store's default name is provided by SummaryKind.MINIMUM.getName(). See Store.totalStore(Duration) for information on how the first data value is handled.

Specified by:
minimumStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
Returns:
a new sequence of minimums at the requested resolution

minimumStore

public Store minimumStore(Duration newResolution,
                          String newName)
Description copied from interface: Store
Creates a new store containing data summarised by finding the minimum of each subrange. See Store.totalStore(Duration) for information on how the first data value is handled.

Specified by:
minimumStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
newName - the new name for the store
Returns:
a new sequence of minimums at the requested resolution

maximumStore

public Store maximumStore(Duration newResolution)
Description copied from interface: Store
Creates a new store containing data summarised by finding the maximum of each subrange. See Store.totalStore(Duration) for information on how the first data value is handled. The new store's default name is provided by SummaryKind.MAXIMUM.getName().

Specified by:
maximumStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
Returns:
a new sequence of maximums at the requested resolution

maximumStore

public Store maximumStore(Duration newResolution,
                          String newName)
Description copied from interface: Store
Creates a new store containing data summarised by finding the maximum of each subrange. See Store.totalStore(Duration) for information on how the first data value is handled.

Specified by:
maximumStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
newName - the new name for the store
Returns:
a new sequence of maximums at the requested resolution

sampleStore

public Store sampleStore(Duration newResolution)
Description copied from interface: Store
Creates a new store with data sampled to a lower temporal resolution. eg sample hourly data into daily data. Data is sampled at the end of subintervals. The new store's default name is provided by SummaryKind.SAMPLE.getName(). See Store.totalStore(Duration) for information on how the first data value is handled.

Specified by:
sampleStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
Returns:
a new sequence of samples at the requested resolution

sampleStore

public Store sampleStore(Duration newResolution,
                         String newName)
Description copied from interface: Store
Creates a new store with data sampled to a lower temporal resolution. eg sample hourly data into daily data. Data is sampled at the end of subintervals. See Store.totalStore(Duration) for information on how the first data value is handled.

Specified by:
sampleStore in interface Store
Parameters:
newResolution - the resolution of the resulting sequence
newName - the new name for the store
Returns:
a new sequence of samples at the requested resolution

extendStore

public Store extendStore(Interval interval)
Description copied from interface: Store
Creates a new store at the same resolution as this one but covering a different DateRange.
If the period covered by the two stores overlaps, the new store contains a copy of the data in the overlap. Data is transferred using getInstant() and putInstant().

Specified by:
extendStore in interface Store
Parameters:
interval - the interval that the new store covers.
Returns:
the new store.

extendStore

public Store extendStore(Date newEnd)
Description copied from interface: Store
Creates a new store with a copy of the same data covering a longer period.
The new store's resolution and starting point are the same as this one's. Data is transferred using getInstant() and putInstant().

Specified by:
extendStore in interface Store
Parameters:
newEnd - the new end date, later than the current end date;
Returns:
the new store.

makeSummarizedStore

protected abstract Store makeSummarizedStore(Duration newResolution,
                                             SummaryKind summaryType,
                                             String newName)
Creates a new, empty store at a lower temporal resolution covering the same dateRange.

Parameters:
newResolution - the resolution of the resulting store
summaryType - the way in which data will be summarised to make the new store.
newName - the name for the new store
Returns:
a new, empty store.

makeExtendedStore

protected abstract Store makeExtendedStore(Interval interval)
Creates a new store at the same resolution as this one but covering a different DateRange.

Parameters:
interval - the interval that the new store covers.
Returns:
a new, empty store.

getData

public abstract double[] getData()
Description copied from interface: Store
Creates an array containing the data from the store. You should use Store.getCoverage() to test for the coverage. (Missing values are returned as Double.NaN at present, but this might change.)
Note that the first element of the array corresponds to getStart() and is therefore empty in most cases.

Specified by:
getData in interface Store
Returns:
the data in a timeseries array

getCoverage

public abstract float[] getCoverage()
Description copied from interface: Store
Creates an array representing the coverage of the data returned by Store.getData().

Specified by:
getCoverage in interface Store
Returns:
an array of values ranging from JigsawQuantity.COMPLETE to JigsawQuantity.DEVOID.

clone

public Object clone()
Specified by:
clone in interface Sequence
Overrides:
clone in class Object