com.jstatcom.ts
Class TS
- java.lang.Object
-
- com.jstatcom.ts.TS
-
public final class TS extends java.lang.ObjectThis class pools information about a particular time series:- name
- observations
- start date
- project
TSobject must have at least one observation, the data is therefore initialized withnew double[1]. Any attempt to set the data to a zero length array or tonullis ignored.Once a time series is created, it is not possible anymore to change the underlying data, instead, a new
TSmust be instantiated. The type may be changed. Type changes throw aTS_TYPE_CHANGED PropertyChangeEvent.This class is thread-safe. All access to mutable data is synchronized.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringTS_TYPE_CHANGEDType changed property event name.
-
Constructor Summary
Constructors Constructor and Description TS(double[] newObservations, java.lang.String newName)Creates aTSobject with the type being guessed and the project is the default.TS(double[] newObservations, java.lang.String newName, TSDate newDate)Creates aTSobject, with the type being guessed and the project is the default.TS(double[] newObservations, java.lang.String newName, TSDate newDate, TSTypes tsType)Creates aTSobject with the default project.TS(double[] newObservations, java.lang.String newName, TSDate newDate, TSTypes tsType, TSProject newProject)Preferred constructor for aTSobject with everything explicitely specified.TS(TS ts)TScopy-constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)TScreateDiff(int periods)Applies the difference operator to a copy of the series and returns the new series with the nameoldName + "_d" + Math.abs(periods).TScreateLog()Applies the log operator to a copy of the series and returns the new series with the nameoldName + "_log".booleanequals(java.lang.Object o)Overridesequals()to provide logical comparison of two different TS.static double[][]getMergedData(TS[] tsArray)Gets the merged data of all time series in the given array.inthashCode()OverrideshashCode, because equals was overwritten.java.lang.Stringname()Returns the identifying name of this time series object.intnumOfObs()Returns the number of observations.voidprint(java.io.PrintStream p)Prints this object to the argument print stream with the time index and the respective observation next to it.TSProjectproject()Gets project that thisTSbelongs to.TSDateRangerange()Returns theTSDateRangedefining the beginning and the end of this time series.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)voidsetName(java.lang.String newValue)Sets the name of this time series to a new name.voidsetTSProject(TSProject newTSProject)Sets project that this TS belongs to.voidsetTSType(TSTypes newTSType)Sets the type of this time series.TSDatestart()Returns the date when the first observation in thisTSoccurs.java.lang.StringtoString()String representation of a timeseries.TSTypestype()Gets the type of this time series.doublevalueAt(int i)Returns the observation at indexi.doublevalueAt(TSDate date)Returns the observation at a given date.double[]values()Returns a copy of the array of observations.
-
-
-
Field Detail
-
TS_TYPE_CHANGED
public static final java.lang.String TS_TYPE_CHANGED
Type changed property event name.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TS
public TS(double[] newObservations, java.lang.String newName)Creates aTSobject with the type being guessed and the project is the default. For the start date theTSDatedefault constructor is used.- Parameters:
newObservations- the array of observationsnewName- the identifying name- Throws:
java.lang.IllegalArgumentException- ifnewNameisnull
-
TS
public TS(double[] newObservations, java.lang.String newName, TSDate newDate)Creates aTSobject, with the type being guessed and the project is the default.- Parameters:
newObservations- the array of observationsnewName- the identifying namenewDate- the date of the first observation.- Throws:
java.lang.IllegalArgumentException- ifnewNameornewDateisnull
-
TS
public TS(double[] newObservations, java.lang.String newName, TSDate newDate, TSTypes tsType)Creates aTSobject with the default project.- Parameters:
newObservations- the array of observationsnewName- the identifying namenewDate- the date of the first observation.tsType- the type ornullif it should be automatically defined- Throws:
java.lang.IllegalArgumentException- ifnewNameornewDateisnull
-
TS
public TS(double[] newObservations, java.lang.String newName, TSDate newDate, TSTypes tsType, TSProject newProject)Preferred constructor for aTSobject with everything explicitely specified.- Parameters:
newObservations- the array of observationsnewName- the identifying namenewDate- the date of the first observation.tsType- the type ornullif it should be automatically definednewProject- the time series project- Throws:
java.lang.IllegalArgumentException- ifnewNameornewDateisnull
-
TS
public TS(TS ts)
TScopy-constructor.- Parameters:
ts- theTSto copy
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
-
createDiff
public TS createDiff(int periods)
Applies the difference operator to a copy of the series and returns the new series with the nameoldName + "_d" + Math.abs(periods). If periods is the same as the sub periodicity and the sub periodicity > 1, the new name isoldName + "_dseas".- Parameters:
periods- the number of lags of the part being subtracted from the original series, it may also be < 0- Returns:
- the differenced time series or
nullif the operation failed.
-
createLog
public TS createLog()
Applies the log operator to a copy of the series and returns the new series with the nameoldName + "_log".- Returns:
- TS the logged time series or
null, if the operation failed.
-
equals
public boolean equals(java.lang.Object o)
Overridesequals()to provide logical comparison of two different TS.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to compare- Returns:
trueif name, start, all observations and type are the same,falseotherwise
-
values
public double[] values()
Returns a copy of the array of observations.- Returns:
- copied data array
-
valueAt
public double valueAt(int i)
Returns the observation at indexi.- Parameters:
i- the index to retrieve the data from- Returns:
- the respective observation if
iis within the range of this time series, otherwiseDouble.NaN
-
valueAt
public double valueAt(TSDate date)
Returns the observation at a given date.- Parameters:
date- theTSDatefor the observation, if it is invalid, thenDouble.NaNis returned- Returns:
- the respective observation if date is within the range of this
time series, otherwise
Double.NaN
-
getMergedData
public static double[][] getMergedData(TS[] tsArray)
Gets the merged data of all time series in the given array. The merge range starts from the earliest start date till the latest end date of all series.- Parameters:
tsArray- an array ofTSobjects- Returns:
- the data starting from the earliest till the latest observation
over all time series in the array, filled with
Double.NaNif no observation is available for a series in the array at a certain date - Throws:
java.lang.IllegalArgumentException- if oneTSisnullor if sub periodicities are different
-
name
public java.lang.String name()
Returns the identifying name of this time series object.- Returns:
- the name of this series
-
numOfObs
public int numOfObs()
Returns the number of observations.- Returns:
- number of observations.
-
start
public TSDate start()
Returns the date when the first observation in thisTSoccurs.- Returns:
- the date of the first observation.
-
range
public TSDateRange range()
Returns theTSDateRangedefining the beginning and the end of this time series.- Returns:
- the range for the observations
-
project
public TSProject project()
Gets project that thisTSbelongs to.- Returns:
- the current project
-
type
public TSTypes type()
Gets the type of this time series.- Returns:
- the type of this series
- See Also:
setTSType(com.jstatcom.ts.TSTypes)
-
hashCode
public int hashCode()
OverrideshashCode, because equals was overwritten. The algorithm was taken from (Joshua Bloch, "Effective Java", Item 8) .- Overrides:
hashCodein classjava.lang.Object- Returns:
- hash code
-
print
public void print(java.io.PrintStream p)
Prints this object to the argument print stream with the time index and the respective observation next to it.- Parameters:
p- the stream to print to
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
-
setName
public void setName(java.lang.String newValue)
Sets the name of this time series to a new name. The name must not benullor empty. The name must begin either with '_' .- Parameters:
newValue- the new name.- Throws:
java.lang.IllegalArgumentException- if newValue isnull, empty or if it does not start with a letter or '_'
-
setTSProject
public void setTSProject(TSProject newTSProject)
Sets project that this TS belongs to.- Parameters:
newTSProject- the new project
-
setTSType
public void setTSType(TSTypes newTSType)
Sets the type of this time series. If the argument isnull, the type is determined internally to be either deterministic or endogenous.- Parameters:
newTSType- the new type of theTS- See Also:
type()
-
toString
public java.lang.String toString()
String representation of a timeseries. Do not use for comparisons, implementation might change without notice.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representing this series
-
-
DMelt 3.0 © DataMelt by jWork.ORG