public abstract class

DataAdapter

extends Object
implements Iterable<T>
java.lang.Object
   ↳ com.shinobicontrols.charts.DataAdapter<Tx, Ty>
Known Direct Subclasses

Class Overview

Abstract base class for an ordered collection of Data objects which it holds for, and provides to, a Series. Data points can be added and removed as necessary, and accessed and inserted by their integer index (position in the list). Duplicate data points are allowed. However, null data points cannot be added to a data adapter; trying to do so will result in a NullPointerException being thrown.

A DataAdapter is created independently from a series. It is passed to the series in order for the data to be displayed on the chart. This abstract base class handles the storage and modification of data points. It is up to concrete subclass implementations to define the way in which the data adapter's series is notified when it is updated. DataAdapter implements the Iterable interface and so can be used with the enhanced for loop to iterate through its data points.

A SimpleDataAdapter is provided which notifies its series that it has been updated every time its data points are modified. Alternatively, DataAdapter may be extended and a custom implementation made to suit specific requirements. In this case, it is important to call the super implementation of any overridden methods to ensure data points are managed correctly.

Summary

Nested Classes
interface DataAdapter.OnDataChangedListener Callback interface for listening to changes in the data held by a DataAdapter
Protected Constructors
DataAdapter()
Public Methods
boolean add(Data<Tx, Ty> dataPoint)
Appends the specified data point to the end of this data adapter.
void add(int location, Data<Tx, Ty> dataPoint)
Inserts the specified data point at the specified position in the data adapter.
boolean addAll(Collection<? extends Data<Tx, Ty>> dataPoints)
Appends all of the data points in the specified collection to the end of this data adapter.
boolean addAll(int location, Collection<? extends Data<Tx, Ty>> dataPoints)
Inserts all of the data points in the specified collection into the data adapter at the specified position.
void addOnDataChangedListener(DataAdapter.OnDataChangedListener onDataChangedListener)
Adds an DataAdapter.OnDataChangedListener to this DataAdapter to be notified of any changes to its data.
void clear()
Removes all of the data points from this data adapter, resulting in an empty data adapter.
boolean contains(Object object)
Returns true if this data adapter contains the specified object.
boolean containsAll(Collection<?> collection)
Whether this data adapter contains all objects in the specified collection.
Data<Tx, Ty> get(int location)
Returns the data point at the specified location in this data adapter.
List<Data<Tx, Ty>> getDataPointsForDisplay()
Returns a list of all the data points which are to be displayed on the chart.
int hashCode()
Returns the hash code for this data adapter.
int indexOf(Object object)
Searches for the specified object in this data adapter returning the index of the first occurrence.
boolean isEmpty()
Returns whether this data adapter contains no data points.
Iterator<Data<Tx, Ty>> iterator()
Returns an iterator on the data points in this data adapter.
int lastIndexOf(Object object)
Searches this data adapter for the specified object and returns the index of the last occurrence.
void notifyDataChanged()
Notifies any DataAdapter.OnDataChangedListeners added to this DataAdapter that its data has been modified in some way.
Data<Tx, Ty> remove(int location)
Removes the data point at the specified location from this data adapter.
boolean remove(Object object)
Removes the first occurrence of the specified object from this data adapter.
boolean removeAll(Collection<?> collection)
Removes all occurrences of each object in the specified collection from this data adapter
void removeOnDataChangedListener(DataAdapter.OnDataChangedListener onDataChangedListener)
Removes the given DataAdapter.OnDataChangedListener from this DataAdapter.
boolean retainAll(Collection<?> collection)
Removes all objects from this data adapter that are not contained in the specified collection.
Data<Tx, Ty> set(int location, Data<Tx, Ty> dataPoint)
Replaces the data point at the specified location in this data adapter with the specified data point.
int size()
Returns the number of data points in this data adapter.
Object[] toArray()
Returns an array containing all data points in this data adapter.
<T> T[] toArray(T[] array)
Returns an array containing all data points in the data adapter.
Protected Methods
final void fireUpdateHandler()
This method is deprecated. as of v1.8.0, use notifyDataChanged() instead
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Iterable

Protected Constructors

protected DataAdapter ()

Public Methods

public boolean add (Data<Tx, Ty> dataPoint)

Appends the specified data point to the end of this data adapter. Null data points are not permitted; trying to add one will result in a NullPointerException being thrown.

Parameters
dataPoint The data point to append to this data adapter
Returns
  • true if the data adapter changed as a result of the call

public void add (int location, Data<Tx, Ty> dataPoint)

Inserts the specified data point at the specified position in the data adapter. This will shift the data point currently at location and all subsequent data points to the right, adding one to their indices. Null data points are not permitted; trying to add one will result in a NullPointerException being thrown.

Parameters
location The index at which to insert
dataPoint The data point to insert into this data adapter

public boolean addAll (Collection<? extends Data<Tx, Ty>> dataPoints)

Appends all of the data points in the specified collection to the end of this data adapter. Adding a null collection of data points, or a collection containing one or more null data points is not permitted and will result in a NullPointerException being thrown.

Parameters
dataPoints Collection containing data points to be appended to the end of this data adapter
Returns
  • true if the data adapter changed as a result of the call

public boolean addAll (int location, Collection<? extends Data<Tx, Ty>> dataPoints)

Inserts all of the data points in the specified collection into the data adapter at the specified position. This will shift the data point currently at location and all subsequent data points to the right, adding one to their indices. Adding a null collection of data points, or a collection containing one or more null data points is not permitted and will result in a NullPointerException being thrown.

