@Test public void isValidDoubleTrue() throws Exception { assertTrue(NumberUtilities.isValidDouble("12345")); assertTrue(NumberUtilities.isValidDouble("-123.99")); assertTrue(NumberUtilities.isValidDouble("9999999999", -19999999999L, 19999999999L)); assertTrue(NumberUtilities.isValidDouble("0.1", 0.1, 1, true, false)); assertTrue(NumberUtilities.isValidDouble("1.1", 1.1, 1.1, true, true)); assertTrue(NumberUtilities.isValidDouble("-1.9", -2, -1.9, false, true)); assertTrue(NumberUtilities.isValidDouble("0.0001", 0.00009, 0.00011, false, false)); }
public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidDouble(doubleStr)) { return false; } final double aDouble = toDouble(doubleStr); final boolean respectsLowerBound = includeLowerBound ? Double.compare(lowerBound, aDouble) <= 0 : lowerBound < aDouble; final boolean respectsUpperBound = includeUpperBound ? Double.compare(aDouble, upperBound) <= 0 : aDouble < upperBound; return respectsLowerBound && respectsUpperBound; }
NumberUtilities { public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidDouble(doubleStr)) { return false; } final double aDouble = toDouble(doubleStr); final boolean respectsLowerBound = includeLowerBound ? Double.compare(lowerBound, aDouble) <= 0 : lowerBound < aDouble; final boolean respectsUpperBound = includeUpperBound ? Double.compare(aDouble, upperBound) <= 0 : aDouble < upperBound; return respectsLowerBound && respectsUpperBound; } }
NumberUtilities { public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidDouble(doubleStr)) { return false; } final double aDouble = toDouble(doubleStr); final boolean respectsLowerBound = includeLowerBound ? Double.compare(lowerBound, aDouble) <= 0 : lowerBound < aDouble; final boolean respectsUpperBound = includeUpperBound ? Double.compare(aDouble, upperBound) <= 0 : aDouble < upperBound; return respectsLowerBound && respectsUpperBound; } private  NumberUtilities(); }
NumberUtilities { public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidDouble(doubleStr)) { return false; } final double aDouble = toDouble(doubleStr); final boolean respectsLowerBound = includeLowerBound ? Double.compare(lowerBound, aDouble) <= 0 : lowerBound < aDouble; final boolean respectsUpperBound = includeUpperBound ? Double.compare(aDouble, upperBound) <= 0 : aDouble < upperBound; return respectsLowerBound && respectsUpperBound; } private  NumberUtilities(); static boolean isValidInt(@Nullable final String integerStr); static boolean isValidLong(@Nullable final String longStr); static boolean isValidInt(@Nullable final String integerStr, final int lowerBound, final int upperBound, final boolean includeLowerBound, final boolean includeUpperBound); static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound, final boolean includeLowerBound, final boolean includeUpperBound); static boolean isValidInt(@Nullable final String integerStr, final int lowerBound, final int upperBound); static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound); static int toInteger(@Nullable final String integerStr); static long toLong(@Nullable final String longStr); static int toInteger(@Nullable final String integerStr, final int defaultInteger); static long toLong(@Nullable final String longStr, final long defaultLong); static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound); static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound); static boolean isValidDouble(@Nullable final String doubleStr); static double toDouble(@Nullable final String doubleStr); static double toDouble(@Nullable final String doubleStr, final double defaultDouble); }
NumberUtilities { public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidDouble(doubleStr)) { return false; } final double aDouble = toDouble(doubleStr); final boolean respectsLowerBound = includeLowerBound ? Double.compare(lowerBound, aDouble) <= 0 : lowerBound < aDouble; final boolean respectsUpperBound = includeUpperBound ? Double.compare(aDouble, upperBound) <= 0 : aDouble < upperBound; return respectsLowerBound && respectsUpperBound; } private  NumberUtilities(); static boolean isValidInt(@Nullable final String integerStr); static boolean isValidLong(@Nullable final String longStr); static boolean isValidInt(@Nullable final String integerStr, final int lowerBound, final int upperBound, final boolean includeLowerBound, final boolean includeUpperBound); static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound, final boolean includeLowerBound, final boolean includeUpperBound); static boolean isValidInt(@Nullable final String integerStr, final int lowerBound, final int upperBound); static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound); static int toInteger(@Nullable final String integerStr); static long toLong(@Nullable final String longStr); static int toInteger(@Nullable final String integerStr, final int defaultInteger); static long toLong(@Nullable final String longStr, final long defaultLong); static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound); static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound); static boolean isValidDouble(@Nullable final String doubleStr); static double toDouble(@Nullable final String doubleStr); static double toDouble(@Nullable final String doubleStr, final double defaultDouble);  }