Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 2929:0ef4753e5515
Improved manual wsp input validation.
flys-client/trunk@4830 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 28 Jun 2012 15:44:10 +0000 |
parents | 4f4d29404dba |
children | a30d77d86386 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java Thu Jun 28 15:33:08 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java Thu Jun 28 15:44:10 2012 +0000 @@ -17,6 +17,32 @@ /** The interface that provides i18n messages. */ protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** Statically determine doubility of String value. */ + public static boolean isDouble(Object obj) { + if (obj == null) { + return false; + } + + boolean valid = true; + String v = obj.toString(); + + NumberFormat f = NumberFormat.getDecimalFormat(); + + try { + if (v == null) { + throw new NumberFormatException("empty"); + } + + double value = f.parse(v); + } + catch (NumberFormatException nfe) { + valid = false; + } + return valid; + + } + /** * */