Created enum "OrderDirection" in "MathUtils" (instead of the existing

"Direction" enum enclosed in an "Order" class). Changed affected files.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@981347 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2010-08-01 23:38:06 +00:00
parent f215f96be0
commit e58f83acb8
5 changed files with 34 additions and 39 deletions

View File

@ -21,7 +21,7 @@ import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.util.LocalizedFormats;
import org.apache.commons.math.util.MathUtils;
import org.apache.commons.math.util.MathUtils.Order;
import org.apache.commons.math.util.MathUtils.OrderDirection;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
@ -56,8 +56,8 @@ public class SmoothingBicubicSplineInterpolator
throw new DimensionMismatchException(xval.length, zval.length);
}
MathUtils.checkOrder(xval, Order.Direction.INCREASING, true);
MathUtils.checkOrder(yval, Order.Direction.INCREASING, true);
MathUtils.checkOrder(xval, OrderDirection.INCREASING, true);
MathUtils.checkOrder(yval, OrderDirection.INCREASING, true);
final int xLen = xval.length;
final int yLen = yval.length;

View File

@ -34,7 +34,7 @@ public class NonMonotonousSequenceException extends MathIllegalNumberException {
/**
* Direction (positive for increasing, negative for decreasing).
*/
private final MathUtils.Order.Direction direction;
private final MathUtils.OrderDirection direction;
/**
* Whether the sequence must be strictly increasing or decreasing.
*/
@ -60,7 +60,7 @@ public class NonMonotonousSequenceException extends MathIllegalNumberException {
public NonMonotonousSequenceException(Number wrong,
Number previous,
int index) {
this(wrong, previous, index, MathUtils.Order.Direction.INCREASING, true);
this(wrong, previous, index, MathUtils.OrderDirection.INCREASING, true);
}
/**
@ -77,9 +77,9 @@ public class NonMonotonousSequenceException extends MathIllegalNumberException {
public NonMonotonousSequenceException(Number wrong,
Number previous,
int index,
MathUtils.Order.Direction direction,
MathUtils.OrderDirection direction,
boolean strict) {
super(direction == MathUtils.Order.Direction.INCREASING ?
super(direction == MathUtils.OrderDirection.INCREASING ?
(strict ?
LocalizedFormats.NOT_STRICTLY_INCREASING_SEQUENCE :
LocalizedFormats.NOT_INCREASING_SEQUENCE) :
@ -97,7 +97,7 @@ public class NonMonotonousSequenceException extends MathIllegalNumberException {
/**
* @return the order direction.
**/
public MathUtils.Order.Direction getDirection() {
public MathUtils.OrderDirection getDirection() {
return direction;
}
/**

View File

@ -1867,30 +1867,25 @@ public final class MathUtils {
return max;
}
public static class Order {
/** Enumerate type for increasing/decreasing directions. */
public static enum Direction {
/** Constant for increasing direction. */
INCREASING,
/** Constant for decreasing direction. */
DECREASING
};
/**
* Specification of ordering direction.
*/
public static enum OrderDirection {
/** Constant for increasing direction. */
INCREASING,
/** Constant for decreasing direction. */
DECREASING
}
/**
* Checks that the given array is sorted.
*
* @param val Values.
* @param dir Order direction.
* @param dir Ordering direction.
* @param strict Whether the order should be strict.
* @throws NonMonotonousSequenceException if the array is not sorted.
*/
public static void checkOrder(double[] val, Order.Direction dir, boolean strict) {
public static void checkOrder(double[] val, OrderDirection dir, boolean strict) {
double previous = val[0];
boolean ok = true;
@ -1938,7 +1933,7 @@ public final class MathUtils {
* @throws NonMonotonousSequenceException if the array is not sorted.
*/
public static void checkOrder(double[] val) {
checkOrder(val, Order.Direction.INCREASING, true);
checkOrder(val, OrderDirection.INCREASING, true);
}
/**
@ -1948,14 +1943,14 @@ public final class MathUtils {
* @param dir Order direction (-1 for decreasing, 1 for increasing)
* @param strict Whether the order should be strict
* @throws NonMonotonousSequenceException if the array is not sorted.
* @deprecated as of 2.2 (please use the new {@link #checkOrder(double[],Order.Direction,boolean)
* @deprecated as of 2.2 (please use the new {@link #checkOrder(double[],OrderDirection,boolean)
* checkOrder} method). To be removed in 3.0.
*/
public static void checkOrder(double[] val, int dir, boolean strict) {
public static void checkOrder(double[] val, int dir, boolean strict) {
if (dir > 0) {
checkOrder(val, Order.Direction.INCREASING, strict);
checkOrder(val, OrderDirection.INCREASING, strict);
} else {
checkOrder(val, Order.Direction.DECREASING, strict);
checkOrder(val, OrderDirection.DECREASING, strict);
}
}
}

View File

@ -30,18 +30,18 @@ public class NonMonotonousSequenceExceptionTest {
@Test
public void testAccessors() {
NonMonotonousSequenceException e
= new NonMonotonousSequenceException(0, -1, 1, MathUtils.Order.Direction.DECREASING, false);
= new NonMonotonousSequenceException(0, -1, 1, MathUtils.OrderDirection.DECREASING, false);
Assert.assertEquals(0, e.getArgument());
Assert.assertEquals(-1, e.getPrevious());
Assert.assertEquals(1, e.getIndex());
Assert.assertTrue(e.getDirection() == MathUtils.Order.Direction.DECREASING);
Assert.assertTrue(e.getDirection() == MathUtils.OrderDirection.DECREASING);
Assert.assertFalse(e.getStrict());
e = new NonMonotonousSequenceException(-1, 0, 1);
Assert.assertEquals(-1, e.getArgument());
Assert.assertEquals(0, e.getPrevious());
Assert.assertEquals(1, e.getIndex());
Assert.assertTrue(e.getDirection() == MathUtils.Order.Direction.INCREASING);
Assert.assertTrue(e.getDirection() == MathUtils.OrderDirection.INCREASING);
Assert.assertTrue(e.getStrict());
}
}

View File

@ -1471,38 +1471,38 @@ public final class MathUtilsTest extends TestCase {
public void testCheckOrder() {
MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 15},
MathUtils.Order.Direction.INCREASING, true);
MathUtils.OrderDirection.INCREASING, true);
MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 2},
MathUtils.Order.Direction.INCREASING, false);
MathUtils.OrderDirection.INCREASING, false);
MathUtils.checkOrder(new double[] {3, -5.5, -11, -27.5},
MathUtils.Order.Direction.DECREASING, true);
MathUtils.OrderDirection.DECREASING, true);
MathUtils.checkOrder(new double[] {3, 0, 0, -5.5, -11, -27.5},
MathUtils.Order.Direction.DECREASING, false);
MathUtils.OrderDirection.DECREASING, false);
try {
MathUtils.checkOrder(new double[] {-15, -5.5, -1, -1, 2, 15},
MathUtils.Order.Direction.INCREASING, true);
MathUtils.OrderDirection.INCREASING, true);
fail("an exception should have been thrown");
} catch (NonMonotonousSequenceException e) {
// Expected
}
try {
MathUtils.checkOrder(new double[] {-15, -5.5, -1, -2, 2},
MathUtils.Order.Direction.INCREASING, false);
MathUtils.OrderDirection.INCREASING, false);
fail("an exception should have been thrown");
} catch (NonMonotonousSequenceException e) {
// Expected
}
try {
MathUtils.checkOrder(new double[] {3, 3, -5.5, -11, -27.5},
MathUtils.Order.Direction.DECREASING, true);
MathUtils.OrderDirection.DECREASING, true);
fail("an exception should have been thrown");
} catch (NonMonotonousSequenceException e) {
// Expected
}
try {
MathUtils.checkOrder(new double[] {3, -1, 0, -5.5, -11, -27.5},
MathUtils.Order.Direction.DECREASING, false);
MathUtils.OrderDirection.DECREASING, false);
fail("an exception should have been thrown");
} catch (NonMonotonousSequenceException e) {
// Expected