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:
parent
7222fd432e
commit
70c0b99284
|
@ -2062,39 +2062,30 @@ public final class MathUtils {
|
||||||
boolean strict, boolean abort) {
|
boolean strict, boolean abort) {
|
||||||
double previous = val[0];
|
double previous = val[0];
|
||||||
final int max = val.length;
|
final int max = val.length;
|
||||||
for (int i = 1; i < max; i++) {
|
|
||||||
|
int index;
|
||||||
|
ITEM:
|
||||||
|
for (index = 1; index < max; index++) {
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case INCREASING:
|
case INCREASING:
|
||||||
if (strict) {
|
if (strict) {
|
||||||
if (val[i] <= previous) {
|
if (val[index] <= previous) {
|
||||||
if (abort) {
|
break ITEM;
|
||||||
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (val[i] < previous) {
|
if (val[index] < previous) {
|
||||||
if (abort) {
|
break ITEM;
|
||||||
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DECREASING:
|
case DECREASING:
|
||||||
if (strict) {
|
if (strict) {
|
||||||
if (val[i] >= previous) {
|
if (val[index] >= previous) {
|
||||||
if (abort) {
|
break ITEM;
|
||||||
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (val[i] > previous) {
|
if (val[index] > previous) {
|
||||||
if (abort) {
|
break ITEM;
|
||||||
throw new NonMonotonousSequenceException(val[i], previous, i, dir, strict);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2102,9 +2093,20 @@ public final class MathUtils {
|
||||||
// Should never happen.
|
// Should never happen.
|
||||||
throw new IllegalArgumentException();
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue