Using labeled loop to avoid code duplication.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1174153 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2011-09-22 14:13:09 +00:00
parent 7222fd432e
commit 70c0b99284
1 changed files with 25 additions and 23 deletions

View File

@ -2062,39 +2062,30 @@ public final class MathUtils {
boolean strict, boolean abort) {
double previous = val[0];
final int max = val.length;
for (int i = 1; i < max; i++) {
int index;
ITEM:
for (index = 1; index < max; index++) {
switch (dir) {
case INCREASING:
if (strict) {
if (val[i] <= previous) {
if (abort) {
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
}
return false;
if (val[index] <= previous) {
break ITEM;
}
} else {
if (val[i] < previous) {
if (abort) {
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
}
return false;
if (val[index] < previous) {
break ITEM;
}
}
break;
case DECREASING:
if (strict) {
if (val[i] >= previous) {
if (abort) {
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
}
return false;
if (val[index] >= previous) {
break ITEM;
}
} else {
if (val[i] > previous) {
if (abort) {
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
}
return false;
if (val[index] > previous) {
break ITEM;
}
}
break;
@ -2102,9 +2093,20 @@ public final class MathUtils {
// Should never happen.
throw new IllegalArgumentException();
}
previous = val[i];
previous = val[index];
}
if (index == max) {
// Loop completed.
return true;
}
// Loop early exit means wrong ordering.
if (abort) {
throw new NonMonotonousSequenceException(val[index], previous, index, dir, strict);
} else {
return false;
}
return true;
}
/**