diff --git a/core/src/processing/data/FloatList.java b/core/src/processing/data/FloatList.java index 1d06b772a..625850a1e 100644 --- a/core/src/processing/data/FloatList.java +++ b/core/src/processing/data/FloatList.java @@ -423,10 +423,13 @@ public class FloatList implements Iterable { } - 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 { 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 { 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 { 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 { if (index < count) { data[index] /= amount; } else { - throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "div")); + boundsProblem(index, "div"); } } diff --git a/core/src/processing/data/IntList.java b/core/src/processing/data/IntList.java index 0cf5f207b..c591d3ae8 100644 --- a/core/src/processing/data/IntList.java +++ b/core/src/processing/data/IntList.java @@ -407,10 +407,14 @@ public class IntList implements Iterable { 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 { 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 { 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 { 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 { if (index < count) { data[index] /= amount; } else { - throw new IndexOutOfBoundsException(exceptionText(count, index, "div")); + boundsProblem(index, "div"); } } diff --git a/core/todo.txt b/core/todo.txt index c14ac47e3..39592f074 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -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