| Method from org.jfree.data.xy.XYSeries Detail: |
public void add(XYDataItem item) {
// argument checking delegated...
add(item, true);
}
Adds a data item to the series and sends a SeriesChangeEvent to
all registered listeners. |
public void add(double x,
double y) {
add(new Double(x), new Double(y), true);
}
Adds a data item to the series and sends a SeriesChangeEvent to
all registered listeners. |
public void add(double x,
Number y) {
add(new Double(x), y);
}
Adds a data item to the series and sends a SeriesChangeEvent to
all registered listeners. The unusual pairing of parameter types is to
make it easier to add null y-values. |
public void add(Number x,
Number y) {
// argument checking delegated...
add(x, y, true);
}
|
public void add(XYDataItem item,
boolean notify) {
if (item == null) {
throw new IllegalArgumentException("Null 'item' argument.");
}
if (this.autoSort) {
int index = Collections.binarySearch(this.data, item);
if (index < 0) {
this.data.add(-index - 1, item);
}
else {
if (this.allowDuplicateXValues) {
// need to make sure we are adding *after* any duplicates
int size = this.data.size();
while (index < size
&& item.compareTo(this.data.get(index)) == 0) {
index++;
}
if (index < this.data.size()) {
this.data.add(index, item);
}
else {
this.data.add(item);
}
}
else {
throw new SeriesException("X-value already exists.");
}
}
}
else {
if (!this.allowDuplicateXValues) {
// can't allow duplicate values, so we need to check whether
// there is an item with the given x-value already
int index = indexOf(item.getX());
if (index >= 0) {
throw new SeriesException("X-value already exists.");
}
}
this.data.add(item);
}
if (getItemCount() > this.maximumItemCount) {
this.data.remove(0);
}
if (notify) {
fireSeriesChanged();
}
}
Adds a data item to the series and, if requested, sends a
SeriesChangeEvent to all registered listeners. |
public void add(double x,
double y,
boolean notify) {
add(new Double(x), new Double(y), notify);
}
Adds a data item to the series and, if requested, sends a
SeriesChangeEvent to all registered listeners. |
public void add(double x,
Number y,
boolean notify) {
add(new Double(x), y, notify);
}
Adds a data item to the series and, if requested, sends a
SeriesChangeEvent to all registered listeners. The unusual
pairing of parameter types is to make it easier to add null y-values. |
public void add(Number x,
Number y,
boolean notify) {
// delegate argument checking to XYDataItem...
XYDataItem item = new XYDataItem(x, y);
add(item, notify);
}
|
public XYDataItem addOrUpdate(double x,
double y) {
return addOrUpdate(new Double(x), new Double(y));
}
Adds or updates an item in the series and sends a
SeriesChangeEvent to all registered listeners. |
public XYDataItem addOrUpdate(Number x,
Number y) {
if (x == null) {
throw new IllegalArgumentException("Null 'x' argument.");
}
XYDataItem overwritten = null;
int index = indexOf(x);
if (index >= 0 && !this.allowDuplicateXValues) {
XYDataItem existing = (XYDataItem) this.data.get(index);
try {
overwritten = (XYDataItem) existing.clone();
}
catch (CloneNotSupportedException e) {
throw new SeriesException("Couldn't clone XYDataItem!");
}
existing.setY(y);
}
else {
// if the series is sorted, the negative index is a result from
// Collections.binarySearch() and tells us where to insert the
// new item...otherwise it will be just -1 and we should just
// append the value to the list...
if (this.autoSort) {
this.data.add(-index - 1, new XYDataItem(x, y));
}
else {
this.data.add(new XYDataItem(x, y));
}
// check if this addition will exceed the maximum item count...
if (getItemCount() > this.maximumItemCount) {
this.data.remove(0);
}
}
fireSeriesChanged();
return overwritten;
}
|
public void clear() {
if (this.data.size() > 0) {
this.data.clear();
fireSeriesChanged();
}
}
Removes all data items from the series. |
public Object clone() throws CloneNotSupportedException {
XYSeries clone = (XYSeries) super.clone();
clone.data = (List) ObjectUtilities.deepClone(this.data);
return clone;
}
Returns a clone of the series. |
public XYSeries createCopy(int start,
int end) throws CloneNotSupportedException {
XYSeries copy = (XYSeries) super.clone();
copy.data = new java.util.ArrayList();
if (this.data.size() > 0) {
for (int index = start; index < = end; index++) {
XYDataItem item = (XYDataItem) this.data.get(index);
XYDataItem clone = (XYDataItem) item.clone();
try {
copy.add(clone);
}
catch (SeriesException e) {
System.err.println("Unable to add cloned data item.");
}
}
}
return copy;
}
Creates a new series by copying a subset of the data in this time series. |
public void delete(int start,
int end) {
for (int i = start; i < = end; i++) {
this.data.remove(start);
}
fireSeriesChanged();
}
Deletes a range of items from the series and sends a
SeriesChangeEvent to all registered listeners. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof XYSeries)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
XYSeries that = (XYSeries) obj;
if (this.maximumItemCount != that.maximumItemCount) {
return false;
}
if (this.autoSort != that.autoSort) {
return false;
}
if (this.allowDuplicateXValues != that.allowDuplicateXValues) {
return false;
}
if (!ObjectUtilities.equal(this.data, that.data)) {
return false;
}
return true;
}
Tests this series for equality with an arbitrary object. |
public boolean getAllowDuplicateXValues() {
return this.allowDuplicateXValues;
}
Returns a flag that controls whether duplicate x-values are allowed.
This flag can only be set in the constructor. |
public boolean getAutoSort() {
return this.autoSort;
}
Returns the flag that controls whether the items in the series are
automatically sorted. There is no setter for this flag, it must be
defined in the series constructor. |
public XYDataItem getDataItem(int index) {
return (XYDataItem) this.data.get(index);
}
Return the data item with the specified index. |
public int getItemCount() {
return this.data.size();
}
Returns the number of items in the series. |
public List getItems() {
return Collections.unmodifiableList(this.data);
}
Returns the list of data items for the series (the list contains
XYDataItem objects and is unmodifiable). |
public int getMaximumItemCount() {
return this.maximumItemCount;
}
Returns the maximum number of items that will be retained in the series.
The default value is Integer.MAX_VALUE. |
public Number getX(int index) {
return getDataItem(index).getX();
}
Returns the x-value at the specified index. |
public Number getY(int index) {
return getDataItem(index).getY();
}
Returns the y-value at the specified index. |
public int hashCode() {
int result = super.hashCode();
// it is too slow to look at every data item, so let's just look at
// the first, middle and last items...
int count = getItemCount();
if (count > 0) {
XYDataItem item = getDataItem(0);
result = 29 * result + item.hashCode();
}
if (count > 1) {
XYDataItem item = getDataItem(count - 1);
result = 29 * result + item.hashCode();
}
if (count > 2) {
XYDataItem item = getDataItem(count / 2);
result = 29 * result + item.hashCode();
}
result = 29 * result + this.maximumItemCount;
result = 29 * result + (this.autoSort ? 1 : 0);
result = 29 * result + (this.allowDuplicateXValues ? 1 : 0);
return result;
}
|
public int indexOf(Number x) {
if (this.autoSort) {
return Collections.binarySearch(this.data, new XYDataItem(x, null));
}
else {
for (int i = 0; i < this.data.size(); i++) {
XYDataItem item = (XYDataItem) this.data.get(i);
if (item.getX().equals(x)) {
return i;
}
}
return -1;
}
}
Returns the index of the item with the specified x-value, or a negative
index if the series does not contain an item with that x-value. Be
aware that for an unsorted series, the index is found by iterating
through all items in the series. |
public XYDataItem remove(int index) {
XYDataItem result = (XYDataItem) this.data.remove(index);
fireSeriesChanged();
return result;
}
Removes the item at the specified index and sends a
SeriesChangeEvent to all registered listeners. |
public XYDataItem remove(Number x) {
return remove(indexOf(x));
}
Removes the item with the specified x-value and sends a
SeriesChangeEvent to all registered listeners. |
public void setMaximumItemCount(int maximum) {
this.maximumItemCount = maximum;
boolean dataRemoved = false;
while (this.data.size() > maximum) {
this.data.remove(0);
dataRemoved = true;
}
if (dataRemoved) {
fireSeriesChanged();
}
}
Sets the maximum number of items that will be retained in the series.
If you add a new item to the series such that the number of items will
exceed the maximum item count, then the first element in the series is
automatically removed, ensuring that the maximum item count is not
exceeded.
Typically this value is set before the series is populated with data,
but if it is applied later, it may cause some items to be removed from
the series (in which case a SeriesChangeEvent will be sent to
all registered listeners. |
public double[][] toArray() {
int itemCount = getItemCount();
double[][] result = new double[2][itemCount];
for (int i = 0; i < itemCount; i++) {
result[0][i] = this.getX(i).doubleValue();
Number y = getY(i);
if (y != null) {
result[1][i] = y.doubleValue();
}
else {
result[1][i] = Double.NaN;
}
}
return result;
}
Returns a new array containing the x and y values from this series. |
public void update(int index,
Number y) {
XYDataItem item = getDataItem(index);
item.setY(y);
fireSeriesChanged();
} Deprecated! Renamed - #updateByIndex(int, Number) to avoid
confusion with the #update(Number, Number) method.
Updates the value of an item in the series and sends a
SeriesChangeEvent to all registered listeners. |
public void update(Number x,
Number y) {
int index = indexOf(x);
if (index < 0) {
throw new SeriesException("No observation for x = " + x);
}
else {
XYDataItem item = getDataItem(index);
item.setY(y);
fireSeriesChanged();
}
}
Updates an item in the series. |
public void updateByIndex(int index,
Number y) {
update(index, y);
}
Updates the value of an item in the series and sends a
SeriesChangeEvent to all registered listeners. |