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

View File

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

View File

@ -1867,30 +1867,25 @@ public final class MathUtils {
return max; return max;
} }
public static class Order { /**
* Specification of ordering direction.
/** Enumerate type for increasing/decreasing directions. */ */
public static enum Direction { public static enum OrderDirection {
/** Constant for increasing direction. */
/** Constant for increasing direction. */ INCREASING,
INCREASING, /** Constant for decreasing direction. */
DECREASING
/** Constant for decreasing direction. */
DECREASING
};
} }
/** /**
* Checks that the given array is sorted. * Checks that the given array is sorted.
* *
* @param val Values. * @param val Values.
* @param dir Order direction. * @param dir Ordering direction.
* @param strict Whether the order should be strict. * @param strict Whether the order should be strict.
* @throws NonMonotonousSequenceException if the array is not sorted. * @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]; double previous = val[0];
boolean ok = true; boolean ok = true;
@ -1938,7 +1933,7 @@ public final class MathUtils {
* @throws NonMonotonousSequenceException if the array is not sorted. * @throws NonMonotonousSequenceException if the array is not sorted.
*/ */
public static void checkOrder(double[] val) { 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 dir Order direction (-1 for decreasing, 1 for increasing)
* @param strict Whether the order should be strict * @param strict Whether the order should be strict
* @throws NonMonotonousSequenceException if the array is not sorted. * @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. * 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) { if (dir > 0) {
checkOrder(val, Order.Direction.INCREASING, strict); checkOrder(val, OrderDirection.INCREASING, strict);
} else { } else {
checkOrder(val, Order.Direction.DECREASING, strict); checkOrder(val, OrderDirection.DECREASING, strict);
} }
} }
} }

View File

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

View File

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