MathUtils { public static boolean isCoordinate( String value ) { if( value == null ) { return false; } value = value.replaceAll( "\\s+", "" ); if ( value.length() < 5 || value.indexOf( "[" ) != 0 || value.indexOf( "]" ) != value.length() - 1 ) { return false; } try { String[] lnglat = value.substring( 1, value.length() - 1 ).split( "," ); float lng = Float.parseFloat( lnglat[0] ); float lat = Float.parseFloat( lnglat[1] ); return (lng >= -180 && lng <= 180 && lat >= -90 && lat <= 90); } catch ( Exception x ) { return false; } }  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 testIsCoordinate() { assertTrue( MathUtils.isCoordinate( "[0.0,0.0]" ) ); assertTrue( MathUtils.isCoordinate( "[18, 65]" ) ); assertTrue( MathUtils.isCoordinate( "[18.56, 65.342]" ) ); assertTrue( MathUtils.isCoordinate( "[18.56,65.342]" ) ); assertTrue( MathUtils.isCoordinate( "[-18.56,-65.342]" ) ); assertTrue( MathUtils.isCoordinate( " [18.56 , 65.342 ] " ) ); assertTrue( MathUtils.isCoordinate( " [ -180 , -90] " ) ); assertTrue( MathUtils.isCoordinate( " [ 12.30 , 45.67 ] " ) ); assertFalse( MathUtils.isCoordinate( "" ) ); assertFalse( MathUtils.isCoordinate( null ) ); assertFalse( MathUtils.isCoordinate( "18.56a, 65.342b" ) ); assertFalse( MathUtils.isCoordinate( "0" ) ); assertFalse( MathUtils.isCoordinate( "-0" ) ); assertFalse( MathUtils.isCoordinate( "Hey" ) ); assertFalse( MathUtils.isCoordinate( " 1" ) ); assertFalse( MathUtils.isCoordinate( "1 " ) ); assertFalse( MathUtils.isCoordinate( "1.2345,123, 123" ) ); assertFalse( MathUtils.isCoordinate( "12147483647" ) ); assertFalse( MathUtils.isCoordinate( "-181 ,-90" ) ); assertFalse( MathUtils.isCoordinate( "-180 , 91" ) ); assertFalse( MathUtils.isCoordinate( "12,34" ) ); assertFalse( MathUtils.isCoordinate( "[,]" ) ); assertFalse( MathUtils.isCoordinate( "[12, ]" ) ); }