From 0f3ff7f4587549439ef3c10562a0402fae8acc14 Mon Sep 17 00:00:00 2001 From: Oleg Kan Date: Sat, 25 Jul 2015 16:55:10 -0400 Subject: [PATCH] override isLegal() to check unique X values in Yvals arrayList --- .../mikephil/charting/data/LineData.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/MPChartLib/src/com/github/mikephil/charting/data/LineData.java b/MPChartLib/src/com/github/mikephil/charting/data/LineData.java index c65307247..1862cddc2 100644 --- a/MPChartLib/src/com/github/mikephil/charting/data/LineData.java +++ b/MPChartLib/src/com/github/mikephil/charting/data/LineData.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.TreeSet; /** * Data object that encapsulates all data associated with a LineChart. @@ -44,4 +46,28 @@ private static List toList(LineDataSet dataSet) { sets.add(dataSet); return sets; } + + + // overridden methods + + @Override + protected void isLegal() { + if (mDataSets == null) + return; + + for (int i = 0; i < mDataSets.size(); i++) { + + List yVals = mDataSets.get(i).getYVals(); + Set uniqueX = new TreeSet(); + + for (Entry e : yVals) { + uniqueX.add(e.getXIndex()); + } + + if (uniqueX.size() > mXVals.size()) { + throw new IllegalArgumentException( + "One or more of the DataSet Entry arrays are longer than the x-values array of this ChartData object."); + } + } + } }