refinements/simplification

This commit is contained in:
Ben Fry
2015-01-21 15:53:55 -05:00
parent ba1f496247
commit 7096c953b2
3 changed files with 23 additions and 12 deletions
+9 -6
View File
@@ -423,10 +423,13 @@ public class FloatList implements Iterable<Float> {
}
private String exceptionText(int count, int index, String method){
return "The list size is "+count+". Trying to "+method+" the element at "+index+" which does not exist.";
private void boundsProblem(int index, String method) {
final String msg = String.format("The list size is %d. " +
"You cannot %s() to element %d.", count, method, index);
throw new ArrayIndexOutOfBoundsException(msg);
}
/**
* @webref floatlist:method
* @brief Add to a value
@@ -435,7 +438,7 @@ public class FloatList implements Iterable<Float> {
if (index < count) {
data[index] += amount;
} else {
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "add"));
boundsProblem(index, "add");
}
}
@@ -448,7 +451,7 @@ public class FloatList implements Iterable<Float> {
if (index < count) {
data[index] -= amount;
} else {
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "sub"));
boundsProblem(index, "sub");
}
}
@@ -461,7 +464,7 @@ public class FloatList implements Iterable<Float> {
if (index < count) {
data[index] *= amount;
} else {
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "mult"));
boundsProblem(index, "mult");
}
}
@@ -474,7 +477,7 @@ public class FloatList implements Iterable<Float> {
if (index < count) {
data[index] /= amount;
} else {
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "div"));
boundsProblem(index, "div");
}
}
+10 -6
View File
@@ -407,10 +407,14 @@ public class IntList implements Iterable<Integer> {
data[index]++;
}
private String exceptionText(int count, int index, String method){
return "The list size is "+count+". Trying to "+method+" the element at "+index+" which does not exist.";
private void boundsProblem(int index, String method) {
final String msg = String.format("The list size is %d. " +
"You cannot %s() to element %d.", count, method, index);
throw new ArrayIndexOutOfBoundsException(msg);
}
/**
* @webref intlist:method
* @brief Add to a value
@@ -419,7 +423,7 @@ public class IntList implements Iterable<Integer> {
if (index < count) {
data[index] += amount;
} else {
throw new IndexOutOfBoundsException(exceptionText(count, index, "add"));
boundsProblem(index, "add");
}
}
@@ -431,7 +435,7 @@ public class IntList implements Iterable<Integer> {
if (index < count) {
data[index] -= amount;
} else {
throw new IndexOutOfBoundsException(exceptionText(count, index, "sub"));
boundsProblem(index, "sub");
}
}
@@ -443,7 +447,7 @@ public class IntList implements Iterable<Integer> {
if (index < count) {
data[index] *= amount;
} else {
throw new IndexOutOfBoundsException(exceptionText(count, index, "mult"));
boundsProblem(index, "mult");
}
}
@@ -455,7 +459,7 @@ public class IntList implements Iterable<Integer> {
if (index < count) {
data[index] /= amount;
} else {
throw new IndexOutOfBoundsException(exceptionText(count, index, "div"));
boundsProblem(index, "div");
}
}
+4
View File
@@ -11,6 +11,9 @@ X size(640,360 , P3D) doesn't work properly
X https://github.com/processing/processing/issues/2924
X https://github.com/processing/processing/issues/2925
data
X Add exceptions for FloatList and IntList when using add() w/o enough elements
X https://github.com/processing/processing/pull/3053
applet/sketch
X remove isGL(), is2D(), is3D(), displayable() from PApplet
@@ -107,6 +110,7 @@ _ but for NaN values, it's a necessity
_ get() methods in List/Dict shouldn't allow you to get bad values
_ but set() methods can automatically resize the arrays
_ though that means insert() should allow you to insert past the end
_ and should add/div/mult let you work on non-existent elements?
_ addRow() is not efficient, probably need to do the doubling
o or have a setIncrement() function?
_ it would default to 1 on tables loaded from a file