Skip to content

Commit

Permalink
Renamed values -> entries for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 22, 2020
1 parent e02e9be commit 14456f4
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public BarDataSet(List<BarEntry> yVals, String label) {
@Override
public DataSet<BarEntry> copy() {
List<BarEntry> entries = new ArrayList<BarEntry>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
entries.add(mEntries.get(i).copy());
}
BarDataSet copied = new BarDataSet(entries, getLabel());
copy(copied);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected void calcMinMax(BubbleEntry e) {
@Override
public DataSet<BubbleEntry> copy() {
List<BubbleEntry> entries = new ArrayList<BubbleEntry>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
entries.add(mEntries.get(i).copy());
}
BubbleDataSet copied = new BubbleDataSet(entries, getLabel());
copy(copied);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public CandleDataSet(List<CandleEntry> yVals, String label) {
@Override
public DataSet<CandleEntry> copy() {
List<CandleEntry> entries = new ArrayList<CandleEntry>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
entries.add(mEntries.get(i).copy());
}
CandleDataSet copied = new CandleDataSet(entries, getLabel());
copy(copied);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
/**
* the entries that this DataSet represents / holds together
*/
protected List<T> mValues = null;
protected List<T> mEntries;

/**
* maximum y-value in the value array
Expand Down Expand Up @@ -45,15 +45,15 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
* label that describes the DataSet can be specified. The label can also be
* used to retrieve the DataSet from a ChartData object.
*
* @param values
* @param entries
* @param label
*/
public DataSet(List<T> values, String label) {
public DataSet(List<T> entries, String label) {
super(label);
this.mValues = values;
this.mEntries = entries;

if (mValues == null)
mValues = new ArrayList<T>();
if (mEntries == null)
mEntries = new ArrayList<T>();

calcMinMax();
}
Expand All @@ -66,10 +66,10 @@ public void calcMinMax() {
mXMax = -Float.MAX_VALUE;
mXMin = Float.MAX_VALUE;

if (mValues == null || mValues.isEmpty())
if (mEntries == null || mEntries.isEmpty())
return;

for (T e : mValues) {
for (T e : mEntries) {
calcMinMax(e);
}
}
Expand All @@ -79,7 +79,7 @@ public void calcMinMaxY(float fromX, float toX) {
mYMax = -Float.MAX_VALUE;
mYMin = Float.MAX_VALUE;

if (mValues == null || mValues.isEmpty())
if (mEntries == null || mEntries.isEmpty())
return;

int indexFrom = getEntryIndex(fromX, Float.NaN, Rounding.DOWN);
Expand All @@ -90,7 +90,7 @@ public void calcMinMaxY(float fromX, float toX) {
for (int i = indexFrom; i <= indexTo; i++) {

// only recalculate y
calcMinMaxY(mValues.get(i));
calcMinMaxY(mEntries.get(i));
}
}

Expand Down Expand Up @@ -129,25 +129,47 @@ protected void calcMinMaxY(T e) {

@Override
public int getEntryCount() {
return mValues.size();
return mEntries.size();
}

/**
* Returns the array of entries that this DataSet represents.
* This method is deprecated.
* Use getEntries() instead.
*
* @return
*/
@Deprecated
public List<T> getValues() {
return mValues;
return mEntries;
}

/**
* Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged()
* Returns the array of entries that this DataSet represents.
*
* @return
*/
public List<T> getEntries() {
return mEntries;
}

/**
* This method is deprecated.
* Use setEntries(...) instead.
*
* @param values
*/
@Deprecated
public void setValues(List<T> values) {
mValues = values;
setEntries(values);
}

/**
* Sets the array of entries that this DataSet represents, and calls notifyDataSetChanged()
*
* @return
*/
public void setEntries(List<T> entries) {
mEntries = entries;
notifyDataSetChanged();
}

Expand All @@ -170,8 +192,8 @@ protected void copy(DataSet dataSet) {
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(toSimpleString());
for (int i = 0; i < mValues.size(); i++) {
buffer.append(mValues.get(i).toString() + " ");
for (int i = 0; i < mEntries.size(); i++) {
buffer.append(mEntries.get(i).toString() + " ");
}
return buffer.toString();
}
Expand All @@ -184,7 +206,7 @@ public String toString() {
*/
public String toSimpleString() {
StringBuffer buffer = new StringBuffer();
buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mValues.size() +
buffer.append("DataSet, label: " + (getLabel() == null ? "" : getLabel()) + ", entries: " + mEntries.size() +
"\n");
return buffer.toString();
}
Expand Down Expand Up @@ -215,23 +237,23 @@ public void addEntryOrdered(T e) {
if (e == null)
return;

if (mValues == null) {
mValues = new ArrayList<T>();
if (mEntries == null) {
mEntries = new ArrayList<T>();
}

calcMinMax(e);

if (mValues.size() > 0 && mValues.get(mValues.size() - 1).getX() > e.getX()) {
if (mEntries.size() > 0 && mEntries.get(mEntries.size() - 1).getX() > e.getX()) {
int closestIndex = getEntryIndex(e.getX(), e.getY(), Rounding.UP);
mValues.add(closestIndex, e);
mEntries.add(closestIndex, e);
} else {
mValues.add(e);
mEntries.add(e);
}
}

@Override
public void clear() {
mValues.clear();
mEntries.clear();
notifyDataSetChanged();
}

Expand All @@ -241,9 +263,9 @@ public boolean addEntry(T e) {
if (e == null)
return false;

List<T> values = getValues();
List<T> values = getEntries();
if (values == null) {
values = new ArrayList<T>();
values = new ArrayList<>();
}

calcMinMax(e);
Expand All @@ -258,11 +280,11 @@ public boolean removeEntry(T e) {
if (e == null)
return false;

if (mValues == null)
if (mEntries == null)
return false;

// remove the entry
boolean removed = mValues.remove(e);
boolean removed = mEntries.remove(e);

if (removed) {
calcMinMax();
Expand All @@ -273,15 +295,15 @@ public boolean removeEntry(T e) {

@Override
public int getEntryIndex(Entry e) {
return mValues.indexOf(e);
return mEntries.indexOf(e);
}

@Override
public T getEntryForXValue(float xValue, float closestToY, Rounding rounding) {

int index = getEntryIndex(xValue, closestToY, rounding);
if (index > -1)
return mValues.get(index);
return mEntries.get(index);
return null;
}

Expand All @@ -292,24 +314,24 @@ public T getEntryForXValue(float xValue, float closestToY) {

@Override
public T getEntryForIndex(int index) {
return mValues.get(index);
return mEntries.get(index);
}

@Override
public int getEntryIndex(float xValue, float closestToY, Rounding rounding) {

if (mValues == null || mValues.isEmpty())
if (mEntries == null || mEntries.isEmpty())
return -1;

int low = 0;
int high = mValues.size() - 1;
int high = mEntries.size() - 1;
int closest = high;

while (low < high) {
int m = (low + high) / 2;

final float d1 = mValues.get(m).getX() - xValue,
d2 = mValues.get(m + 1).getX() - xValue,
final float d1 = mEntries.get(m).getX() - xValue,
d2 = mEntries.get(m + 1).getX() - xValue,
ad1 = Math.abs(d1), ad2 = Math.abs(d2);

if (ad2 < ad1) {
Expand All @@ -336,10 +358,10 @@ public int getEntryIndex(float xValue, float closestToY, Rounding rounding) {
}

if (closest != -1) {
float closestXValue = mValues.get(closest).getX();
float closestXValue = mEntries.get(closest).getX();
if (rounding == Rounding.UP) {
// If rounding up, and found x-value is lower than specified x, and we can go upper...
if (closestXValue < xValue && closest < mValues.size() - 1) {
if (closestXValue < xValue && closest < mEntries.size() - 1) {
++closest;
}
} else if (rounding == Rounding.DOWN) {
Expand All @@ -351,18 +373,18 @@ public int getEntryIndex(float xValue, float closestToY, Rounding rounding) {

// Search by closest to y-value
if (!Float.isNaN(closestToY)) {
while (closest > 0 && mValues.get(closest - 1).getX() == closestXValue)
while (closest > 0 && mEntries.get(closest - 1).getX() == closestXValue)
closest -= 1;

float closestYValue = mValues.get(closest).getY();
float closestYValue = mEntries.get(closest).getY();
int closestYIndex = closest;

while (true) {
closest += 1;
if (closest >= mValues.size())
if (closest >= mEntries.size())
break;

final Entry value = mValues.get(closest);
final Entry value = mEntries.get(closest);

if (value.getX() != closestXValue)
break;
Expand All @@ -386,22 +408,22 @@ public List<T> getEntriesForXValue(float xValue) {
List<T> entries = new ArrayList<T>();

int low = 0;
int high = mValues.size() - 1;
int high = mEntries.size() - 1;

while (low <= high) {
int m = (high + low) / 2;
T entry = mValues.get(m);
T entry = mEntries.get(m);

// if we have a match
if (xValue == entry.getX()) {
while (m > 0 && mValues.get(m - 1).getX() == xValue)
while (m > 0 && mEntries.get(m - 1).getX() == xValue)
m--;

high = mValues.size();
high = mEntries.size();

// loop over all "equal" entries
for (; m < high; m++) {
entry = mValues.get(m);
entry = mEntries.get(m);
if (entry.getX() == xValue) {
entries.add(entry);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public LineDataSet(List<Entry> yVals, String label) {
@Override
public DataSet<Entry> copy() {
List<Entry> entries = new ArrayList<Entry>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
entries.add(mEntries.get(i).copy());
}
LineDataSet copied = new LineDataSet(entries, getLabel());
copy(copied);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public PieDataSet(List<PieEntry> yVals, String label) {
@Override
public DataSet<PieEntry> copy() {
List<PieEntry> entries = new ArrayList<>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
entries.add(mEntries.get(i).copy());
}
PieDataSet copied = new PieDataSet(entries, getLabel());
copy(copied);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public void setHighlightCircleStrokeWidth(float strokeWidth) {
@Override
public DataSet<RadarEntry> copy() {
List<RadarEntry> entries = new ArrayList<RadarEntry>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
entries.add(mEntries.get(i).copy());
}
RadarDataSet copied = new RadarDataSet(entries, getLabel());
copy(copied);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public ScatterDataSet(List<Entry> yVals, String label) {
@Override
public DataSet<Entry> copy() {
List<Entry> entries = new ArrayList<Entry>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
for (int i = 0; i < mEntries.size(); i++) {
entries.add(mEntries.get(i).copy());
}
ScatterDataSet copied = new ScatterDataSet(entries, getLabel());
copy(copied);
Expand Down

0 comments on commit 14456f4

Please sign in to comment.