Skip to content

Commit 4978d5a

Browse files
committed
refinements/simplification
1 parent b71982b commit 4978d5a

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

core/src/processing/data/FloatList.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,13 @@ public boolean hasValue(float value) {
423423
}
424424

425425

426-
private String exceptionText(int count, int index, String method){
427-
return "The list size is "+count+". Trying to "+method+" the element at "+index+" which does not exist.";
426+
private void boundsProblem(int index, String method) {
427+
final String msg = String.format("The list size is %d. " +
428+
"You cannot %s() to element %d.", count, method, index);
429+
throw new ArrayIndexOutOfBoundsException(msg);
428430
}
429431

432+
430433
/**
431434
* @webref floatlist:method
432435
* @brief Add to a value
@@ -435,7 +438,7 @@ public void add(int index, float amount) {
435438
if (index < count) {
436439
data[index] += amount;
437440
} else {
438-
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "add"));
441+
boundsProblem(index, "add");
439442
}
440443
}
441444

@@ -448,7 +451,7 @@ public void sub(int index, float amount) {
448451
if (index < count) {
449452
data[index] -= amount;
450453
} else {
451-
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "sub"));
454+
boundsProblem(index, "sub");
452455
}
453456
}
454457

@@ -461,7 +464,7 @@ public void mult(int index, float amount) {
461464
if (index < count) {
462465
data[index] *= amount;
463466
} else {
464-
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "mult"));
467+
boundsProblem(index, "mult");
465468
}
466469
}
467470

@@ -474,7 +477,7 @@ public void div(int index, float amount) {
474477
if (index < count) {
475478
data[index] /= amount;
476479
} else {
477-
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "div"));
480+
boundsProblem(index, "div");
478481
}
479482
}
480483

core/src/processing/data/IntList.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,14 @@ public void increment(int index) {
407407
data[index]++;
408408
}
409409

410-
private String exceptionText(int count, int index, String method){
411-
return "The list size is "+count+". Trying to "+method+" the element at "+index+" which does not exist.";
410+
411+
private void boundsProblem(int index, String method) {
412+
final String msg = String.format("The list size is %d. " +
413+
"You cannot %s() to element %d.", count, method, index);
414+
throw new ArrayIndexOutOfBoundsException(msg);
412415
}
413416

417+
414418
/**
415419
* @webref intlist:method
416420
* @brief Add to a value
@@ -419,7 +423,7 @@ public void add(int index, int amount) {
419423
if (index < count) {
420424
data[index] += amount;
421425
} else {
422-
throw new IndexOutOfBoundsException(exceptionText(count, index, "add"));
426+
boundsProblem(index, "add");
423427
}
424428
}
425429

@@ -431,7 +435,7 @@ public void sub(int index, int amount) {
431435
if (index < count) {
432436
data[index] -= amount;
433437
} else {
434-
throw new IndexOutOfBoundsException(exceptionText(count, index, "sub"));
438+
boundsProblem(index, "sub");
435439
}
436440
}
437441

@@ -443,7 +447,7 @@ public void mult(int index, int amount) {
443447
if (index < count) {
444448
data[index] *= amount;
445449
} else {
446-
throw new IndexOutOfBoundsException(exceptionText(count, index, "mult"));
450+
boundsProblem(index, "mult");
447451
}
448452
}
449453

@@ -455,7 +459,7 @@ public void div(int index, int amount) {
455459
if (index < count) {
456460
data[index] /= amount;
457461
} else {
458-
throw new IndexOutOfBoundsException(exceptionText(count, index, "div"));
462+
boundsProblem(index, "div");
459463
}
460464
}
461465

core/todo.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ X size(640,360 , P3D) doesn't work properly
1111
X https://github.com/processing/processing/issues/2924
1212
X https://github.com/processing/processing/issues/2925
1313

14+
data
15+
X Add exceptions for FloatList and IntList when using add() w/o enough elements
16+
X https://github.com/processing/processing/pull/3053
1417

1518
applet/sketch
1619
X remove isGL(), is2D(), is3D(), displayable() from PApplet
@@ -107,6 +110,7 @@ _ but for NaN values, it's a necessity
107110
_ get() methods in List/Dict shouldn't allow you to get bad values
108111
_ but set() methods can automatically resize the arrays
109112
_ though that means insert() should allow you to insert past the end
113+
_ and should add/div/mult let you work on non-existent elements?
110114
_ addRow() is not efficient, probably need to do the doubling
111115
o or have a setIncrement() function?
112116
_ it would default to 1 on tables loaded from a file

0 commit comments

Comments
 (0)