Package jcckit.data
Class DataContainer
java.lang.Object
jcckit.data.DataContainer
Abstract superclass of all data containers. A data container holds an
ordered list of
DataElements of the same type.
Data elements can be added, inserted, removed, or replaced.
Such an action leads to a DataEvent which will be delivered to
all DataListeners observing this
DataContainer. If this data container also implements
DataEvent (as DataCurve does) also the listeners
registrated at the data container containg this container will be notified.
As a consequence a DataListener must only be registered at the
DataPlot instance and it will automatically also received events
caused by manipulating one of its DataCurves.
Concrete subclasses have to implement isValid(jcckit.data.DataElement) which
checks whether the added or inserted DataElement is of the right
type. This is an application of the Template Method Design Pattern.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataListener(DataListener listener) Adds aDataListener.voidaddElement(DataElement element) Adds aDataElement.getElement(int index) Returns the element for the specified index.intgetIndexOf(DataElement element) Returns the index of the specified element.intReturns the number of elements of this container.voidinsertElementAt(int index, DataElement element) Inserts aDataElementat the specified index.protected abstract booleanisValid(DataElement element) Returns true if the specifiedDataElementhas the correct type.voidremoveDataListener(DataListener listener) Removes aDataListener.voidremoveElementAt(int index) Removes aDataElementat the specified index.voidreplaceElementAt(int index, DataElement element) Replaces theDataElementat the specified index.
-
Constructor Details
-
DataContainer
public DataContainer()
-
-
Method Details
-
addDataListener
Adds aDataListener. Does nothing if already added. -
removeDataListener
Removes aDataListener. Does nothing if already removed. -
getNumberOfElements
public int getNumberOfElements()Returns the number of elements of this container. -
getElement
Returns the element for the specified index. -
getIndexOf
Returns the index of the specified element.- Parameters:
element- Element to be looked for.- Returns:
- -1 if not found.
-
addElement
Adds aDataElement. After the element has been successfully added allDataListenerswill be informed.- Parameters:
element- DataElement to be added.- Throws:
IllegalArgumentException- if element is not of the correct type which will be checked by the methodisValid(jcckit.data.DataElement).
-
insertElementAt
Inserts aDataElementat the specified index. After the element has been successfully inserted allDataListenerswill be informed.- Parameters:
index- Index at which element will be inserted. All elements with an index >= index will be shifted.element- DataElement to be added.- Throws:
IllegalArgumentException- if element is not of the correct type which will be checked by the methodisValid(jcckit.data.DataElement).
-
removeElementAt
public void removeElementAt(int index) Removes aDataElementat the specified index. After the element has been successfully removed allDataListenerswill be informed.- Parameters:
index- Index of the element which will be removed. All elements with an index > index will be shifted.
-
replaceElementAt
Replaces theDataElementat the specified index. After the element has been successfully replaced allDataListenerswill be informed.- Parameters:
index- Index of the element which will be replaced by element.element- The new DataElement.- Throws:
IllegalArgumentException- if element is not of the correct type which will be checked by the methodisValid(jcckit.data.DataElement).
-
isValid
Returns true if the specifiedDataElementhas the correct type. Concrete subclasses have to implement this method.- Parameters:
element- DataElement to be checked.
-