JIDE 3.5.15

com.jidesoft.chart.model
Class CopiedChartModel

java.lang.Object
  extended by com.jidesoft.chart.model.CopiedChartModel
All Implemented Interfaces:
ChartModel, Named, Iterable<Chartable>

public final class CopiedChartModel
extends Object
implements ChartModel

A ChartModel class that creates a copy of the delegate chart model and does not allow it to be altered. Useful for multi-threading.

This class also attempts to make sure that it gets a 'clean' copy of the original model, i.e., that the model is not altered during the copying add. It does this in an optimistic fashion by going ahead with the copying and then checking whether the model changed during the copying add.

Note that because of the copying that occurs during initialisation, this class is not the exact analogue of the Unmodifiable wrappers for the Collection classes. This class has the disadvantage that it does some copying during initialisation, but has the advantage that we can make stronger guarantees about the contents of the container afterwards (and without having to be worrying about leaking references to the mutable data structure underneath). An unmodifiable ChartModel may also be added in a future release.


Constructor Summary
CopiedChartModel(ChartModel delegate)
          Construct a new ChartModel as a copy of the supplied model.
 
Method Summary
 void addChartModelListener(ChartModelListener listener)
          This method accepts a listener but in fact does nothing with it.
 boolean equals(Object other)
          Equality is based on the name of the chart model, so that this copy is considered equal to the model from which it originated.
 String getName()
          Returns the name of the chart model.
 Chartable getPoint(int n)
          Returns the nth point of the model.
 int getPointCount()
          Returns the number of points in the model.
 boolean isCyclical()
          Returns whether the model is cyclical.
 boolean isErrorFree()
          Enables the caller to enquire whether the copying add was error-free.
 Iterator<Chartable> iterator()
          Returns an iterator for the model, so the model can be used directly in an advanced for ...
 void removeChartModelListener(ChartModelListener listener)
          This method is also a no-op method (see addChartModelListener(ChartModelListener))
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CopiedChartModel

public CopiedChartModel(ChartModel delegate)
Construct a new ChartModel as a copy of the supplied model. The copied model, once created, cannot have any points added or removed, so is useful in a multi-threaded context. The points themselves are not copies but references to the original Chartables.

Parameters:
delegate - the ChartModel to copy.
Method Detail

isErrorFree

public boolean isErrorFree()
Enables the caller to enquire whether the copying add was error-free. It is deemed to be error-free if no change events were received from the delegate during the construction of the instance.

Returns:
whether the copy was created successfully (without changes occurring to the delegate)

addChartModelListener

public void addChartModelListener(ChartModelListener listener)
This method accepts a listener but in fact does nothing with it. It is a no-op method because the model is immutable and therefore will never fire a change event.

Specified by:
addChartModelListener in interface ChartModel
Parameters:
listener - the listener that will receive events

removeChartModelListener

public void removeChartModelListener(ChartModelListener listener)
This method is also a no-op method (see addChartModelListener(ChartModelListener))

Specified by:
removeChartModelListener in interface ChartModel
Parameters:
listener - the listener that will no longer receive events

getName

public String getName()
Returns the name of the chart model.

Specified by:
getName in interface ChartModel
Specified by:
getName in interface Named
Returns:
the name of the chart model

getPoint

public Chartable getPoint(int n)
Returns the nth point of the model.

Specified by:
getPoint in interface ChartModel
Parameters:
n - the index
Returns:
the nth point of the model.

getPointCount

public int getPointCount()
Returns the number of points in the model.

Specified by:
getPointCount in interface ChartModel
Returns:
the number of points in the model.

isCyclical

public boolean isCyclical()
Returns whether the model is cyclical. When the model is drawn with a line this has the effect that a line is drawn from the last point back to the first.

Specified by:
isCyclical in interface ChartModel
Returns:
whether the model is cyclical

iterator

public Iterator<Chartable> iterator()
Returns an iterator for the model, so the model can be used directly in an advanced for ... loop.

Specified by:
iterator in interface Iterable<Chartable>

equals

public boolean equals(Object other)
Equality is based on the name of the chart model, so that this copy is considered equal to the model from which it originated.

Overrides:
equals in class Object

JIDE 3.5.15