MathUtils { public static boolean isNumeric( String value ) { return value != null && DOUBLE_VALIDATOR.isValid( value, LOCALE ) && NUMERIC_PATTERN.matcher( value ).matches() && value.length() < NUMBER_MAX_LENGTH; }  static boolean isValidDouble( Double d ); static double getFloor( double value ); static double getRounded( double value ); static Object getRoundedObject( Object value ); static double roundSignificant( double value ); static double roundToSignificantDigits( double value, int n ); static double roundFraction( double value, int n ); static int getMin( int number, int min ); static int getMax( int number, int max ); static int getWithin( int value, int min, int max ); static boolean isNumeric( String value ); static boolean isNumericLenient( String value ); static boolean isUnitInterval( String value ); static boolean isPercentage( String value ); static boolean isInteger( String value ); static boolean isPositiveInteger( String value ); static boolean isZeroOrPositiveInteger( String value ); static boolean isCoordinate( String value ); static boolean isNegativeInteger( String value ); static boolean isZero( String value ); static boolean isBool( String value ); static boolean isEqual( Double d1, Double d2 ); static boolean isEqual( double d1, double d2 ); static boolean isZero( double value ); static double zeroIfNull( Double value ); static int getRandom(); static Double getMin( double[] array ); static Double getMax( double[] array ); static Double getAverage( List<Double> values ); static Double getSum( List<Double> values ); static Double parseDouble( String value ); static Integer parseInt( String string ); static double getLowBound( double stdDev, double stdDevNo, double average ); static double getHighBound( double stdDev, double stdDevFactor, double average ); static int divideToCeil( int numerator, int denominator ); static int divideToFloor( int numerator, int denominator ); static final Double ZERO; static final String NUMERIC_REGEXP; static final String NUMERIC_LENIENT_REGEXP; }
@Test public void testIsNumeric() { assertTrue( MathUtils.isNumeric( "123" ) ); assertTrue( MathUtils.isNumeric( "0" ) ); assertTrue( MathUtils.isNumeric( "1.2" ) ); assertTrue( MathUtils.isNumeric( "12.34" ) ); assertTrue( MathUtils.isNumeric( "0.0" ) ); assertTrue( MathUtils.isNumeric( "1.234" ) ); assertTrue( MathUtils.isNumeric( "-1234" ) ); assertTrue( MathUtils.isNumeric( "-12.34" ) ); assertTrue( MathUtils.isNumeric( "-0.34" ) ); assertTrue( MathUtils.isNumeric( "6.34" ) ); assertTrue( MathUtils.isNumeric( "3.34" ) ); assertTrue( MathUtils.isNumeric( "2.43" ) ); assertFalse( MathUtils.isNumeric( "Hey" ) ); assertFalse( MathUtils.isNumeric( "45 Perinatal Condition" ) ); assertFalse( MathUtils.isNumeric( "Long street 2" ) ); assertFalse( MathUtils.isNumeric( "1.2f" ) ); assertFalse( MathUtils.isNumeric( "1 234" ) ); assertFalse( MathUtils.isNumeric( "." ) ); assertFalse( MathUtils.isNumeric( "1." ) ); assertFalse( MathUtils.isNumeric( ".1" ) ); assertFalse( MathUtils.isNumeric( "" ) ); assertFalse( MathUtils.isNumeric( " " ) ); assertFalse( MathUtils.isNumeric( "+1234 " ) ); assertFalse( MathUtils.isNumeric( "1234 " ) ); assertFalse( MathUtils.isNumeric( " 1234" ) ); assertFalse( MathUtils.isNumeric( "1,234" ) ); assertFalse( MathUtils.isNumeric( "0,1" ) ); assertFalse( MathUtils.isNumeric( "0," ) ); assertFalse( MathUtils.isNumeric( "0." ) ); assertFalse( MathUtils.isNumeric( "01" ) ); assertFalse( MathUtils.isNumeric( "001" ) ); assertFalse( MathUtils.isNumeric( "00.23" ) ); assertFalse( MathUtils.isNumeric( "01.23" ) ); assertFalse( MathUtils.isNumeric( "4.23E" ) ); assertFalse( MathUtils.isNumeric( "4.23Ef" ) ); assertFalse( MathUtils.isNumeric( "E5" ) ); assertFalse( MathUtils.isNumeric( null ) ); }