com.jrefinery.data
Class BasicTimeSeries

java.lang.Object
  extended by com.jrefinery.data.Series
      extended by com.jrefinery.data.BasicTimeSeries
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class BasicTimeSeries
extends Series

Represents a sequence of zero or more data pairs in the form (period, value).

See Also:
Serialized Form

Field Summary
protected  java.util.List data
          The list of data pairs in the series.
protected static java.lang.String DEFAULT_DOMAIN_DESCRIPTION
          Default value for the domain description.
protected static java.lang.String DEFAULT_RANGE_DESCRIPTION
          Default value for the range description.
protected  java.lang.String domain
          A description of the domain.
protected  java.lang.String range
          A description of the range.
protected  java.lang.Class timePeriodClass
          The type of period for the data.
 
Fields inherited from class com.jrefinery.data.Series
description, listeners, name, propertyChangeSupport
 
Constructor Summary
BasicTimeSeries(java.lang.String name)
          Creates a new (empty) time series.
BasicTimeSeries(java.lang.String name, java.lang.Class timePeriodClass)
          Creates a new (empty) time series.
BasicTimeSeries(java.lang.String name, java.lang.String domain, java.lang.String range, java.lang.Class timePeriodClass)
          Creates a new time series that contains no data.
 
Method Summary
 void add(TimePeriod period, double value)
          Adds a new data item to the series.
 void add(TimePeriod period, java.lang.Number value)
          Adds a new data item to the series.
 void add(TimeSeriesDataPair pair)
          Adds a data item to the series.
 BasicTimeSeries addAndOrUpdate(BasicTimeSeries series)
          Adds or updates data from one series to another.
 TimeSeriesDataPair addOrUpdate(TimePeriod period, java.lang.Number value)
          Adds or updates the times series.
 java.lang.Object clone()
          Returns a clone of the time series.
 BasicTimeSeries createCopy(int start, int end)
          Creates a new timeseries by copying a subset of the data in this time series.
 BasicTimeSeries createCopy(TimePeriod start, TimePeriod end)
          Creates a new timeseries by copying a subset of the data in this time series.
 BasicTimeSeries delete(int start, int end)
          Deletes data between the start and end index.
 void delete(TimePeriod period)
          Deletes data for the given time period.
 TimeSeriesDataPair getDataPair(int index)
          Returns one data pair for the series.
 TimeSeriesDataPair getDataPair(TimePeriod period)
          Returns the data pair for a specific period.
 java.lang.String getDomainDescription()
          Returns the domain description.
 int getIndex(TimePeriod period)
          Returns the index of the specified time period.
 int getItemCount()
          Returns the number of items in the series.
 TimePeriod getNextTimePeriod()
          Returns a time period that would be the next in sequence on the end of the time series.
 java.lang.String getRangeDescription()
          Returns the range description.
 TimePeriod getTimePeriod(int index)
          Returns the time period at the specified index.
 java.lang.Class getTimePeriodClass()
          Returns the time period class for this series.
 java.util.Collection getTimePeriods()
          Returns a collection of all the time periods in the time series.
 java.util.Collection getTimePeriodsUniqueToOtherSeries(BasicTimeSeries series)
          Returns a collection of time periods in the specified series, but not in this series, and therefore unique to the specified series.
 java.lang.Number getValue(int index)
          Returns the value at the specified index.
 java.lang.Number getValue(TimePeriod period)
          Returns the value for a time period.
static void main(java.lang.String[] args)
          Test code - please ignore.
 void setDomainDescription(java.lang.String description)
          Sets the domain description.
 void setRangeDescription(java.lang.String description)
          Sets the range description.
 void update(int index, java.lang.Number value)
          Updates (changes) the value of a data pair.
 void update(TimePeriod period, java.lang.Number value)
          Updates (changes) the value for a time period.
 
Methods inherited from class com.jrefinery.data.Series
addChangeListener, addPropertyChangeListener, fireSeriesChanged, getDescription, getName, notifyListeners, removeChangeListener, removePropertyChangeListener, setDescription, setName
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DOMAIN_DESCRIPTION

protected static final java.lang.String DEFAULT_DOMAIN_DESCRIPTION
Default value for the domain description.

See Also:
Constant Field Values

DEFAULT_RANGE_DESCRIPTION

protected static final java.lang.String DEFAULT_RANGE_DESCRIPTION
Default value for the range description.

See Also:
Constant Field Values

domain

protected java.lang.String domain
A description of the domain.


range

protected java.lang.String range
A description of the range.


timePeriodClass

protected java.lang.Class timePeriodClass
The type of period for the data.


data

protected java.util.List data
The list of data pairs in the series.

Constructor Detail

BasicTimeSeries

public BasicTimeSeries(java.lang.String name)
Creates a new (empty) time series.

By default, a daily time series is created. Use one of the other constructors if you require a different time period.

Parameters:
name - The name of the series.

BasicTimeSeries

public BasicTimeSeries(java.lang.String name,
                       java.lang.Class timePeriodClass)
Creates a new (empty) time series.

