List of usage examples for java.math BigDecimal ROUND_FLOOR
int ROUND_FLOOR
To view the source code for java.math BigDecimal ROUND_FLOOR.
Click Source Link
From source file:Armadillo.Analytics.Base.Precision.java
/** * Rounds the given non-negative value to the "nearest" integer. Nearest is * determined by the rounding method specified. Rounding methods are defined * in {@link BigDecimal}.//from ww w. j av a 2 s . co m * * @param unscaled Value to round. * @param sign Sign of the original, scaled value. * @param roundingMethod Rounding method, as defined in {@link BigDecimal}. * @return the rounded value. * @throws MathArithmeticException if an exact operation is required but result is not exact * @throws MathIllegalArgumentException if {@code roundingMethod} is not a valid rounding method. * @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0) */ private static double roundUnscaled(double unscaled, double sign, int roundingMethod) throws MathArithmeticException, MathIllegalArgumentException { switch (roundingMethod) { case BigDecimal.ROUND_CEILING: if (sign == -1) { unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY)); } else { unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY)); } break; case BigDecimal.ROUND_DOWN: unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY)); break; case BigDecimal.ROUND_FLOOR: if (sign == -1) { unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY)); } else { unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY)); } break; case BigDecimal.ROUND_HALF_DOWN: { unscaled = FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY); double fraction = unscaled - FastMath.floor(unscaled); if (fraction > 0.5) { unscaled = FastMath.ceil(unscaled); } else { unscaled = FastMath.floor(unscaled); } break; } case BigDecimal.ROUND_HALF_EVEN: { double fraction = unscaled - FastMath.floor(unscaled); if (fraction > 0.5) { unscaled = FastMath.ceil(unscaled); } else if (fraction < 0.5) { unscaled = FastMath.floor(unscaled); } else { // The following equality test is intentional and needed for rounding purposes if (FastMath.floor(unscaled) / 2.0 == FastMath.floor(Math.floor(unscaled) / 2.0)) { // even unscaled = FastMath.floor(unscaled); } else { // odd unscaled = FastMath.ceil(unscaled); } } break; } case BigDecimal.ROUND_HALF_UP: { unscaled = FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY); double fraction = unscaled - FastMath.floor(unscaled); if (fraction >= 0.5) { unscaled = FastMath.ceil(unscaled); } else { unscaled = FastMath.floor(unscaled); } break; } case BigDecimal.ROUND_UNNECESSARY: if (unscaled != FastMath.floor(unscaled)) { throw new MathArithmeticException(); } break; case BigDecimal.ROUND_UP: unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY)); break; default: throw new MathIllegalArgumentException(LocalizedFormats.INVALID_ROUNDING_METHOD, roundingMethod, "ROUND_CEILING", BigDecimal.ROUND_CEILING, "ROUND_DOWN", BigDecimal.ROUND_DOWN, "ROUND_FLOOR", BigDecimal.ROUND_FLOOR, "ROUND_HALF_DOWN", BigDecimal.ROUND_HALF_DOWN, "ROUND_HALF_EVEN", BigDecimal.ROUND_HALF_EVEN, "ROUND_HALF_UP", BigDecimal.ROUND_HALF_UP, "ROUND_UNNECESSARY", BigDecimal.ROUND_UNNECESSARY, "ROUND_UP", BigDecimal.ROUND_UP); } return unscaled; }
From source file:org.pentaho.di.core.ConstTest.java
@Test public void testRound_BigDecimal() { assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.0"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.2"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.5"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("1.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("1.7"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.0"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.2"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.5"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.5"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("2.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("3.0"), Const.round(new BigDecimal("2.7"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.0"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.2"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.5"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.5"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-1.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-1.7"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.0"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.2"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.5"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-2.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-3.0"), Const.round(new BigDecimal("-2.7"), 0, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.010"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.012"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.015"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.010"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.017"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.020"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.022"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.025"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.025"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("0.020"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("0.030"), Const.round(new BigDecimal("0.027"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.010"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.012"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.015"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.015"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.010"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.017"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.020"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.022"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.025"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-0.020"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-0.030"), Const.round(new BigDecimal("-0.027"), 2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("100.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("120.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("150.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("100.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("170.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("200.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("220.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("250.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("250.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("200.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("300.0"), Const.round(new BigDecimal("270.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-100.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-120.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-150.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-150.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-100.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-170.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-200.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-220.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-250.0"), -2, Const.ROUND_HALF_CEILING)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_UP)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_DOWN)); assertEquals(new BigDecimal("-200.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_CEILING)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_FLOOR)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_HALF_UP)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(new BigDecimal("-300.0"), Const.round(new BigDecimal("-270.0"), -2, Const.ROUND_HALF_CEILING)); }
From source file:at.alladin.rmbt.statisticServer.OpenTestSearchResource.java
/** * Gets the JSON Array for a specific histogram * @param min lower bound of first class * @param max upper bound of last class/*w w w .j a va 2s .c o m*/ * @param field numeric database-field that the histogram is based on * @param isLogarithmic * @param whereClause * @param searchValues * @return * @throws JSONException * @throws CacheException */ private JSONArray getJSONForHistogram(double min, double max, String field, boolean isLogarithmic, String whereClause, Queue<Map.Entry<String, FieldType>> searchValues) throws JSONException { //Get min and max steps double difference = max - min; int digits = (int) Math.floor(Math.log10(difference)); //get histogram classes long upperBound = new BigDecimal(max).setScale(-digits, BigDecimal.ROUND_CEILING).longValue(); long lowerBound = new BigDecimal(min).setScale(-digits, BigDecimal.ROUND_FLOOR).longValue(); double step = ((double) (upperBound - lowerBound)) / ((double) HISTOGRAMCLASSES); System.out.println("lower: " + lowerBound + ", upper: " + upperBound + ", digits: " + digits + ", diff: " + difference + ", step: " + step); //psql width_bucket: gets the histogram class in which a value belongs final String sql = "select " + " width_bucket(" + field + "," + lowerBound + "," + upperBound + "," + HISTOGRAMCLASSES + ") bucket, " + " count(*) cnt " + " from test t " + " LEFT JOIN network_type nt ON nt.uid=t.network_type" + " LEFT JOIN device_map adm ON adm.codename=t.model" + " LEFT JOIN test_server ts ON ts.uid=t.server_id" + " LEFT JOIN provider prov ON provider_id = prov.uid " + " LEFT JOIN provider mprov ON mobile_provider_id = mprov.uid" + " where " + field + " > 0 " + " AND t.deleted = false" + ((this.excludeImplausible) ? " AND implausible = false" : "") + " AND status = 'FINISHED' " + whereClause + " group by bucket " + "order by bucket asc;"; JSONArray jArray = new JSONArray(); try { PreparedStatement stmt = conn.prepareStatement(sql); stmt = fillInWhereClause(stmt, searchValues, 1); ResultSet rs = stmt.executeQuery(); JSONObject jBucket = null; long prevCnt = 0; int prevBucket = 0; while (rs.next()) { int bucket = rs.getInt("bucket"); long cnt = rs.getLong("cnt"); double current_lower_bound = lowerBound + step * (bucket - 1); //logarithmic -> times 10 for kbit if (isLogarithmic) current_lower_bound = Math.pow(10, current_lower_bound * 4) * 10; double current_upper_bound = lowerBound + (step * bucket); if (isLogarithmic) current_upper_bound = Math.pow(10, current_upper_bound * 4) * 10; if (bucket - prevBucket > 1) { //problem: bucket without values //solution: respond with classes with "0" elements in them int diff = bucket - prevBucket; for (int i = 1; i < diff; i++) { prevBucket++; jBucket = new JSONObject(); double tLowerBound = lowerBound + step * (prevBucket - 1); if (isLogarithmic) tLowerBound = Math.pow(10, tLowerBound * 4) * 10; double tUpperBound = lowerBound + (step * prevBucket); if (isLogarithmic) tUpperBound = Math.pow(10, tUpperBound * 4) * 10; jBucket.put("lower_bound", tLowerBound); jBucket.put("upper_bound", tUpperBound); jBucket.put("results", 0); jArray.put(jBucket); } } prevBucket = bucket; prevCnt = cnt; jBucket = new JSONObject(); if (bucket == 0) { jBucket.put("lower_bound", JSONObject.NULL); } else { //2 digits accuracy for small differences if (step < 1 && !isLogarithmic) jBucket.put("lower_bound", ((double) Math.round(current_lower_bound * 100)) / (double) 100); else jBucket.put("lower_bound", Math.round(current_lower_bound)); } if (bucket == HISTOGRAMCLASSES + 1) { jBucket.put("upper_bound", JSONObject.NULL); } else { if (step < 1 && !isLogarithmic) jBucket.put("upper_bound", ((double) Math.round(current_upper_bound * 100)) / (double) 100); else jBucket.put("upper_bound", Math.round(current_upper_bound)); } jBucket.put("results", cnt); jArray.put(jBucket); } //problem: not enough buckets //solution: respond with classes with "0" elements if (jArray.length() < HISTOGRAMCLASSES) { int diff = HISTOGRAMCLASSES - jArray.length(); int bucket = jArray.length(); for (int i = 0; i < diff; i++) { jBucket = new JSONObject(); bucket++; double tLowerBound = lowerBound + step * (bucket - 1); if (isLogarithmic) tLowerBound = Math.pow(10, tLowerBound * 4) * 10; double tUpperBound = lowerBound + (step * bucket); if (isLogarithmic) tUpperBound = Math.pow(10, tUpperBound * 4) * 10; jBucket.put("lower_bound", tLowerBound); jBucket.put("upper_bound", tUpperBound); jBucket.put("results", 0); jArray.put(jBucket); } } rs.close(); stmt.close(); } catch (SQLException e) { e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jArray; }
From source file:com.cisco.dvbu.ps.deploytool.dao.jdbcapi.RegressionPerfTestDAOImpl.java
private String executePerformanceTestWorkers() throws CompositeException { try {/*ww w .j a va 2 s . c om*/ // Create all the connections Worker[] workers = new Worker[perfTestThreads]; for (int i = 0; i < workers.length; i++) { workers[i] = new Worker(); } // Pause in between query executions Thread.sleep(perfTestSleepExec * 1000); // Start the clock long startTime = System.currentTimeMillis(); endTime = startTime + perfTestDuration * 1000; // Start the workers for (int i = 0; i < workers.length; i++) { workers[i].start(); } // Output the Header Rows String content = CommonUtils.lpad(HEADER, 7, padChar) + logDelim + CommonUtils.rpad("Threads=" + perfTestThreads, 12, padChar) + logDelim + CommonUtils.rpad("Duration (s)=" + perfTestDuration, 17, padChar) + logDelim + CommonUtils.rpad("Print Sleep (s)=" + perfTestSleepPrint, 19, padChar) + logDelim + CommonUtils.rpad("Exec Sleep (s)=" + perfTestSleepExec, 18, padChar) + logDelim + logDelim + logDelim + logDelim; RegressionManagerUtils.printOutputStr(printOutputType, "summary", content, ""); StringBuffer buf = new StringBuffer(); buf.append(content + "\n"); content = CommonUtils.lpad(HEADER, 8, padChar) + logDelim + CommonUtils.rpad("Execs", 12, padChar) + logDelim + CommonUtils.rpad("Execs/sec", 12, padChar) + logDelim + CommonUtils.rpad("Rows/exec", 12, padChar) + logDelim + CommonUtils.rpad("Latency (ms)", 13, padChar) + logDelim + CommonUtils.rpad("1st row (ms)", 13, padChar) + logDelim + CommonUtils.rpad("Duration (ms)", 14, padChar) + logDelim + logDelim; RegressionManagerUtils.printOutputStr(printOutputType, "summary", content, ""); buf.append(content + "\n"); // Initialize the totals before each query execution. numStatExecs.set(0); execsTotal = 0; tpsTotal = new BigDecimal(0); rptTotal = new BigDecimal(0); latTotal = new BigDecimal(0); frTotal = new BigDecimal(0); durTotal = new BigDecimal(0); /* Safeguard: determine the number of loops by taking the "total duration" divided by the "print stat sleep interval" * This is important because sometimes the timing is off when the end time is calculated and when worker threads are * still running. The issue is pointed out below (-->) when there is an extra line printed that throws off the stats. * * HEADER|Threads=1 |Duration (s)=10 |Print Sleep (s)=5 |Exec Sleep (s)=0 |||| * HEADER|Execs |Execs/sec |Rows/exec |Latency (ms) |1st row (ms) |Duration (ms) || * DETAIL|4780 |957.91 |1.00 |1.04 |1.03 |4990.00 || * DETAIL|5146 |1027.96 |1.00 |0.97 |0.96 |5006.00 || * -->DETAIL|11 |2.19 |1.00 |0.90 |0.90 |5018.00 || * TOTALS|3312.33 |662.68 |1.00 |0.97 |0.96 |5004.66 || */ int totalExecLoops = perfTestDuration / perfTestSleepPrint; // Print stats periodically errorFound = false; int loopCounter = 0; while (System.currentTimeMillis() < endTime && !errorFound && loopCounter < totalExecLoops) { Thread.sleep(perfTestSleepPrint * 1000); content = printStats(startTime); if (content != null) buf.append(content); // Reset print stat counters numExecs.set(0); numLatency.set(0); firstRowLatency.set(0); numRows.set(0); startTime = System.currentTimeMillis(); loopCounter++; } // Wait for the workers to finish for (int i = 0; i < workers.length; i++) { workers[i].join(); } // Print stats /* * This is @deprecated as it was determined that the last stat line was inconsistent and throwing off the numbers content = printStats(startTime); if (content != null) buf.append(content); */ // Calculate the Total Average Stats for each run and output as a TOTALS line if (numStatExecs.get() > 0) { // Calculate total average executions BigDecimal execAvg = new BigDecimal(execsTotal); execAvg = execAvg.divide(new BigDecimal(numStatExecs.get()), 5, BigDecimal.ROUND_FLOOR); execAvg = execAvg.setScale(2, BigDecimal.ROUND_DOWN); // Calculate total average execs/sec or tps BigDecimal tpsAvg = tpsTotal; tpsAvg = tpsAvg.divide(new BigDecimal(numStatExecs.get()), 5, BigDecimal.ROUND_FLOOR); tpsAvg = tpsAvg.setScale(2, BigDecimal.ROUND_DOWN); // Calculate total average Rows per Execution BigDecimal rptAvg = rptTotal; rptAvg = rptAvg.divide(new BigDecimal(numStatExecs.get()), 5, BigDecimal.ROUND_FLOOR); rptAvg = rptAvg.setScale(2, BigDecimal.ROUND_DOWN); // Calculate total average Latency BigDecimal latAvg = latTotal; latAvg = latAvg.divide(new BigDecimal(numStatExecs.get()), 5, BigDecimal.ROUND_FLOOR); latAvg = latAvg.setScale(2, BigDecimal.ROUND_DOWN); // Calculate total average First Row Latency BigDecimal frAvg = frTotal; frAvg = frAvg.divide(new BigDecimal(numStatExecs.get()), 5, BigDecimal.ROUND_FLOOR); frAvg = frAvg.setScale(2, BigDecimal.ROUND_DOWN); // Calculate total average Duration BigDecimal durAvg = durTotal; durAvg = durAvg.divide(new BigDecimal(numStatExecs.get()), 5, BigDecimal.ROUND_FLOOR); durAvg = durAvg.setScale(2, BigDecimal.ROUND_DOWN); // Print out the summary Totals line content = CommonUtils.lpad(TOTALS, 8, padChar) + logDelim + CommonUtils.rpad("" + execAvg, 12, padChar) + logDelim + CommonUtils.rpad("" + tpsAvg, 12, padChar) + logDelim + CommonUtils.rpad("" + rptAvg, 12, padChar) + logDelim + CommonUtils.rpad("" + latAvg, 13, padChar) + logDelim + CommonUtils.rpad("" + frAvg, 13, padChar) + logDelim + CommonUtils.rpad("" + durAvg, 20, padChar) + logDelim + logDelim; RegressionManagerUtils.printOutputStr(printOutputType, "summary", content, ""); buf.append(content + "\n"); } return buf.toString(); } catch (Exception e) { throw new ApplicationException(e); } }
From source file:hjow.hgtable.util.DataUtil.java
/** * <p>2? 1 ? .</p>//from w w w . j ava2s . c o m * * @param original : ?? * @param scale : ? * @return 2? 1 */ public static BigDecimal sqrt(BigDecimal original, int scale) { BigDecimal temp = new BigDecimal(String.valueOf(original)); BigDecimal results = new BigDecimal("1.0"); results.setScale(scale + 2); int loops = 0; while (true) { if (loops >= 1) { temp = new BigDecimal(String.valueOf(results)); } temp.setScale(scale + 2, BigDecimal.ROUND_FLOOR); results = original.divide(temp, scale + 2, BigDecimal.ROUND_FLOOR).add(temp) .divide(new BigDecimal("2.0"), scale + 2, BigDecimal.ROUND_FLOOR); if (temp.equals(results)) break; loops++; } return results.setScale(scale, BigDecimal.ROUND_HALF_UP); }
From source file:org.apache.ofbiz.shipment.thirdparty.usps.UspsServices.java
public static Map<String, Object> uspsUpdateShipmentRateInfo(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); Locale locale = (Locale) context.get("locale"); Map<String, Object> shipmentGatewayConfig = ShipmentServices.getShipmentGatewayConfigFromShipment(delegator, shipmentId, locale);/*from w w w.j av a2s . c o m*/ String shipmentGatewayConfigId = (String) shipmentGatewayConfig.get("shipmentGatewayConfigId"); String resource = (String) shipmentGatewayConfig.get("configProps"); if (UtilValidate.isEmpty(shipmentGatewayConfigId) && UtilValidate.isEmpty(resource)) { return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentUspsGatewayNotAvailable", locale)); } try { GenericValue shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment") .where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).queryOne(); if (shipmentRouteSegment == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductShipmentRouteSegmentNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } // ensure the carrier is USPS if (!"USPS".equals(shipmentRouteSegment.getString("carrierPartyId"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNotRouteSegmentCarrier", UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId), locale)); } // get the origin address GenericValue originAddress = shipmentRouteSegment.getRelatedOne("OriginPostalAddress", false); if (originAddress == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentRouteSegmentOriginPostalAddressNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } if (!"USA".equals(originAddress.getString("countryGeoId"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentOriginCountryGeoNotInUsa", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } String originZip = originAddress.getString("postalCode"); if (UtilValidate.isEmpty(originZip)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentOriginZipCodeMissing", UtilMisc.toMap("contactMechId", originAddress.getString("contactMechId")), locale)); } // get the destination address GenericValue destinationAddress = shipmentRouteSegment.getRelatedOne("DestPostalAddress", false); if (destinationAddress == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentRouteSegmentDestPostalAddressNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } if (!"USA".equals(destinationAddress.getString("countryGeoId"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentOriginCountryGeoNotInUsa", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } String destinationZip = destinationAddress.getString("postalCode"); if (UtilValidate.isEmpty(destinationZip)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentDestinationZipCodeMissing", UtilMisc.toMap("contactMechId", destinationAddress.getString("contactMechId")), locale)); } // get the service type from the CarrierShipmentMethod String shipmentMethodTypeId = shipmentRouteSegment.getString("shipmentMethodTypeId"); String partyId = shipmentRouteSegment.getString("carrierPartyId"); GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") .where("partyId", partyId, "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentMethodTypeId) .queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNoCarrierShipmentMethod", UtilMisc.toMap("carrierPartyId", partyId, "shipmentMethodTypeId", shipmentMethodTypeId), locale)); } String serviceType = carrierShipmentMethod.getString("carrierServiceCode"); if (UtilValidate.isEmpty(serviceType)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNoCarrierServiceCodeFound", UtilMisc.toMap("carrierPartyId", partyId, "shipmentMethodTypeId", shipmentMethodTypeId), locale)); } // get the packages for this shipment route segment List<GenericValue> shipmentPackageRouteSegList = shipmentRouteSegment .getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId"), false); if (UtilValidate.isEmpty(shipmentPackageRouteSegList)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentPackageRouteSegsNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } BigDecimal actualTransportCost = BigDecimal.ZERO; String carrierDeliveryZone = null; String carrierRestrictionCodes = null; String carrierRestrictionDesc = null; // send a new request for each package for (Iterator<GenericValue> i = shipmentPackageRouteSegList.iterator(); i.hasNext();) { GenericValue shipmentPackageRouteSeg = i.next(); Document requestDocument = createUspsRequestDocument("RateRequest", true, delegator, shipmentGatewayConfigId, resource); Element packageElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "Package", requestDocument); packageElement.setAttribute("ID", "0"); UtilXml.addChildElementValue(packageElement, "Service", serviceType, requestDocument); UtilXml.addChildElementValue(packageElement, "ZipOrigination", originZip, requestDocument); UtilXml.addChildElementValue(packageElement, "ZipDestination", destinationZip, requestDocument); GenericValue shipmentPackage = null; shipmentPackage = shipmentPackageRouteSeg.getRelatedOne("ShipmentPackage", false); // weight elements - Pounds, Ounces String weightStr = shipmentPackage.getString("weight"); if (UtilValidate.isEmpty(weightStr)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsWeightNotFound", UtilMisc.toMap("shipmentId", shipmentPackage.getString("shipmentId"), "shipmentPackageSeqId", shipmentPackage.getString("shipmentPackageSeqId")), locale)); } BigDecimal weight = BigDecimal.ZERO; try { weight = new BigDecimal(weightStr); } catch (NumberFormatException nfe) { nfe.printStackTrace(); // TODO: handle exception } String weightUomId = shipmentPackage.getString("weightUomId"); if (UtilValidate.isEmpty(weightUomId)) { weightUomId = "WT_lb"; // assume weight is in pounds } if (!"WT_lb".equals(weightUomId)) { // attempt a conversion to pounds Map<String, Object> result = new HashMap<String, Object>(); try { result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", "WT_lb", "originalValue", weight)); } catch (GenericServiceException ex) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsWeightConversionError", UtilMisc.toMap("errorString", ex.getMessage()), locale)); } if (result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS) && result.get("convertedValue") != null) { weight = weight.multiply((BigDecimal) result.get("convertedValue")); } else { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsWeightUnsupported", UtilMisc.toMap("weightUomId", weightUomId, "shipmentId", shipmentPackage.getString("shipmentId"), "shipmentPackageSeqId", shipmentPackage.getString("shipmentPackageSeqId"), "weightUom", "WT_lb"), locale)); } } BigDecimal weightPounds = weight.setScale(0, BigDecimal.ROUND_FLOOR); BigDecimal weightOunces = weight.multiply(new BigDecimal("16")).remainder(new BigDecimal("16")) .setScale(0, BigDecimal.ROUND_CEILING); DecimalFormat df = new DecimalFormat("#"); UtilXml.addChildElementValue(packageElement, "Pounds", df.format(weightPounds), requestDocument); UtilXml.addChildElementValue(packageElement, "Ounces", df.format(weightOunces), requestDocument); // Container element GenericValue carrierShipmentBoxType = null; List<GenericValue> carrierShipmentBoxTypes = null; carrierShipmentBoxTypes = shipmentPackage.getRelated("CarrierShipmentBoxType", UtilMisc.toMap("partyId", "USPS"), null, false); if (carrierShipmentBoxTypes.size() > 0) { carrierShipmentBoxType = carrierShipmentBoxTypes.get(0); } if (carrierShipmentBoxType != null && UtilValidate.isNotEmpty(carrierShipmentBoxType.getString("packagingTypeCode"))) { UtilXml.addChildElementValue(packageElement, "Container", carrierShipmentBoxType.getString("packagingTypeCode"), requestDocument); } else { // default to "None", for customers using their own package UtilXml.addChildElementValue(packageElement, "Container", "None", requestDocument); } // Size element if (carrierShipmentBoxType != null && UtilValidate.isNotEmpty("oversizeCode")) { UtilXml.addChildElementValue(packageElement, "Size", carrierShipmentBoxType.getString("oversizeCode"), requestDocument); } else { // default to "Regular", length + girth measurement <= 84 inches UtilXml.addChildElementValue(packageElement, "Size", "Regular", requestDocument); } // Although only applicable for Parcel Post, this tag is required for all requests UtilXml.addChildElementValue(packageElement, "Machinable", "False", requestDocument); Document responseDocument = null; try { responseDocument = sendUspsRequest("Rate", requestDocument, delegator, shipmentGatewayConfigId, resource, locale); } catch (UspsRequestException e) { Debug.logInfo(e, module); return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticSendingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } Element respPackageElement = UtilXml.firstChildElement(responseDocument.getDocumentElement(), "Package"); if (respPackageElement == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticResponseIncompleteElementPackage", locale)); } Element respErrorElement = UtilXml.firstChildElement(respPackageElement, "Error"); if (respErrorElement != null) { return ServiceUtil .returnError(UtilProperties .getMessage(resourceError, "FacilityShipmentUspsRateDomesticResponseError", UtilMisc.toMap("errorString", UtilXml.childElementValue(respErrorElement, "Description")), locale)); } // update the ShipmentPackageRouteSeg String postageString = UtilXml.childElementValue(respPackageElement, "Postage"); if (UtilValidate.isEmpty(postageString)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticResponseIncompleteElementPostage", locale)); } BigDecimal postage = BigDecimal.ZERO; try { postage = new BigDecimal(postageString); } catch (NumberFormatException nfe) { nfe.printStackTrace(); // TODO: handle exception } actualTransportCost = actualTransportCost.add(postage); shipmentPackageRouteSeg.setString("packageTransportCost", postageString); shipmentPackageRouteSeg.store(); // if this is the last package, get the zone and APO/FPO restrictions for the ShipmentRouteSegment if (!i.hasNext()) { carrierDeliveryZone = UtilXml.childElementValue(respPackageElement, "Zone"); carrierRestrictionCodes = UtilXml.childElementValue(respPackageElement, "RestrictionCodes"); carrierRestrictionDesc = UtilXml.childElementValue(respPackageElement, "RestrictionDescription"); } } // update the ShipmentRouteSegment shipmentRouteSegment.set("carrierDeliveryZone", carrierDeliveryZone); shipmentRouteSegment.set("carrierRestrictionCodes", carrierRestrictionCodes); shipmentRouteSegment.set("carrierRestrictionDesc", carrierRestrictionDesc); shipmentRouteSegment.setString("actualTransportCost", String.valueOf(actualTransportCost)); shipmentRouteSegment.store(); } catch (GenericEntityException gee) { Debug.logInfo(gee, module); return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticReadingError", UtilMisc.toMap("errorString", gee.getMessage()), locale)); } return ServiceUtil.returnSuccess(); }
From source file:org.ofbiz.shipment.thirdparty.usps.UspsServices.java
public static Map<String, Object> uspsUpdateShipmentRateInfo(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); Locale locale = (Locale) context.get("locale"); Map<String, Object> shipmentGatewayConfig = ShipmentServices.getShipmentGatewayConfigFromShipment(delegator, shipmentId, locale);//from www . ja v a 2s . c o m String shipmentGatewayConfigId = (String) shipmentGatewayConfig.get("shipmentGatewayConfigId"); String resource = (String) shipmentGatewayConfig.get("configProps"); if (UtilValidate.isEmpty(shipmentGatewayConfigId) && UtilValidate.isEmpty(resource)) { return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentUspsGatewayNotAvailable", locale)); } try { GenericValue shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment") .where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).queryOne(); if (shipmentRouteSegment == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductShipmentRouteSegmentNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } // ensure the carrier is USPS if (!"USPS".equals(shipmentRouteSegment.getString("carrierPartyId"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNotRouteSegmentCarrier", UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId), locale)); } // get the origin address GenericValue originAddress = shipmentRouteSegment.getRelatedOne("OriginPostalAddress", false); if (originAddress == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentRouteSegmentOriginPostalAddressNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } if (!"USA".equals(originAddress.getString("countryGeoId"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentOriginCountryGeoNotInUsa", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } String originZip = originAddress.getString("postalCode"); if (UtilValidate.isEmpty(originZip)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentOriginZipCodeMissing", UtilMisc.toMap("contactMechId", originAddress.getString("contactMechId")), locale)); } // get the destination address GenericValue destinationAddress = shipmentRouteSegment.getRelatedOne("DestPostalAddress", false); if (destinationAddress == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentRouteSegmentDestPostalAddressNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } if (!"USA".equals(destinationAddress.getString("countryGeoId"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentOriginCountryGeoNotInUsa", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } String destinationZip = destinationAddress.getString("postalCode"); if (UtilValidate.isEmpty(destinationZip)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRouteSegmentDestinationZipCodeMissing", UtilMisc.toMap("contactMechId", destinationAddress.getString("contactMechId")), locale)); } // get the service type from the CarrierShipmentMethod String shipmentMethodTypeId = shipmentRouteSegment.getString("shipmentMethodTypeId"); String partyId = shipmentRouteSegment.getString("carrierPartyId"); GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") .where("partyId", partyId, "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentMethodTypeId) .queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNoCarrierShipmentMethod", UtilMisc.toMap("carrierPartyId", partyId, "shipmentMethodTypeId", shipmentMethodTypeId), locale)); } String serviceType = carrierShipmentMethod.getString("carrierServiceCode"); if (UtilValidate.isEmpty(serviceType)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNoCarrierServiceCodeFound", UtilMisc.toMap("carrierPartyId", partyId, "shipmentMethodTypeId", shipmentMethodTypeId), locale)); } // get the packages for this shipment route segment List<GenericValue> shipmentPackageRouteSegList = shipmentRouteSegment .getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId"), false); if (UtilValidate.isEmpty(shipmentPackageRouteSegList)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentPackageRouteSegsNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } BigDecimal actualTransportCost = BigDecimal.ZERO; String carrierDeliveryZone = null; String carrierRestrictionCodes = null; String carrierRestrictionDesc = null; // send a new request for each package for (Iterator<GenericValue> i = shipmentPackageRouteSegList.iterator(); i.hasNext();) { GenericValue shipmentPackageRouteSeg = i.next(); //String sprsKeyString = "[" + shipmentPackageRouteSeg.getString("shipmentId") + "," + // shipmentPackageRouteSeg.getString("shipmentPackageSeqId") + "," + // shipmentPackageRouteSeg.getString("shipmentRouteSegmentId") + "]"; Document requestDocument = createUspsRequestDocument("RateRequest", true, delegator, shipmentGatewayConfigId, resource); Element packageElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "Package", requestDocument); packageElement.setAttribute("ID", "0"); UtilXml.addChildElementValue(packageElement, "Service", serviceType, requestDocument); UtilXml.addChildElementValue(packageElement, "ZipOrigination", originZip, requestDocument); UtilXml.addChildElementValue(packageElement, "ZipDestination", destinationZip, requestDocument); GenericValue shipmentPackage = null; shipmentPackage = shipmentPackageRouteSeg.getRelatedOne("ShipmentPackage", false); // weight elements - Pounds, Ounces String weightStr = shipmentPackage.getString("weight"); if (UtilValidate.isEmpty(weightStr)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsWeightNotFound", UtilMisc.toMap("shipmentId", shipmentPackage.getString("shipmentId"), "shipmentPackageSeqId", shipmentPackage.getString("shipmentPackageSeqId")), locale)); } BigDecimal weight = BigDecimal.ZERO; try { weight = new BigDecimal(weightStr); } catch (NumberFormatException nfe) { nfe.printStackTrace(); // TODO: handle exception } String weightUomId = shipmentPackage.getString("weightUomId"); if (UtilValidate.isEmpty(weightUomId)) { weightUomId = "WT_lb"; // assume weight is in pounds } if (!"WT_lb".equals(weightUomId)) { // attempt a conversion to pounds Map<String, Object> result = FastMap.newInstance(); try { result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", "WT_lb", "originalValue", weight)); } catch (GenericServiceException ex) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsWeightConversionError", UtilMisc.toMap("errorString", ex.getMessage()), locale)); } if (result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS) && result.get("convertedValue") != null) { weight = weight.multiply((BigDecimal) result.get("convertedValue")); } else { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsWeightUnsupported", UtilMisc.toMap("weightUomId", weightUomId, "shipmentId", shipmentPackage.getString("shipmentId"), "shipmentPackageSeqId", shipmentPackage.getString("shipmentPackageSeqId"), "weightUom", "WT_lb"), locale)); } } BigDecimal weightPounds = weight.setScale(0, BigDecimal.ROUND_FLOOR); BigDecimal weightOunces = weight.multiply(new BigDecimal("16")).remainder(new BigDecimal("16")) .setScale(0, BigDecimal.ROUND_CEILING); DecimalFormat df = new DecimalFormat("#"); UtilXml.addChildElementValue(packageElement, "Pounds", df.format(weightPounds), requestDocument); UtilXml.addChildElementValue(packageElement, "Ounces", df.format(weightOunces), requestDocument); // Container element GenericValue carrierShipmentBoxType = null; List<GenericValue> carrierShipmentBoxTypes = null; carrierShipmentBoxTypes = shipmentPackage.getRelated("CarrierShipmentBoxType", UtilMisc.toMap("partyId", "USPS"), null, false); if (carrierShipmentBoxTypes.size() > 0) { carrierShipmentBoxType = carrierShipmentBoxTypes.get(0); } if (carrierShipmentBoxType != null && UtilValidate.isNotEmpty(carrierShipmentBoxType.getString("packagingTypeCode"))) { UtilXml.addChildElementValue(packageElement, "Container", carrierShipmentBoxType.getString("packagingTypeCode"), requestDocument); } else { // default to "None", for customers using their own package UtilXml.addChildElementValue(packageElement, "Container", "None", requestDocument); } // Size element if (carrierShipmentBoxType != null && UtilValidate.isNotEmpty("oversizeCode")) { UtilXml.addChildElementValue(packageElement, "Size", carrierShipmentBoxType.getString("oversizeCode"), requestDocument); } else { // default to "Regular", length + girth measurement <= 84 inches UtilXml.addChildElementValue(packageElement, "Size", "Regular", requestDocument); } // Although only applicable for Parcel Post, this tag is required for all requests UtilXml.addChildElementValue(packageElement, "Machinable", "False", requestDocument); Document responseDocument = null; try { responseDocument = sendUspsRequest("Rate", requestDocument, delegator, shipmentGatewayConfigId, resource, locale); } catch (UspsRequestException e) { Debug.logInfo(e, module); return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticSendingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } Element respPackageElement = UtilXml.firstChildElement(responseDocument.getDocumentElement(), "Package"); if (respPackageElement == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticResponseIncompleteElementPackage", locale)); } Element respErrorElement = UtilXml.firstChildElement(respPackageElement, "Error"); if (respErrorElement != null) { return ServiceUtil .returnError(UtilProperties .getMessage(resourceError, "FacilityShipmentUspsRateDomesticResponseError", UtilMisc.toMap("errorString", UtilXml.childElementValue(respErrorElement, "Description")), locale)); } // update the ShipmentPackageRouteSeg String postageString = UtilXml.childElementValue(respPackageElement, "Postage"); if (UtilValidate.isEmpty(postageString)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticResponseIncompleteElementPostage", locale)); } BigDecimal postage = BigDecimal.ZERO; try { postage = new BigDecimal(postageString); } catch (NumberFormatException nfe) { nfe.printStackTrace(); // TODO: handle exception } actualTransportCost = actualTransportCost.add(postage); shipmentPackageRouteSeg.setString("packageTransportCost", postageString); shipmentPackageRouteSeg.store(); // if this is the last package, get the zone and APO/FPO restrictions for the ShipmentRouteSegment if (!i.hasNext()) { carrierDeliveryZone = UtilXml.childElementValue(respPackageElement, "Zone"); carrierRestrictionCodes = UtilXml.childElementValue(respPackageElement, "RestrictionCodes"); carrierRestrictionDesc = UtilXml.childElementValue(respPackageElement, "RestrictionDescription"); } } // update the ShipmentRouteSegment shipmentRouteSegment.set("carrierDeliveryZone", carrierDeliveryZone); shipmentRouteSegment.set("carrierRestrictionCodes", carrierRestrictionCodes); shipmentRouteSegment.set("carrierRestrictionDesc", carrierRestrictionDesc); shipmentRouteSegment.setString("actualTransportCost", String.valueOf(actualTransportCost)); shipmentRouteSegment.store(); } catch (GenericEntityException gee) { Debug.logInfo(gee, module); return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticReadingError", UtilMisc.toMap("errorString", gee.getMessage()), locale)); } return ServiceUtil.returnSuccess(); }
From source file:org.pentaho.di.core.ConstTest.java
@Test public void testRound() { assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(1.0, Const.round(1.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(1.0, Const.round(1.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(1.2, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(1.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(1.0, Const.round(1.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(1.0, Const.round(1.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1.0, Const.round(1.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(1.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(1.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_UP)); assertEquals(1.0, Const.round(1.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(1.0, Const.round(1.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(1.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(1.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(2.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(2.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(3.0, Const.round(2.2, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(3.0, Const.round(2.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(2.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2.0, Const.round(2.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(3.0, Const.round(2.5, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(3.0, Const.round(2.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(3.0, Const.round(2.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2.0, Const.round(2.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(3.0, Const.round(2.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_UP)); assertEquals(2.0, Const.round(2.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(2.0, Const.round(2.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(3.0, Const.round(2.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(3.0, Const.round(2.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-1.0, Const.round(-1.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1.0, Const.round(-1.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-1.2, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-1.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-1.0, Const.round(-1.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1.0, Const.round(-1.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1.0, Const.round(-1.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-1.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1.0, Const.round(-1.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_UP)); assertEquals(-1.0, Const.round(-1.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1.0, Const.round(-1.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-1.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-1.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-2.0, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-2.0, 0, Const.ROUND_HALF_CEILING)); assertEquals(-3.0, Const.round(-2.2, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_CEILING)); assertEquals(-3.0, Const.round(-2.2, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-2.2, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-2.2, 0, Const.ROUND_HALF_CEILING)); assertEquals(-3.0, Const.round(-2.5, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_CEILING)); assertEquals(-3.0, Const.round(-2.5, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-3.0, Const.round(-2.5, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2.0, Const.round(-2.5, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2.0, Const.round(-2.5, 0, Const.ROUND_HALF_CEILING)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_UP)); assertEquals(-2.0, Const.round(-2.7, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2.0, Const.round(-2.7, 0, BigDecimal.ROUND_CEILING)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-3.0, Const.round(-2.7, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-3.0, Const.round(-2.7, 0, Const.ROUND_HALF_CEILING)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.010, Const.round(0.010, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.010, Const.round(0.010, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.012, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.012, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.010, Const.round(0.012, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.010, Const.round(0.012, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.015, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.015, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.010, Const.round(0.015, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.015, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.015, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_UP)); assertEquals(0.010, Const.round(0.017, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.010, Const.round(0.017, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.017, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.017, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.020, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.020, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.030, Const.round(0.022, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.030, Const.round(0.022, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.022, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.020, Const.round(0.022, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.030, Const.round(0.025, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.030, Const.round(0.025, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.030, Const.round(0.025, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.020, Const.round(0.025, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.030, Const.round(0.025, 2, Const.ROUND_HALF_CEILING)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_UP)); assertEquals(0.020, Const.round(0.027, 2, BigDecimal.ROUND_DOWN)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_CEILING)); assertEquals(0.020, Const.round(0.027, 2, BigDecimal.ROUND_FLOOR)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(0.030, Const.round(0.027, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(0.030, Const.round(0.027, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.010, Const.round(-0.010, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.010, Const.round(-0.010, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.012, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.012, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.010, Const.round(-0.012, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.010, Const.round(-0.012, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.015, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.015, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.010, Const.round(-0.015, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.015, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.010, Const.round(-0.015, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_UP)); assertEquals(-0.010, Const.round(-0.017, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.010, Const.round(-0.017, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.017, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.017, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.020, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.020, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.030, Const.round(-0.022, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.030, Const.round(-0.022, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.022, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.022, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.030, Const.round(-0.025, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.030, Const.round(-0.025, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.030, Const.round(-0.025, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.020, Const.round(-0.025, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.020, Const.round(-0.025, 2, Const.ROUND_HALF_CEILING)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_UP)); assertEquals(-0.020, Const.round(-0.027, 2, BigDecimal.ROUND_DOWN)); assertEquals(-0.020, Const.round(-0.027, 2, BigDecimal.ROUND_CEILING)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_FLOOR)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_HALF_UP)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-0.030, Const.round(-0.027, 2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-0.030, Const.round(-0.027, 2, Const.ROUND_HALF_CEILING)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100.0, Const.round(100.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100.0, Const.round(100.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(120.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(120.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100.0, Const.round(120.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100.0, Const.round(120.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(150.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(150.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100.0, Const.round(150.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(150.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(150.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_UP)); assertEquals(100.0, Const.round(170.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(100.0, Const.round(170.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(170.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(170.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(200.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(200.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(300.0, Const.round(220.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(300.0, Const.round(220.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(220.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200.0, Const.round(220.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(300.0, Const.round(250.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(300.0, Const.round(250.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300.0, Const.round(250.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200.0, Const.round(250.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300.0, Const.round(250.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_UP)); assertEquals(200.0, Const.round(270.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(200.0, Const.round(270.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(300.0, Const.round(270.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300.0, Const.round(270.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100.0, Const.round(-100.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100.0, Const.round(-100.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-120.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-120.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100.0, Const.round(-120.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100.0, Const.round(-120.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-150.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-150.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100.0, Const.round(-150.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-150.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100.0, Const.round(-150.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_UP)); assertEquals(-100.0, Const.round(-170.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100.0, Const.round(-170.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-170.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-170.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-200.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-200.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300.0, Const.round(-220.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300.0, Const.round(-220.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-220.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-220.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300.0, Const.round(-250.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300.0, Const.round(-250.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300.0, Const.round(-250.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200.0, Const.round(-250.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200.0, Const.round(-250.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_UP)); assertEquals(-200.0, Const.round(-270.0, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200.0, Const.round(-270.0, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-300.0, Const.round(-270.0, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-300.0, Const.round(-270.0, -2, Const.ROUND_HALF_CEILING)); assertEquals(Double.NaN, Const.round(Double.NaN, 0, BigDecimal.ROUND_UP)); assertEquals(Double.NEGATIVE_INFINITY, Const.round(Double.NEGATIVE_INFINITY, 0, BigDecimal.ROUND_UP)); assertEquals(Double.POSITIVE_INFINITY, Const.round(Double.POSITIVE_INFINITY, 0, BigDecimal.ROUND_UP)); }
From source file:org.pentaho.di.core.ConstTest.java
@Test public void testRound_Long() { assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_UP)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_DOWN)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_CEILING)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(1L, Const.round(1L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(1L, Const.round(1L, 0, Const.ROUND_HALF_CEILING)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_UP)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_DOWN)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_CEILING)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(2L, Const.round(2L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(2L, Const.round(2L, 0, Const.ROUND_HALF_CEILING)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_UP)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_DOWN)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_CEILING)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-1L, Const.round(-1L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-1L, Const.round(-1L, 0, Const.ROUND_HALF_CEILING)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_UP)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_DOWN)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_CEILING)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_FLOOR)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_HALF_UP)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-2L, Const.round(-2L, 0, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-2L, Const.round(-2L, 0, Const.ROUND_HALF_CEILING)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_DOWN)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100L, Const.round(100L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100L, Const.round(100L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(120L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(120L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(100L, Const.round(120L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(100L, Const.round(120L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(150L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(150L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(100L, Const.round(150L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(150L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(150L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_UP)); assertEquals(100L, Const.round(170L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_CEILING)); assertEquals(100L, Const.round(170L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(170L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(170L, -2, Const.ROUND_HALF_CEILING)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_DOWN)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(200L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(200L, -2, Const.ROUND_HALF_CEILING)); assertEquals(300L, Const.round(220L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_DOWN)); assertEquals(300L, Const.round(220L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(220L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(200L, Const.round(220L, -2, Const.ROUND_HALF_CEILING)); assertEquals(300L, Const.round(250L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_DOWN)); assertEquals(300L, Const.round(250L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300L, Const.round(250L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(200L, Const.round(250L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300L, Const.round(250L, -2, Const.ROUND_HALF_CEILING)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_UP)); assertEquals(200L, Const.round(270L, -2, BigDecimal.ROUND_DOWN)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_CEILING)); assertEquals(200L, Const.round(270L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(300L, Const.round(270L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(300L, Const.round(270L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100L, Const.round(-100L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100L, Const.round(-100L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-120L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-120L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-100L, Const.round(-120L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100L, Const.round(-120L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-150L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-150L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-100L, Const.round(-150L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-150L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-100L, Const.round(-150L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_UP)); assertEquals(-100L, Const.round(-170L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-100L, Const.round(-170L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-170L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-170L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-200L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-200L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300L, Const.round(-220L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300L, Const.round(-220L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-220L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-220L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300L, Const.round(-250L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300L, Const.round(-250L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300L, Const.round(-250L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-200L, Const.round(-250L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-200L, Const.round(-250L, -2, Const.ROUND_HALF_CEILING)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_UP)); assertEquals(-200L, Const.round(-270L, -2, BigDecimal.ROUND_DOWN)); assertEquals(-200L, Const.round(-270L, -2, BigDecimal.ROUND_CEILING)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_FLOOR)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_HALF_UP)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_HALF_DOWN)); assertEquals(-300L, Const.round(-270L, -2, BigDecimal.ROUND_HALF_EVEN)); assertEquals(-300L, Const.round(-270L, -2, Const.ROUND_HALF_CEILING)); }
From source file:org.apache.ofbiz.shipment.thirdparty.usps.UspsServices.java
public static Integer[] convertPoundsToPoundsOunces(BigDecimal decimalPounds) { if (decimalPounds == null) return null; Integer[] poundsOunces = new Integer[2]; poundsOunces[0] = Integer.valueOf(decimalPounds.setScale(0, BigDecimal.ROUND_FLOOR).toPlainString()); // (weight % 1) * 16 rounded up to nearest whole number poundsOunces[1] = Integer.valueOf(decimalPounds.remainder(BigDecimal.ONE).multiply(new BigDecimal("16")) .setScale(0, BigDecimal.ROUND_CEILING).toPlainString()); return poundsOunces; }