Package jcckit.data
Class DataContainer
- java.lang.Object
-
- jcckit.data.DataContainer
-
public abstract class DataContainer extends Object
Abstract superclass of all data containers. A data container holds an ordered list ofDataElements
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 allDataListeners
observing thisDataContainer
. If this data container also implementsDataEvent
(asDataCurve
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 theDataPlot
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.- Author:
- Franz-Josef Elmer
-
-
Constructor Summary
Constructors Constructor Description DataContainer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDataListener(DataListener listener)
Adds aDataListener
.void
addElement(DataElement element)
Adds aDataElement
.DataElement
getElement(int index)
Returns the element for the specified index.int
getIndexOf(DataElement element)
Returns the index of the specified element.int
getNumberOfElements()
Returns the number of elements of this container.void
insertElementAt(int index, DataElement element)
Inserts aDataElement
at the specified index.protected abstract boolean
isValid(DataElement element)
Returns true if the specifiedDataElement
has the correct type.void
removeDataListener(DataListener listener)
Removes aDataListener
.void
removeElementAt(int index)
Removes aDataElement
at the specified index.void
replaceElementAt(int index, DataElement element)
Replaces theDataElement
at the specified index.
-
-
-
Method Detail
-
addDataListener
public void addDataListener(DataListener listener)
Adds aDataListener
. Does nothing if already added.
-
removeDataListener
public void removeDataListener(DataListener listener)
Removes aDataListener
. Does nothing if already removed.
-
getNumberOfElements
public int getNumberOfElements()
Returns the number of elements of this container.
-
getElement
public DataElement getElement(int index)
Returns the element for the specified index.
-
getIndexOf
public int getIndexOf(DataElement element)
Returns the index of the specified element.- Parameters:
element
- Element to be looked for.- Returns:
- -1 if not found.
-
addElement
public void addElement(DataElement element)
Adds aDataElement
. After the element has been successfully added allDataListeners
will 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
public void insertElementAt(int index, DataElement element)
Inserts aDataElement
at the specified index. After the element has been successfully inserted allDataListeners
will 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 aDataElement
at the specified index. After the element has been successfully removed allDataListeners
will be informed.- Parameters:
index
- Index of the element which will be removed. All elements with an index > index will be shifted.
-
replaceElementAt
public void replaceElementAt(int index, DataElement element)
Replaces theDataElement
at the specified index. After the element has been successfully replaced allDataListeners
will 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
protected abstract boolean isValid(DataElement element)
Returns true if the specifiedDataElement
has the correct type. Concrete subclasses have to implement this method.- Parameters:
element
- DataElement to be checked.
-
-