| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -423,6 +423,10 @@ public boolean hasValue(float value) { | |||
| 423 | 423 | } | |
| 424 | 424 | ||
| 425 | 425 | ||
| 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 | + | ||
| 426 | 430 | /** | |
| 427 | 431 | * @webref floatlist:method | |
| 428 | 432 | * @brief Add to a value | |
@@ -431,7 +435,7 @@ public void add(int index, float amount) { | |||
| 431 | 435 | if (index < count) { | |
| 432 | 436 | data[index] += amount; | |
| 433 | 437 | } else { | |
| 434 | - throw new IndexOutOfBoundsException(); | ||
| 438 | + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "add")); | ||
| 435 | 439 | } | |
| 436 | 440 | } | |
| 437 | 441 | ||
@@ -444,7 +448,7 @@ public void sub(int index, float amount) { | |||
| 444 | 448 | if (index < count) { | |
| 445 | 449 | data[index] -= amount; | |
| 446 | 450 | } else { | |
| 447 | - throw new IndexOutOfBoundsException(); | ||
| 451 | + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "sub")); | ||
| 448 | 452 | } | |
| 449 | 453 | } | |
| 450 | 454 | ||
@@ -457,7 +461,7 @@ public void mult(int index, float amount) { | |||
| 457 | 461 | if (index < count) { | |
| 458 | 462 | data[index] *= amount; | |
| 459 | 463 | } else { | |
| 460 | - throw new IndexOutOfBoundsException(); | ||
| 464 | + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "mult")); | ||
| 461 | 465 | } | |
| 462 | 466 | } | |
| 463 | 467 | ||
@@ -470,7 +474,7 @@ public void div(int index, float amount) { | |||
| 470 | 474 | if (index < count) { | |
| 471 | 475 | data[index] /= amount; | |
| 472 | 476 | } else { | |
| 473 | - throw new IndexOutOfBoundsException(); | ||
| 477 | + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "div")); | ||
| 474 | 478 | } | |
| 475 | 479 | } | |
| 476 | 480 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -407,52 +407,56 @@ public void increment(int index) { | |||
| 407 | 407 | data[index]++; | |
| 408 | 408 | } | |
| 409 | 409 | ||
| 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 | + | ||
| 410 | 414 | /** | |
| 411 | 415 | * @webref intlist:method | |
| 412 | 416 | * @brief Add to a value | |
| 413 | 417 | */ | |
| 414 | 418 | public void add(int index, int amount) { | |
| 415 | - if( index < count) { | ||
| 416 | - data[index] += amount; | ||
| 419 | + if (index < count) { | ||
| 420 | + data[index] += amount; | ||
| 417 | 421 | } else { | |
| 418 | - throw new IndexOutOfBoundsException(); | ||
| 419 | - } | ||
| 422 | + throw new IndexOutOfBoundsException(exceptionText(count, index, "add")); | ||
| 423 | + } | ||
| 420 | 424 | } | |
| 421 | 425 | ||
| 422 | 426 | /** | |
| 423 | 427 | * @webref intlist:method | |
| 424 | 428 | * @brief Subtract from a value | |
| 425 | 429 | */ | |
| 426 | 430 | public void sub(int index, int amount) { | |
| 427 | - if( index < count) { | ||
| 428 | - data[index] -= amount; | ||
| 431 | + if (index < count) { | ||
| 432 | + data[index] -= amount; | ||
| 429 | 433 | } else { | |
| 430 | - throw new IndexOutOfBoundsException(); | ||
| 431 | - } | ||
| 434 | + throw new IndexOutOfBoundsException(exceptionText(count, index, "sub")); | ||
| 435 | + } | ||
| 432 | 436 | } | |
| 433 | 437 | ||
| 434 | 438 | /** | |
| 435 | 439 | * @webref intlist:method | |
| 436 | 440 | * @brief Multiply a value | |
| 437 | 441 | */ | |
| 438 | 442 | public void mult(int index, int amount) { | |
| 439 | - if( index < count) { | ||
| 440 | - data[index] *= amount; | ||
| 443 | + if (index < count) { | ||
| 444 | + data[index] *= amount; | ||
| 441 | 445 | } else { | |
| 442 | - throw new IndexOutOfBoundsException(); | ||
| 443 | - } | ||
| 446 | + throw new IndexOutOfBoundsException(exceptionText(count, index, "mult")); | ||
| 447 | + } | ||
| 444 | 448 | } | |
| 445 | 449 | ||
| 446 | 450 | /** | |
| 447 | 451 | * @webref intlist:method | |
| 448 | 452 | * @brief Divide a value | |
| 449 | 453 | */ | |
| 450 | 454 | public void div(int index, int amount) { | |
| 451 | - if( index < count) { | ||
| 452 | - data[index] /= amount; | ||
| 455 | + if (index < count) { | ||
| 456 | + data[index] /= amount; | ||
| 453 | 457 | } else { | |
| 454 | - throw new IndexOutOfBoundsException(); | ||
| 455 | - } | ||
| 458 | + throw new IndexOutOfBoundsException(exceptionText(count, index, "div")); | ||
| 459 | + } | ||
| 456 | 460 | } | |
| 457 | 461 | ||
| 458 | 462 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments