Skip to content

Commit 66082fe

Browse files
committed
Added text to the exceptions for FloatList and IntList
Fixed formatting of IntList
1 parent 5213fa8 commit 66082fe

2 files changed

Lines changed: 28 additions & 20 deletions

File tree

core/src/processing/data/FloatList.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ 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.";
428+
}
429+
426430
/**
427431
* @webref floatlist:method
428432
* @brief Add to a value
@@ -431,7 +435,7 @@ public void add(int index, float amount) {
431435
if (index < count) {
432436
data[index] += amount;
433437
} else {
434-
throw new IndexOutOfBoundsException();
438+
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "add"));
435439
}
436440
}
437441

@@ -444,7 +448,7 @@ public void sub(int index, float amount) {
444448
if (index < count) {
445449
data[index] -= amount;
446450
} else {
447-
throw new IndexOutOfBoundsException();
451+
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "sub"));
448452
}
449453
}
450454

@@ -457,7 +461,7 @@ public void mult(int index, float amount) {
457461
if (index < count) {
458462
data[index] *= amount;
459463
} else {
460-
throw new IndexOutOfBoundsException();
464+
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "mult"));
461465
}
462466
}
463467

@@ -470,7 +474,7 @@ public void div(int index, float amount) {
470474
if (index < count) {
471475
data[index] /= amount;
472476
} else {
473-
throw new IndexOutOfBoundsException();
477+
throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "div"));
474478
}
475479
}
476480

core/src/processing/data/IntList.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -407,52 +407,56 @@ 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.";
412+
}
413+
410414
/**
411415
* @webref intlist:method
412416
* @brief Add to a value
413417
*/
414418
public void add(int index, int amount) {
415-
if( index < count) {
416-
data[index] += amount;
419+
if (index < count) {
420+
data[index] += amount;
417421
} else {
418-
throw new IndexOutOfBoundsException();
419-
}
422+
throw new IndexOutOfBoundsException(exceptionText(count, index, "add"));
423+
}
420424
}
421425

422426
/**
423427
* @webref intlist:method
424428
* @brief Subtract from a value
425429
*/
426430
public void sub(int index, int amount) {
427-
if( index < count) {
428-
data[index] -= amount;
431+
if (index < count) {
432+
data[index] -= amount;
429433
} else {
430-
throw new IndexOutOfBoundsException();
431-
}
434+
throw new IndexOutOfBoundsException(exceptionText(count, index, "sub"));
435+
}
432436
}
433437

434438
/**
435439
* @webref intlist:method
436440
* @brief Multiply a value
437441
*/
438442
public void mult(int index, int amount) {
439-
if( index < count) {
440-
data[index] *= amount;
443+
if (index < count) {
444+
data[index] *= amount;
441445
} else {
442-
throw new IndexOutOfBoundsException();
443-
}
446+
throw new IndexOutOfBoundsException(exceptionText(count, index, "mult"));
447+
}
444448
}
445449

446450
/**
447451
* @webref intlist:method
448452
* @brief Divide a value
449453
*/
450454
public void div(int index, int amount) {
451-
if( index < count) {
452-
data[index] /= amount;
455+
if (index < count) {
456+
data[index] /= amount;
453457
} else {
454-
throw new IndexOutOfBoundsException();
455-
}
458+
throw new IndexOutOfBoundsException(exceptionText(count, index, "div"));
459+
}
456460
}
457461

458462

0 commit comments

Comments
 (0)