@Override public double getWeight(double y) { ArgChecker.inRangeInclusive(y, 0d, 1d, "y"); return y; }
@Override public double getWeight(double y) { ArgChecker.inRangeInclusive(y, 0d, 1d, "y"); return 0.5 * (Math.sin(Math.PI * (y - 0.5)) + 1); }
@ImmutableValidator private void validate() { ArgChecker.inRangeInclusive(recoveryRate, 0d, 1d, "recoveryRate"); }
/** * Obtains a standard formatter configured by grouping and decimal places. * <p> * The formatter will have the specified number of decimal places. * The integer part will be grouped if the flag is set. * The decimal part will never be grouped or truncated. * The implementation uses English locale data, which uses commas as a separator and a decimal point (dot). * Numbers will be rounded using {@link RoundingMode#HALF_EVEN} * * @param grouped true to group, false to not group * @param minDecimalPlaces the minimum number of decimal places, from 0 to 9 * @param maxDecimalPlaces the minimum number of decimal places, from 0 to 9 * @return the formatter * @throws IllegalArgumentException if the decimal places is invalid */ public static NumberFormatter of(boolean grouped, int minDecimalPlaces, int maxDecimalPlaces) { ArgChecker.inRangeInclusive(minDecimalPlaces, 0, 9, "minDecimalPlaces"); ArgChecker.inRangeInclusive(maxDecimalPlaces, 0, 9, "maxDecimalPlaces"); ArgChecker.isTrue(minDecimalPlaces <= maxDecimalPlaces, "Expected minDecimalPlaces <= maxDecimalPlaces"); return create(grouped, minDecimalPlaces, maxDecimalPlaces); }
/** * Obtains a formatter for decimal percentages configured by grouping and decimal places. * <p> * The formatter will have the specified number of decimal places. * The integer part will be grouped if the flag is set. * The decimal part will never be grouped or truncated. * The implementation uses English locale data, which uses commas as a separator and a decimal point (dot). * The formatter will suffix the output with '%'. * Numbers will be rounded using {@link RoundingMode#HALF_EVEN} * <p> * The number passed in must be the decimal representation of the percentage. * It will be multiplied by 100 before formatting. * * @param grouped true to group, false to not group * @param minDecimalPlaces the minimum number of decimal places, from 0 to 9 * @param maxDecimalPlaces the minimum number of decimal places, from 0 to 9 * @return the formatter * @throws IllegalArgumentException if the decimal places is invalid */ public static NumberFormatter ofPercentage(boolean grouped, int minDecimalPlaces, int maxDecimalPlaces) { ArgChecker.inRangeInclusive(minDecimalPlaces, 0, 9, "minDecimalPlaces"); ArgChecker.inRangeInclusive(maxDecimalPlaces, 0, 9, "maxDecimalPlaces"); ArgChecker.isTrue(minDecimalPlaces <= maxDecimalPlaces, "Expected minDecimalPlaces <= maxDecimalPlaces"); NumberFormat format = NumberFormat.getPercentInstance(Locale.ENGLISH); format.setGroupingUsed(grouped); format.setMinimumIntegerDigits(1); format.setMinimumFractionDigits(minDecimalPlaces); format.setMaximumFractionDigits(maxDecimalPlaces); return new NumberFormatter(format); }
@Override public Double apply(Double x) { ArgChecker.inRangeInclusive(x, 0d, 1d, "x"); double pp, p, t, h, w, lnA, lnB, u, a1 = _a - 1; double b1 = _b - 1;
public void test_int_inRange() { int low = 0; int mid = 1; int high = 2; assertEquals(ArgChecker.inRange(mid, low, high, "name"), mid); assertEquals(ArgChecker.inRange(low, low, high, "name"), low); assertEquals(ArgChecker.inRangeInclusive(mid, low, high, "name"), mid); assertEquals(ArgChecker.inRangeInclusive(low, low, high, "name"), low); assertEquals(ArgChecker.inRangeInclusive(high, low, high, "name"), high); assertEquals(ArgChecker.inRangeExclusive(mid, low, high, "name"), mid); }
public void test_double_inRange() { double low = 0d; double mid = 0.5d; double high = 1d; double small = 0.00000000001d; assertEquals(ArgChecker.inRange(mid, low, high, "name"), mid); assertEquals(ArgChecker.inRange(low, low, high, "name"), low); assertEquals(ArgChecker.inRange(high - small, low, high, "name"), high - small); assertEquals(ArgChecker.inRangeInclusive(mid, low, high, "name"), mid); assertEquals(ArgChecker.inRangeInclusive(low, low, high, "name"), low); assertEquals(ArgChecker.inRangeInclusive(high, low, high, "name"), high); assertEquals(ArgChecker.inRangeExclusive(mid, low, high, "name"), mid); assertEquals(ArgChecker.inRangeExclusive(small, low, high, "name"), small); assertEquals(ArgChecker.inRangeExclusive(high - small, low, high, "name"), high - small); }
public void test_double_inRange_outOfRange() { double low = 0d; double high = 1d; double small = 0.00000000001d; assertThrowsIllegalArg(() -> ArgChecker.inRange(low - small, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRange(high, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeInclusive(low - small, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeInclusive(high + small, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeExclusive(low, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeExclusive(high, low, high, "name")); }
public void test_int_inRange_outOfRange() { int low = 0; int high = 1; assertThrowsIllegalArg(() -> ArgChecker.inRange(low - 1, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRange(high, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeInclusive(low - 1, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeInclusive(high + 1, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeExclusive(low, low, high, "name")); assertThrowsIllegalArg(() -> ArgChecker.inRangeExclusive(high, low, high, "name")); }