net.agmodel.physical
Class SynchronousStoreImpl

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

public class SynchronousStoreImpl
extends StoreImpl
implements Cloneable

An implementation of Store which uses an array to store data and their derivation Most suitable for regularly spaced data which continually fluctuate, such as hourly temperatures

See Also:
Serialized Form

Field Summary
protected static byte COVERAGEMASK
           
protected static byte SPATIALMASK
           
protected static byte TEMPORALMASK
           
 
Fields inherited from class net.agmodel.physical.StoreImpl
dateRange, history, name
 
Constructor Summary
SynchronousStoreImpl(Interval dateRange, SummaryHistory history, String name)
           
 
Method Summary
 Object clone()
           
 String dumpSequence(DateFormat df, String delimiter, String rowTerminator)
          Gets a printable version of the sequence contents.
 JigsawQuantity getAverage(Interval interval)
          Returns the average value of the time series over the interval.
 int getCapacity()
          Returns the number of possible data values in the store.
 String getContentsAsString(Date date, String delimiter)
          Returns the measurement associated with a particular time as a string.
 float[] getCoverage()
          Creates an array representing the coverage of the data returned by getData().
 double[] getData()
          Creates an array containing the data from the store.
protected  float getDerivation(int index)
           
 JigsawQuantity getInstant(Date time)
          Returns the instantaneous value of the time series at a particular point in time.
 JigsawQuantity getMaximum(Interval interval)
          Returns the maximum value of the time series over the interval.
 JigsawQuantity getMinimum(Interval interval)
          Returns the minimum value of the time series over the interval.
 int getNumberOfSubComponents()
          Get the number of sub-components in the sequence.
 double getNumberOfValues()
          Returns the number of data values in the store
 String getSequenceHeading(String delimiter)
          Returns a localized top level description of the kind of data stored in the sequence.
protected  boolean getSpatialInterpolation(int index)
           
 String getSubHeading(String delimiter)
          Gets a localized subheading, assumed to be in the context of an overall column heading.
protected  boolean getTemporalInterpolation(int index)
           
 JigsawQuantity getTotal(Interval interval)
          Returns the total value of the sequence over the interval.
 String getUnitsHeading(String delimiter)
          Gets a string representation of the measurement units of the column.
protected  Store makeExtendedStore(Interval interval)
          Creates a new store at the same resolution as this one but covering a different DateRange.
protected  Store makeSummarizedStore(Duration newResolution, SummaryKind summaryType, String newName)
          Creates a new, empty store at a lower temporal resolution covering the same dateRange.
protected  int numbValues()
           
 void putInstantValue(Date time, double value)
          Records the instantaneous value of the time series at a particular time
 void putValueOverInterval(Interval interval, double value)
          Records the value of the timeseries over some subinterval.
 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.
protected  void setDerivation(int index, float coverage, boolean temporal, boolean spatial)
           
protected  JigsawQuantity summarizeOverInterval(Interval interval, SummaryKind summaryKind)
           
 String toString()
           
 
Methods inherited from class net.agmodel.physical.StoreImpl
averageStore, averageStore, extendStore, extendStore, getColumnHeading, getCurrentResolution, getDateRange, getName, getResolution, getSummaryHistory, getSummaryKind, maximumStore, maximumStore, minimumStore, minimumStore, sampleStore, sampleStore, setColumnHeading, setName, totalStore, totalStore
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SPATIALMASK

protected static byte SPATIALMASK

TEMPORALMASK

protected static byte TEMPORALMASK

COVERAGEMASK

protected static byte COVERAGEMASK
Constructor Detail

SynchronousStoreImpl

public SynchronousStoreImpl(Interval dateRange,
                            SummaryHistory history,
                            String name)
Method Detail

numbValues

protected int numbValues()

getNumberOfValues

public double getNumberOfValues()
Description copied from interface: Store
Returns the number of data values in the store

Specified by:
getNumberOfValues in interface Store
Returns:
the number of data values stored. If the data is summarised, this may be fractional

getCapacity

public int getCapacity()
Returns the number of possible data values in the store.


getDerivation

protected float getDerivation(int index)

setDerivation

protected void setDerivation(int index,
                             float coverage,
                             boolean temporal,
                             boolean spatial)

getSpatialInterpolation

protected boolean getSpatialInterpolation(int index)

getTemporalInterpolation

protected boolean getTemporalInterpolation(int index)