Parameters:
name - The series name.
timePeriodClass - The type of time period.

BasicTimeSeries

public BasicTimeSeries(java.lang.String name,
                       java.lang.String domain,
                       java.lang.String range,
                       java.lang.Class timePeriodClass)
Creates a new time series that contains no data.

Descriptions can be specified for the domain and range. One situation where this is helpful is when generating a chart for the time series - axis labels can be taken from the domain and range description.

Parameters:
name - The name of the series.
domain - The domain description.
range - The range description.
Method Detail

getDomainDescription

public java.lang.String getDomainDescription()
Returns the domain description.

Returns:
The domain description.

setDomainDescription

public void setDomainDescription(java.lang.String description)
Sets the domain description.

A property change event is fired, and an undoable edit is posted.

Parameters:
description - The new description.

getRangeDescription

public java.lang.String getRangeDescription()
Returns the range description.

Returns:
The range description.

setRangeDescription

public void setRangeDescription(java.lang.String description)
Sets the range description.

Registered listeners are notified of the change.

Parameters:
description - The new description.

getItemCount

public int getItemCount()
Returns the number of items in the series.

Returns:
The item count.

getTimePeriodClass

public java.lang.Class getTimePeriodClass()
Returns the time period class for this series.

Only one time period class can be used within a single series (enforced). If you add a data item with a Year for the time period, then all subsequent data items must also have a Year for the time period.

Returns:
The time period class for this series (null if the series is empty).

getDataPair

public TimeSeriesDataPair getDataPair(int index)
Returns one data pair for the series.

Parameters:
index - The index within the series (zero-based).
Returns:
One data pair for the series.

getDataPair

public TimeSeriesDataPair getDataPair(TimePeriod period)
Returns the data pair for a specific period.

Parameters:
period - The period of interest.
Returns:
The data pair matching the specified period (or null if there is no match).

getTimePeriod

public TimePeriod getTimePeriod(int index)
Returns the time period at the specified index.

Returns:
The time period at the specified index.

getNextTimePeriod

public TimePeriod getNextTimePeriod()
Returns a time period that would be the next in sequence on the end of the time series.


getTimePeriods

public java.util.Collection getTimePeriods()
Returns a collection of all the time periods in the time series.


getTimePeriodsUniqueToOtherSeries

public java.util.Collection getTimePeriodsUniqueToOtherSeries(BasicTimeSeries series)
Returns a collection of time periods in the specified series, but not in this series, and therefore unique to the specified series.


getIndex

public int getIndex(TimePeriod period)
Returns the index of the specified time period.

Returns:
The index of the specified time period.

getValue

public java.lang.Number getValue(int index)
Returns the value at the specified index.

Returns:
The value at the specified index.

getValue

public java.lang.Number getValue(TimePeriod period)
Returns the value for a time period.

Returns:
The value (null if the time period is not in the series).

add

public void add(TimeSeriesDataPair pair)
         throws SeriesException
Adds a data item to the series.

Parameters:
pair - The (timeperiod, value) pair.
Throws:
SeriesException

add

public void add(TimePeriod period,
                double value)
         throws SeriesException
Adds a new data item to the series.

Parameters:
period - The time period.
value - The value.
Throws:
SeriesException

add

public void add(TimePeriod period,
                java.lang.Number value)
         throws SeriesException
Adds a new data item to the series.

Parameters:
period - The time period.
value - The value.
Throws:
SeriesException

update

public void update(TimePeriod period,
                   java.lang.Number value)
            throws SeriesException
Updates (changes) the value for a time period. Ignores the update if the period does not exist.

Parameters:
period - The period to update.
value - The new value.
Throws:
SeriesException

update

public void update(int index,
                   java.lang.Number value)
Updates (changes) the value of a data pair.

Parameters:
index - The index of the data pair to update.
value - The new value.

addAndOrUpdate

public BasicTimeSeries addAndOrUpdate(BasicTimeSeries series)
Adds or updates data from one series to another. Returns another series containing the values that were overwritten.


addOrUpdate

public TimeSeriesDataPair addOrUpdate(TimePeriod period,
                                      java.lang.Number value)
Adds or updates the times series.

Parameters:
period - The time period to add/update.
value - The new value.
Returns:
A copy of the overwritten data pair (or null).

delete

public void delete(TimePeriod period)
Deletes data for the given time period.


delete

public BasicTimeSeries delete(int start,
                              int end)
Deletes data between the start and end index.


clone

public java.lang.Object clone()
Returns a clone of the time series.

Notes: --> no need to clone the domain and range descriptions, since String object is immutable; --> we pass over to the more general method clone(start, end).

Overrides:
clone in class Series

createCopy

public BasicTimeSeries createCopy(int start,
                                  int end)
Creates a new timeseries by copying a subset of the data in this time series.


createCopy

public BasicTimeSeries createCopy(TimePeriod start,
                                  TimePeriod end)
Creates a new timeseries by copying a subset of the data in this time series.


main

public static void main(java.lang.String[] args)
Test code - please ignore.



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.