@Override public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(toSimpleString()); for (int i = 0; i < mValues.size(); i++) { buffer.append(mValues.get(i).toString() + " "); } return buffer.toString(); }
@Override public boolean addEntry(T e) { if (e == null) return false; List<T> values = getValues(); if (values == null) { values = new ArrayList<T>(); } calcMinMax(e); // add the entry return values.add(e); }
/** * Updates the min and max x and y value of this DataSet based on the given Entry. * * @param e */ protected void calcMinMax(T e) { if (e == null) return; calcMinMaxX(e); calcMinMaxY(e); }
@Override public void calcMinMaxY(float fromX, float toX) { if (mValues == null || mValues.isEmpty()) return; mYMax = -Float.MAX_VALUE; mYMin = Float.MAX_VALUE; int indexFrom = getEntryIndex(fromX, Float.NaN, Rounding.DOWN); int indexTo = getEntryIndex(toX, Float.NaN, Rounding.UP); for (int i = indexFrom; i <= indexTo; i++) { // only recalculate y calcMinMaxY(mValues.get(i)); } }
@Override public void addEntryOrdered(T e) { if (e == null) return; if (mValues == null) { mValues = new ArrayList<T>(); } calcMinMax(e); if (mValues.size() > 0 && mValues.get(mValues.size() - 1).getX() > e.getX()) { int closestIndex = getEntryIndex(e.getX(), e.getY(), Rounding.UP); mValues.add(closestIndex, e); } else { mValues.add(e); } }
@Override public void calcMinMax() { if (mValues == null || mValues.isEmpty()) return; mYMax = -Float.MAX_VALUE; mYMin = Float.MAX_VALUE; mXMax = -Float.MAX_VALUE; mXMin = Float.MAX_VALUE; for (T e : mValues) { calcMinMax(e); } }
/** * Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged() * * @return */ public void setValues(List<T> values) { mValues = values; notifyDataSetChanged(); }
/** * Returns a simple string representation of the DataSet with the type and * the number of Entries. * * @return */ public String toSimpleString() { StringBuffer buffer = new StringBuffer(); buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mValues.size() + "\n"); return buffer.toString(); }
@Override public T getEntryForXValue(float xValue, float closestToY, Rounding rounding) { int index = getEntryIndex(xValue, closestToY, rounding); if (index > -1) return mValues.get(index); return null; }
@Override public T getEntryForXValue(float xValue, float closestToY) { return getEntryForXValue(xValue, closestToY, Rounding.CLOSEST); }
@Override public void calcMinMaxY(float fromX, float toX) { if (mValues == null || mValues.isEmpty()) return; mYMax = -Float.MAX_VALUE; mYMin = Float.MAX_VALUE; int indexFrom = getEntryIndex(fromX, Float.NaN, Rounding.DOWN); int indexTo = getEntryIndex(toX, Float.NaN, Rounding.UP); for (int i = indexFrom; i <= indexTo; i++) { // only recalculate y calcMinMaxY(mValues.get(i)); } }
@Override public void addEntryOrdered(T e) { if (e == null) return; if (mValues == null) { mValues = new ArrayList<T>(); } calcMinMax(e); if (mValues.size() > 0 && mValues.get(mValues.size() - 1).getX() > e.getX()) { int closestIndex = getEntryIndex(e.getX(), e.getY(), Rounding.UP); mValues.add(closestIndex, e); } else { mValues.add(e); } }
@Override public boolean removeEntry(T e) { if (e == null) return false; if (mValues == null) return false; // remove the entry boolean removed = mValues.remove(e); if (removed) { calcMinMax(); } return removed; }
@Override public void clear() { mValues.clear(); notifyDataSetChanged(); }
/** * Returns a simple string representation of the DataSet with the type and * the number of Entries. * * @return */ public String toSimpleString() { StringBuffer buffer = new StringBuffer(); buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mValues.size() + "\n"); return buffer.toString(); }
@Override public T getEntryForXValue(float xValue, float closestToY, Rounding rounding) { int index = getEntryIndex(xValue, closestToY, rounding); if (index > -1) { return mValues.get(index); } return null; }
@Override public T getEntryForXValue(float xValue, float closestToY) { return getEntryForXValue(xValue, closestToY, Rounding.CLOSEST); }
/** * Updates the min and max x and y value of this DataSet based on the given Entry. * * @param e */ protected void calcMinMax(T e) { if (e == null) return; calcMinMaxX(e); calcMinMaxY(e); }
@Override public boolean addEntry(T e) { if (e == null) return false; List<T> values = getValues(); if (values == null) { values = new ArrayList<T>(); } calcMinMax(e); // add the entry return values.add(e); }
@Override public void calcMinMaxY(float fromX, float toX) { if (mValues == null || mValues.isEmpty()) return; mYMax = -Float.MAX_VALUE; mYMin = Float.MAX_VALUE; int indexFrom = getEntryIndex(fromX, Float.NaN, Rounding.DOWN); int indexTo = getEntryIndex(toX, Float.NaN, Rounding.UP); for (int i = indexFrom; i <= indexTo; i++) { // only recalculate y calcMinMaxY(mValues.get(i)); } }