Parameters
location The index at which to insert
dataPoints Collection containing data points to be appended to the end of this data adapter
Returns
  • true if the data adapter changed as a result of the call

public void addOnDataChangedListener (DataAdapter.OnDataChangedListener onDataChangedListener)

Adds an DataAdapter.OnDataChangedListener to this DataAdapter to be notified of any changes to its data.

Parameters
onDataChangedListener the DataAdapter.OnDataChangedListener to add

public void clear ()

Removes all of the data points from this data adapter, resulting in an empty data adapter.

public boolean contains (Object object)

Returns true if this data adapter contains the specified object.

Parameters
object The object to search for
Returns
  • true if object is in this data adapter, false otherwise

public boolean containsAll (Collection<?> collection)

Whether this data adapter contains all objects in the specified collection.

Parameters
collection The collection of objects to search for
Returns
  • true if all objects in the specified collection are in this data adapter, false otherwise

public Data<Tx, Ty> get (int location)

Returns the data point at the specified location in this data adapter.

Parameters
location The index of the data point to return
Returns
  • The data point at the specified location

public List<Data<Tx, Ty>> getDataPointsForDisplay ()

Returns a list of all the data points which are to be displayed on the chart. This method is called by the chart framework in response to notifyDataChanged(). It is not normally called by client code, though there is no harm in doing so.

In the base DataAdapter implementation it simply provides a copy of the java.util.ArrayList that backs the class. However, in some subclassing scenarios (e.g. sampling, windowing or smoothing) you may wish to override this method to return a modified set of data points or optionally provide your own backing data store. As this list is a copy you may modify it without changing the original set of data points held in the DataAdapter.

Returns
  • a list of all the data points which are to be displayed on the chart

public int hashCode ()

Returns the hash code for this data adapter. It is calculated by taking each data points' hashcode and its position in the data adapter into account.

Returns
  • The hashcode for this data adapter

public int indexOf (Object object)

Searches for the specified object in this data adapter returning the index of the first occurrence.

Parameters
object The object to search for
Returns
  • The index of the first occurrence of object or -1 if it is not found
Throws
IndexOutOfBoundsException if location < 0 || location >= size()

public boolean isEmpty ()

Returns whether this data adapter contains no data points.

Returns
  • true if this data adapter has no data points, false otherwise

public Iterator<Data<Tx, Ty>> iterator ()

Returns an iterator on the data points in this data adapter. The data points are iterated in the same order as they occur in the data adapter.

Returns
  • An iterator on the data points in this data adapter

public int lastIndexOf (Object object)

Searches this data adapter for the specified object and returns the index of the last occurrence.

Parameters
object The object to search for
Returns
  • The index of the last occurrence of object or -1 if it is not found

public void notifyDataChanged ()

Notifies any DataAdapter.OnDataChangedListeners added to this DataAdapter that its data has been modified in some way.

When creating a custom DataAdapter implementation, call this method to notify any connected Series of this change (you may want to do this after a collection of points have been added rather than every time a point is added).

public Data<Tx, Ty> remove (int location)

Removes the data point at the specified location from this data adapter.

Parameters
location The index of the data point to remove
Returns
  • The removed data point

public boolean remove (Object object)

Removes the first occurrence of the specified object from this data adapter.

Parameters
object The object to remove
Returns
  • true if this data adapter was modified by this operation, false otherwise

public boolean removeAll (Collection<?> collection)

Removes all occurrences of each object in the specified collection from this data adapter

Parameters
collection The collection of objects to remove
Returns
  • true if this data adapter was modified, false otherwise

public void removeOnDataChangedListener (DataAdapter.OnDataChangedListener onDataChangedListener)

Removes the given DataAdapter.OnDataChangedListener from this DataAdapter.

Parameters
onDataChangedListener the DataAdapter.OnDataChangedListener to remove

public boolean retainAll (Collection<?> collection)

Removes all objects from this data adapter that are not contained in the specified collection.

Parameters
collection The collection of objects to retain
Returns
  • true if this data adapter was modified, false otherwise

public Data<Tx, Ty> set (int location, Data<Tx, Ty> dataPoint)

Replaces the data point at the specified location in this data adapter with the specified data point. This size of the data adapter remains the same. Null data points are not permitted; trying to add one will result in a NullPointerException being thrown.

Parameters
location The index of the data point to replace
dataPoint The new data point with which to replace the existing data point
Returns
  • The existing data point at the specified location

public int size ()

Returns the number of data points in this data adapter.

Returns
  • The number of data points in this data adapter

public Object[] toArray ()

Returns an array containing all data points in this data adapter.

Returns
  • An array of the data points in this data adapter

public T[] toArray (T[] array)

Returns an array containing all data points in the data adapter. If the specified array is large enough to hold the data points, the specified array is used. Otherwise, an array of the same type is created. If the specified array is used and is larger than this data adapter, the array element following the data adapter's data points is set to null.

Parameters
array The array to hold the data points, if it is large enough
Returns
  • An array of the data points from this data adapter

Protected Methods

protected final void fireUpdateHandler ()

This method is deprecated.
as of v1.8.0, use notifyDataChanged() instead

Fires the necessary event to signal this data adapter has been modified in some way. When creating a custom DataAdapter implementation, call this method to notify any connected series of this change (you may want to do this after a collection of points have been added rather than every time a point is added).