@@ -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
0 commit comments