List of usage examples for java.lang NumberFormatException NumberFormatException
public NumberFormatException(String s)
NumberFormatException
with the specified detail message. From source file:com.tamnd.core.util.ZConfig.java
public boolean getBoolean(String key) throws NotExistException, InvalidParamException { String strVal = _getProperty(key); if (strVal.equalsIgnoreCase("true")) { return true; } else if (strVal.equalsIgnoreCase("false")) { return false; } else if (strVal.equalsIgnoreCase("yes")) { return true; } else if (strVal.equalsIgnoreCase("no")) { return false; } else if (strVal.equalsIgnoreCase("on")) { return true; } else if (strVal.equalsIgnoreCase("off")) { return false; } else if (strVal.equalsIgnoreCase("1")) { return true; } else if (strVal.equalsIgnoreCase("0")) { return false; } else {//from w w w .ja v a 2 s .c o m throw new NumberFormatException("Wrong format while parsing boolean"); } }
From source file:com.opengamma.web.json.FudgeMsgJSONReader.java
private long longValue(final Object o) { if (o instanceof Number) { return ((Number) o).longValue(); } else if (o instanceof String) { return Long.parseLong((String) o); } else {/*w w w . ja v a 2 s .co m*/ throw new NumberFormatException(o + " is not a number"); } }
From source file:org.deegree.tools.rendering.manager.ModelGeneralizor.java
/** * @param optionValue/*from ww w . j av a 2 s.co m*/ * @return */ private static double[] createTranslationVector(String optionValue, int size) { double[] result = new double[size]; if (optionValue != null && !"".equals(optionValue)) { try { result = ArrayUtils.splitAsDoubles(optionValue, ","); if (result.length != size) { throw new NumberFormatException( "Illigal number of values, only two dimensional translations are allowed"); } } catch (NumberFormatException e) { System.err.println("Translation vector " + optionValue + " could not be read, please make sure it is a comma seperated list of (floating point) numbers: " + e.getLocalizedMessage()); } } return result; }
From source file:com.wordpress.growworkinghard.riverNe3.composite.key.Key.java
/** * @brief <strong>Precondition</strong> to validate input hexadecimal string * * @param hexKey//from w w w .jav a 2s .c o m * The input hexadecimal string * @exception NumberFormatException * if the input string contains characters that are not * hexadecimal symbols */ private void validateStringKey(final String hexKey) { final String DIGITS = "0123456789ABCDEF"; final String HEXKEY = hexKey.toUpperCase(); for (int i = 0; i < HEXKEY.length(); i++) { char c = HEXKEY.charAt(i); int d = DIGITS.indexOf(c); if (d < 0) { String message = "String '" + hexKey; message += "' cannot be converted in"; message += "hexadecimal format.\n"; message += c + " is not an hex symbol"; throw new NumberFormatException(message); } } }
From source file:com.opengamma.web.json.FudgeMsgJSONReader.java
private double doubleValue(final Object o) { if (o instanceof Number) { return ((Number) o).doubleValue(); } else if (o instanceof String) { return Double.parseDouble((String) o); } else {// w ww . j a va2 s . c om throw new NumberFormatException(o + " is not a number"); } }
From source file:com.controlj.green.bulktrend.trendserver.SearchServlet.java
private int getIntParameter(HttpServletRequest req, String paramName) throws NumberFormatException { String parValue = req.getParameter(paramName); if (parValue != null) { return Integer.parseInt(parValue); }/*w w w . ja v a2 s . com*/ throw new NumberFormatException("Number String is null"); }
From source file:com.opengamma.web.json.FudgeMsgJSONReader.java
private float floatValue(final Object o) { if (o instanceof Number) { return ((Number) o).floatValue(); } else if (o instanceof String) { return Float.parseFloat((String) o); } else {/*from w ww .ja v a 2 s . com*/ throw new NumberFormatException(o + " is not a number"); } }
From source file:org.devdom.commons.Feriados.java
/** * Obtener objeto Feriado segn la posicin solicitada * /*from w ww . ja v a 2s . c om*/ * @param id posicin de da feriado * @return Objeto Feriado * @see Feriado * @throws RequesterInformationException si hubo error en la recepcin de informacin * @throws ParseException si hubo error de parseo * @throws NumberFormatException si hubo un intento de pasar caracteres por valores numricos */ @Override public Feriado get(String id) throws RequesterInformationException, ParseException, NumberFormatException { if (!Utils.hasOnlyDigits(id)) { throw new NumberFormatException("Solo se permiten dgitos"); } return get(Integer.parseInt(id)); }
From source file:mil.jpeojtrs.sca.util.AnyUtils.java
/** * @since 3.0//from w ww . j a v a2 s .c om * @throws NumberFormatException */ public static BigInteger bigIntegerDecode(final String nm) { int radix = AnyUtils.RADIX_DECIMAL; int index = 0; boolean negative = false; BigInteger result; // Handle minus sign, if present if (nm.startsWith("-")) { negative = true; index++; } // Handle radix specifier, if present if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) { index += 2; radix = AnyUtils.RADIX_HEX; } else if (nm.startsWith("#", index)) { index++; radix = AnyUtils.RADIX_HEX; } else if (nm.startsWith("0", index) && nm.length() > 1 + index) { index++; radix = AnyUtils.RADIX_OCTAL; } if (nm.startsWith("-", index)) { throw new NumberFormatException("Negative sign in wrong position"); } try { result = new BigInteger(nm.substring(index), radix); if (negative) { result = result.negate(); } } catch (final NumberFormatException e) { // If number is Long.MIN_VALUE, we'll end up here. The next line // handles this case, and causes any genuine format error to be // rethrown. final String constant; if (negative) { constant = "-" + nm.substring(index); } else { constant = nm.substring(index); } result = new BigInteger(constant, radix); } return result; }
From source file:op.tools.SYSCalendar.java
/** * Expiry dates usually have a form like "12-10" oder "12/10" to indicate that the product in question is * best before December 31st, 2010. This method parses dates like this. * If it fails it hands over the parsing efforts to <code>public static Date parseDate(String input)</code>. * * @param input a string to be parsed. It can handle the following formats "mm/yy", "mm/yyyy" (it also recognizes these kinds of * dates if the slash is replaced with one of the following chars: "-,.". * @return the parsed date which is always the last day and the last second of that month. * @throws NumberFormatException//from w w w . j a v a 2 s. c o m */ public static DateTime parseExpiryDate(String input) throws NumberFormatException { if (input == null || input.isEmpty()) { throw new NumberFormatException("empty"); } input = input.trim(); if (input.indexOf(".") + input.indexOf(",") + input.indexOf("-") + input.indexOf("/") == -4) { input += "."; } StringTokenizer st = new StringTokenizer(input, "/,.-"); if (st.countTokens() == 1) { // only one number, then this must be the month. we add the current year. input = "1." + input + SYSCalendar.today().get(GregorianCalendar.YEAR); } if (st.countTokens() == 2) { // complete expiry date. we fill up some dummy day. input = "1." + input; //st = new StringTokenizer(input, "/,.-"); // split again... } DateTime expiry = new DateTime(parseDate(input)); // when the user has entered a complete date, then we return that date // if he has omitted some parts of it, we consider it always the last day of that month. return st.countTokens() == 3 ? expiry : expiry.dayOfMonth().withMaximumValue().secondOfDay().withMaximumValue(); }