getInstant

public 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
Specified by:
getInstant in class StoreImpl
Returns:
the instantaneous value

getTotal

public 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
Specified by:
getTotal in class StoreImpl
Returns:
the total value

summarizeOverInterval

protected JigsawQuantity summarizeOverInterval(Interval interval,
                                               SummaryKind summaryKind)

getAverage

public 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
Specified by:
getAverage in class StoreImpl
Returns:
the average value

getMaximum

public 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
Specified by:
getMaximum in class StoreImpl
Returns:
the maximum value

getMinimum

public 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
Specified by:
getMinimum in class StoreImpl
Returns:
the minimum value

putInstantValue

public 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
Specified by:
putInstantValue in class StoreImpl
Parameters:
time - the point in time
value - the value of the time series at that time

putValueOverInterval

public 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
Specified by:
putValueOverInterval in class StoreImpl
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 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
Specified by:
putValueOverInterval in class StoreImpl
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

getSequenceHeading

public String getSequenceHeading(String delimiter)
Description copied from interface: Sequence
Returns a localized top level description of the kind of data stored in the sequence. This value can be used as a column heading if the sequence is listed. If there is more than one component in the heading, this value is right-padded with additional delimiters - one for each component.

Specified by:
getSequenceHeading in interface Sequence
Parameters:
delimiter - the delimiter to use if padding is required for multiple columns

getSubHeading

public String getSubHeading(String delimiter)
Description copied from interface: Sequence
Gets a localized subheading, assumed to be in the context of an overall column heading.

Specified by:
getSubHeading in interface Sequence
Parameters:
delimiter - the delimiter to use between columns if there are multiple columns
See Also:
Sequence.getNumberOfSubComponents(), Sequence.getSequenceHeading(String)

getUnitsHeading

public String getUnitsHeading(String delimiter)
Description copied from interface: Sequence
Gets a string representation of the measurement units of the column. This value is typically used as part of the column heading when the sequence is listed. It is assumed to be in the context of an overall column heading.

Specified by:
getUnitsHeading in interface Sequence
Parameters:
delimiter - the delimiter to use between columns if there are multiple columns
See Also:
Sequence.getNumberOfSubComponents(), Sequence.getSequenceHeading(String), Sequence.getSubHeading(String)

getNumberOfSubComponents

public int getNumberOfSubComponents()
Description copied from interface: Sequence
Get the number of sub-components in the sequence. This indicates how many "columns" the sequence output will occupy.

Specified by:
getNumberOfSubComponents in interface Sequence
Returns:
the number of sub-components
See Also:
Sequence.getSequenceHeading(String)

makeSummarizedStore

protected Store makeSummarizedStore(Duration newResolution,
                                    SummaryKind summaryType,
                                    String newName)
Description copied from class: StoreImpl
Creates a new, empty store at a lower temporal resolution covering the same dateRange.

Specified by:
makeSummarizedStore in class StoreImpl
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 Store makeExtendedStore(Interval interval)
Description copied from class: StoreImpl
Creates a new store at the same resolution as this one but covering a different DateRange.

Specified by:
makeExtendedStore in class StoreImpl
Parameters:
interval - the interval that the new store covers.
Returns:
a new, empty store.

getContentsAsString

public String getContentsAsString(Date date,
                                  String delimiter)
Description copied from interface: Sequence
Returns the measurement associated with a particular time as a string. Used by dumpSequence.

Specified by:
getContentsAsString in interface Sequence
Parameters:
date - the time of interest.
delimiter - a string to use between values if required.

dumpSequence

public String dumpSequence(DateFormat df,
                           String delimiter,
                           String rowTerminator)
Description copied from interface: Sequence
Gets a printable version of the sequence contents.
Data is formatted with a line for each time interval.
The first field in the line is the date and time, formatted using the DateFormat passed as a parameter.
The data for that time interval follows, separated by the default delimiter, with a new line character at the end of the row.

Specified by:
dumpSequence in interface Sequence
Parameters:
df - the format to use for the date and time
delimiter - the separator to use between the date and the data
rowTerminator - the String used at the end of each row
Returns:
a string containing all the sequences data with formatted times.

getData

public 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
Specified by:
getData in class StoreImpl
Returns:
the data in a timeseries array

getCoverage

public 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
Specified by:
getCoverage in class StoreImpl
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 StoreImpl

toString

public String toString()
Overrides:
toString in class Object