com.jstatcom.ts
Class TSHolder
- java.lang.Object
-
- com.jstatcom.ts.TSHolder
-
- All Implemented Interfaces:
- ProjectDataHandler
public class TSHolder extends java.lang.Object implements ProjectDataHandler
Holds all availableTSat runtime. The identifying keys are the names of the time series. The names are converted to lowercase, which makes the lookup case insensitive. It also provides methods for adding, removing, and reading of time series. This class is designed as a Singleton (Gamma et al., 1995) and can be accessed by the staticgetInstancemethod.Classes can register themselves as
PropertyChangeListenersto theTSHolderif they should be notified whenTS_ADDEDorTS_REMOVEDevents happen.This class is designed to be thread-save for adding, removing, and reading of time series.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringALL_TS_REMOVEDstatic java.lang.StringTS_ADDEDPropertyChange values.static java.lang.StringTS_REMOVED
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)intaddTS(TS newTimeSeries)Adds a newTSto thisTSHolder.booleancontains(java.lang.String name)Returns whether theTSHoldercontains aTSwith the given name.TS[]getAllTS()Gets all time series.javax.swing.ListModelgetAsListModel()GetsTSHolderrepresented as aListModelwith the names in alphabetical order.static TSHoldergetInstance()Returns Singleton instance of aTSHolder.ProjectDatagetProjectData()Gets the project data from this shared data repository.ProjectDataTypesgetProjectDataType()Returns time series data type.TSgetTS(java.lang.String name)Retrieves a time series for a given name.java.util.Iterator<java.lang.String>getTSNames()Returns names of all available time series.voidremoveAllTS()Removes all time series from the map and fires anALL_TS_REMOVED PropertyChangeEventif there were any series removed.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)voidremoveTS(java.lang.String name)Removes a time series from the map and fires aTS_REMOVED PropertyChangeEvent.voidsetProjectData(ProjectData pData)Sets the project data to this shared data repository for time series.voidsetTS(TS[] newTimeSeries)Clears all currently stored time series and adds the series contained innewTimeSeries.java.lang.StringtoString()String representation of thisTSHolder.
-
-
-
Field Detail
-
TS_ADDED
public static final java.lang.String TS_ADDED
PropertyChange values.- See Also:
- Constant Field Values
-
TS_REMOVED
public static final java.lang.String TS_REMOVED
- See Also:
- Constant Field Values
-
ALL_TS_REMOVED
public static final java.lang.String ALL_TS_REMOVED
- See Also:
- Constant Field Values
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
-
setTS
public void setTS(TS[] newTimeSeries)
Clears all currently stored time series and adds the series contained innewTimeSeries.- Parameters:
newTimeSeries- array of time series to add
-
addTS
public int addTS(TS newTimeSeries)
Adds a newTSto thisTSHolder. If a series has less than 2 observations, an error message is displayed. If a series with the same name already exists, a question is displayed, whether the existing series should be overwritten. This method returnsJOptionPane.YES_OPTIONifnewTimeSerieswasnull.If the series was added, a
TS_ADDED PropertyChangeEventis fired.- Parameters:
newTimeSeries- the new TS to add- Returns:
- One of
JOptionPane.YES_OPTION,JOptionPane.NO_OPTIONorJOptionPane.CANCEL_OPTION, which the calling method can process accordingly. IfJOptionPane.YES_OPTIONis returned, the time series was added successfully.
-
contains
public boolean contains(java.lang.String name)
Returns whether theTSHoldercontains aTSwith the given name. The lookup is case insensitive.- Parameters:
name- String with the name to be looked up- Returns:
- true if series is contained, false otherwise
-
getAsListModel
public javax.swing.ListModel getAsListModel()
GetsTSHolderrepresented as aListModelwith the names in alphabetical order.- Returns:
- the ListModel that is in sync with this object
-
getInstance
public static TSHolder getInstance()
Returns Singleton instance of aTSHolder.- Returns:
- TSHolder instance to be shared
-
getTS
public TS getTS(java.lang.String name)
Retrieves a time series for a given name.- Parameters:
name- of the time series to get- Returns:
TSwith the given name,nullif it does not exist
-
getAllTS
public TS[] getAllTS()
Gets all time series.- Returns:
- array of all series
-
getTSNames
public java.util.Iterator<java.lang.String> getTSNames()
Returns names of all available time series.- Returns:
- iterator with names of all hashed
TS
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
-
removeTS
public void removeTS(java.lang.String name)
Removes a time series from the map and fires aTS_REMOVED PropertyChangeEvent. Nothing happens, if no series with the given name was stored.- Parameters:
name- of the time series to get
-
removeAllTS
public void removeAllTS()
Removes all time series from the map and fires anALL_TS_REMOVED PropertyChangeEventif there were any series removed.
-
toString
public java.lang.String toString()
String representation of thisTSHolder.- Overrides:
toStringin classjava.lang.Object- Returns:
- string containing name and names of all included
TS
-
setProjectData
public void setProjectData(ProjectData pData)
Sets the project data to this shared data repository for time series.- Specified by:
setProjectDatain interfaceProjectDataHandler- Parameters:
pData- project data to set
-
getProjectData
public ProjectData getProjectData()
Gets the project data from this shared data repository. Typically this method is used for serialization.- Specified by:
getProjectDatain interfaceProjectDataHandler- Returns:
- project data assembled from this data repository
-
getProjectDataType
public ProjectDataTypes getProjectDataType()
Returns time series data type.- Specified by:
getProjectDataTypein interfaceProjectDataHandler- Returns:
ProjectDataTypes.TS_DATA
-
-
DMelt 3.0 © DataMelt by jWork.ORG