+ /** Inner class to remember a single index */
+ class PointIndex
+ {
+ public int index = -1;
+ public boolean hasValue = false;
+ public PointIndex()
+ {
+ index = -1;
+ hasValue = false;
+ }
+ /** Set a single value */
+ public void set(int inValue)
+ {
+ index = inValue;
+ hasValue = (inValue != -1);
+ }
+ /** Add an index to the minimum calculation */
+ public void setMin(PointIndex other)
+ {
+ if (!other.hasValue) {return;}
+ if (!hasValue) {
+ index = other.index;
+ hasValue = other.hasValue;
+ }
+ else {
+ index = Math.min(index, other.index);
+ }
+ }
+ /** Add an index to the maximum calculation */
+ public void setMax(PointIndex other)
+ {
+ if (!other.hasValue) {return;}
+ if (!hasValue) {
+ index = other.index;
+ hasValue = other.hasValue;
+ }
+ else {
+ index = Math.max(index, other.index);
+ }
+ }
+ /** @return true if two Indexes are equal */
+ public boolean equals(PointIndex other)
+ {
+ if (!hasValue || !other.hasValue) {
+ return hasValue == other.hasValue;
+ }
+ return index == other.index;
+ }
+ }
+
+ /** Inner class to remember previous chart parameters */
+ class ChartParameters
+ {
+ public PointIndex selectedPoint = new PointIndex();
+ public PointIndex rangeStart = new PointIndex(), rangeEnd = new PointIndex();
+ public void clear()
+ {
+ selectedPoint.hasValue = false;
+ rangeStart.hasValue = false;
+ rangeEnd.hasValue = false;
+ }
+ /** Get the minimum index which has changed between two sets of parameters */
+ public int getMinChangedIndex(ChartParameters other)
+ {
+ PointIndex minIndex = new PointIndex();
+ if (!selectedPoint.equals(other.selectedPoint)) {
+ minIndex.setMin(selectedPoint);
+ minIndex.setMin(other.selectedPoint);
+ }
+ if (!rangeStart.equals(other.rangeStart)) {
+ minIndex.setMin(rangeStart);
+ minIndex.setMin(other.rangeStart);
+ }
+ if (!rangeEnd.equals(other.rangeEnd)) {
+ minIndex.setMin(rangeEnd);
+ minIndex.setMin(other.rangeEnd);
+ }
+ return minIndex.index;
+ }
+ /** Get the maximum index which has changed between two sets of parameters */
+ public int getMaxChangedIndex(ChartParameters other)
+ {
+ PointIndex maxIndex = new PointIndex();
+ if (!selectedPoint.equals(other.selectedPoint)) {
+ maxIndex.setMax(selectedPoint);
+ maxIndex.setMax(other.selectedPoint);
+ }
+ if (!rangeStart.equals(other.rangeStart)) {
+ maxIndex.setMax(rangeStart);
+ maxIndex.setMax(other.rangeStart);
+ }
+ if (!rangeEnd.equals(other.rangeEnd)) {
+ maxIndex.setMax(rangeEnd);
+ maxIndex.setMax(other.rangeEnd);
+ }
+ return maxIndex.index;
+ }
+ /** @return true if the parameters are completely empty (cleared) */
+ public boolean isEmpty()
+ {
+ return !selectedPoint.hasValue && !rangeStart.hasValue && !rangeEnd.hasValue;
+ }
+ }
+