Skip to content

Commit ef94704

Browse files
Jonathan727halfhp
authored andcommitted
Implement descriptive toString() methods for RectRegion and related classes (halfhp#44)
adds more descriptive toString implementations to various classes
1 parent 633ac98 commit ef94704

File tree

5 files changed

+81
-28
lines changed

5 files changed

+81
-28
lines changed

androidplot-core/src/main/java/com/androidplot/Region.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.androidplot;
1919

20-
import com.androidplot.util.*;
20+
import com.androidplot.util.FastNumber;
2121

2222
/**
2323
* A one dimensional region represented by a starting and ending value.
@@ -249,4 +249,20 @@ public void setMax(Number max) {
249249
public boolean isDefined() {
250250
return min != null && max != null;
251251
}
252+
253+
@Override
254+
public String toString() {
255+
final StringBuffer sb = new StringBuffer("Region{");
256+
sb.append("min=").append(min);
257+
sb.append(", max=").append(max);
258+
sb.append(", cachedLength=").append(cachedLength);
259+
sb.append(", defaults=");
260+
if (defaults != this) {
261+
sb.append(defaults);
262+
} else {
263+
sb.append("this");
264+
}
265+
sb.append('}');
266+
return sb.toString();
267+
}
252268
}

androidplot-core/src/main/java/com/androidplot/util/FastNumber.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ public double doubleValue() {
6363
}
6464
return doublePrimitive;
6565
}
66+
67+
@Override
68+
public String toString() {
69+
return String.valueOf(doubleValue());
70+
}
6671
}

androidplot-core/src/main/java/com/androidplot/util/SeriesUtils.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
package com.androidplot.util;
1818

19-
import com.androidplot.*;
20-
import com.androidplot.xy.*;
19+
import com.androidplot.Region;
20+
import com.androidplot.xy.FastXYSeries;
21+
import com.androidplot.xy.OrderedXYSeries;
22+
import com.androidplot.xy.RectRegion;
23+
import com.androidplot.xy.XYConstraints;
24+
import com.androidplot.xy.XYSeries;
2125

22-
import java.util.*;
26+
import java.util.List;
2327

2428
/**
2529
* Utilities for dealing with Series data.
@@ -83,18 +87,18 @@ public static RectRegion minMax(XYConstraints constraints, XYSeries... seriesArr
8387

8488
// if this is an advanced xy series then minMax have already been calculated for us:
8589
if(series instanceof FastXYSeries) {
86-
final RectRegion b = ((FastXYSeries) series).minMax();
87-
if(b == null) {
90+
final RectRegion seriesBounds = ((FastXYSeries) series).minMax();
91+
if (seriesBounds == null) {
8892
continue;
8993
}
9094
if(constraints == null) {
91-
bounds.union(b);
95+
bounds.union(seriesBounds);
9296
} else {
93-
if(constraints.contains(b.getMinX(), b.getMinY())) {
94-
bounds.union(b.getMinX(), b.getMinY());
97+
if (constraints.contains(seriesBounds.getMinX(), seriesBounds.getMinY())) {
98+
bounds.union(seriesBounds.getMinX(), seriesBounds.getMinY());
9599
}
96-
if(constraints.contains(b.getMaxX(), b.getMaxY())) {
97-
bounds.union(b.getMaxX(), b.getMaxY());
100+
if (constraints.contains(seriesBounds.getMaxX(), seriesBounds.getMaxY())) {
101+
bounds.union(seriesBounds.getMaxX(), seriesBounds.getMaxY());
98102
}
99103
}
100104

androidplot-core/src/main/java/com/androidplot/xy/RectRegion.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.graphics.RectF;
2121

2222
import com.androidplot.Region;
23+
2324
import java.util.ArrayList;
2425
import java.util.List;
2526

@@ -344,4 +345,13 @@ public boolean isFullyDefined() {
344345
public boolean contains(Number x, Number y) {
345346
return getxRegion().contains(x) && getyRegion().contains(y);
346347
}
348+
349+
@Override
350+
public String toString() {
351+
return "RectRegion{" +
352+
"xRegion=" + xRegion +
353+
", yRegion=" + yRegion +
354+
", label='" + label + '\'' +
355+
'}';
356+
}
347357
}

androidplot-core/src/main/java/com/androidplot/xy/XYConstraints.java

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
/**
2020
* Calculates the min/max constraints for an xy plane.
21+
*
2122
* @since 0.9.7
2223
*/
2324
public class XYConstraints {
@@ -52,26 +53,26 @@ public XYConstraints(Number minX, Number maxX, Number minY, Number maxY) {
5253
}
5354

5455
public boolean contains(Number x, Number y) {
55-
if(x == null || y == null) {
56+
if (x == null || y == null) {
5657
// this is essentially an invisible point:
5758
return false;
58-
} else {
59-
final double dx = x.doubleValue();
60-
61-
if(minX != null && dx < minX.doubleValue()) {
62-
return false;
63-
} else if(maxX != null && dx > maxX.doubleValue()) {
64-
return false;
65-
} else {
66-
final double dy = y.doubleValue();
67-
if(minY != null && dy < minY.doubleValue()) {
68-
return false;
69-
} else if(maxY != null && dy > maxY.doubleValue()) {
70-
return false;
71-
}
72-
}
73-
return true;
7459
}
60+
61+
final double dx = x.doubleValue();
62+
if (minX != null && dx < minX.doubleValue()) {
63+
return false;
64+
} else if (maxX != null && dx > maxX.doubleValue()) {
65+
return false;
66+
}
67+
68+
final double dy = y.doubleValue();
69+
if (minY != null && dy < minY.doubleValue()) {
70+
return false;
71+
} else if (maxY != null && dy > maxY.doubleValue()) {
72+
return false;
73+
}
74+
75+
return true;
7576
}
7677

7778
public Number getMinX() {
@@ -153,4 +154,21 @@ public void setMinY(Number minY) {
153154
public void setMaxY(Number maxY) {
154155
this.maxY = maxY;
155156
}
157+
158+
@Override
159+
public String toString() {
160+
final StringBuffer sb = new StringBuffer("XYConstraints{");
161+
sb.append("domainFramingModel=").append(domainFramingModel);
162+
sb.append(", rangeFramingModel=").append(rangeFramingModel);
163+
sb.append(", domainUpperBoundaryMode=").append(domainUpperBoundaryMode);
164+
sb.append(", domainLowerBoundaryMode=").append(domainLowerBoundaryMode);
165+
sb.append(", rangeUpperBoundaryMode=").append(rangeUpperBoundaryMode);
166+
sb.append(", rangeLowerBoundaryMode=").append(rangeLowerBoundaryMode);
167+
sb.append(", minX=").append(minX);
168+
sb.append(", maxX=").append(maxX);
169+
sb.append(", minY=").append(minY);
170+
sb.append(", maxY=").append(maxY);
171+
sb.append('}');
172+
return sb.toString();
173+
}
156174
}

0 commit comments

Comments
 (0)