List of usage examples for java.lang Double parseDouble
public static double parseDouble(String s) throws NumberFormatException
From source file:web.Validator.CreationUtilisateurValidator.java
@Override public void validate(Object o, Errors errors) { CommandAddUser command = (CommandAddUser) o; SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); if (!command.getDateNaissance().isEmpty()) { try {/*from w ww . j a v a 2s. c o m*/ Date parse = myFormatter.parse(command.getDateNaissance()); } catch (Exception e) { errors.rejectValue("dateNaissance", "Erreur forme date", "Date format must be yyyy-mm-dd"); } } if (!command.getTelephone().isEmpty()) { try { Double d = Double.parseDouble(command.getTelephone()); if (command.getTelephone().length() != 8) errors.rejectValue("telephone", "Erreur log tel", "Tel must be 8 digits long"); } catch (Exception e) { errors.rejectValue("telephone", "Erreur format tel", "Tel must contain only numbers AND 8 digits long"); } } if (!command.getCin().isEmpty()) { try { int i = Integer.parseInt(command.getCin()); if (command.getCin().length() != 8) errors.rejectValue("cin", "Erreur format cin", "CIN must contain 8 digits"); } catch (Exception e) { errors.rejectValue("cin", "Erreur format cin", "CIN must contain only digits"); } } if (command.getLogin().isEmpty()) { errors.rejectValue("login", "Erreur login", "Must be filled"); } if (command.getPass().isEmpty()) { errors.rejectValue("pass", "Erreur login", "Must be filled"); } if (!(command.getRole().equals("ADMIN") || command.getRole().equals("USER"))) { errors.rejectValue("role", "Erreur role", "Role must be ADMIN or USER"); } }
From source file:com.swcguild.springmvcwebapp.controller.FlooringController.java
@RequestMapping(value = "/flooring", method = RequestMethod.POST) public String doPost(HttpServletRequest request, Model model) { try {//from w ww .j a v a2 s . co m width = Double.parseDouble(request.getParameter("myWidth")); length = Double.parseDouble(request.getParameter("myLength")); myCost = request.getParameter("myCost"); cost = Double.parseDouble(myCost); area = width * length; totalMatCost = area * cost; totalLabor = laborCost(area); quote = totalLabor + totalMatCost; DecimalFormat df = new DecimalFormat("#.00"); model.addAttribute("area", df.format(area)); model.addAttribute("totalMatCost", df.format(totalMatCost)); model.addAttribute("totalLabor", df.format(totalLabor)); model.addAttribute("quote", df.format(quote)); } catch (NumberFormatException e) { } return "flooringResponse"; }
From source file:com.dtstack.jlogstash.assembly.CmdLineParams.java
public static double getOutputQueueCoefficient() { String number = line.getOptionValue("i"); double coefficient = StringUtils.isNotBlank(number) ? Double.parseDouble(number) : SystemProperty.getOutputProportion(); logger.warn("output queue coefficient:{}", String.valueOf(coefficient)); return coefficient; }
From source file:Main.java
/** * Read a double[] object from an XmlPullParser. The XML data could * previously have been generated by writeDoubleArrayXml(). The XmlPullParser * must be positioned <em>after</em> the tag that begins the list. * * @param parser The XmlPullParser from which to read the list data. * @param endTag Name of the tag that will end the list, usually "double-array". * @param name An array of one string, used to return the name attribute * of the list's tag./*from w w w.ja va 2 s .c o m*/ * @return Returns a newly generated double[]. * @see #readListXml */ public static double[] readThisDoubleArrayXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, java.io.IOException { int num; try { num = Integer.parseInt(parser.getAttributeValue(null, "num")); } catch (NullPointerException e) { throw new XmlPullParserException("Need num attribute in double-array"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in num attribute in double-array"); } parser.next(); double[] array = new double[num]; int i = 0; int eventType = parser.getEventType(); do { if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("item")) { try { array[i] = Double.parseDouble(parser.getAttributeValue(null, "value")); } catch (NullPointerException e) { throw new XmlPullParserException("Need value attribute in item"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in value attribute in item"); } } else { throw new XmlPullParserException("Expected item tag at: " + parser.getName()); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(endTag)) { return array; } else if (parser.getName().equals("item")) { i++; } else { throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName()); } } eventType = parser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); throw new XmlPullParserException("Document ended before " + endTag + " end tag"); }
From source file:org.envirocar.analyse.util.Utils.java
public static double[] convertWKTPointToXY(String wktPointAsString) { double[] result = new double[2]; wktPointAsString = wktPointAsString.replace("POINT(", ""); wktPointAsString = wktPointAsString.replace(")", ""); String[] xyAsStringArray = wktPointAsString.split(" "); result[0] = Double.parseDouble(xyAsStringArray[0].trim()); result[1] = Double.parseDouble(xyAsStringArray[1].trim()); return result; }
From source file:br.ime.usp.aztec.aztdis.AZTDISCommandLineParametersParser.java
@Override protected AZTDISParameters buildParameters(CommandLine options) throws IllegalArgumentException { if (options.hasOption('t') && options.hasOption('e')) { double threshold = Double.parseDouble(options.getOptionValue('t')); double displacement = Double.parseDouble(options.getOptionValue('e')); double minimumDistance = Double .parseDouble(options.getOptionValue('k', Double.toString(AZTDISParameters.DEFAULT_K))); return new AZTDISParameters.Builder().withThreshold(threshold).withMaximumDisplacement(displacement) .withMinimumDistanceBetweenEvents(minimumDistance) .withInput(new SignalParser(this.openInputGivenIn(options))) .withOutput(new WriterEncodingOutput(this.openOutputGivenIn(options))).build(); }//from w w w . j a v a2 s. c o m throw new IllegalArgumentException("Mandatory argument not given." + " -t and -e are mandatory."); }
From source file:org.opendatakit.common.android.utilities.KeyValueStoreUtils.java
public static Double getNumber(String appName, KeyValueStoreEntry entry) throws IllegalArgumentException { if (entry == null) { return null; }//from w ww . j a v a 2s .com if (!entry.type.equals(ElementDataType.number.name())) { throw new IllegalArgumentException("requested number entry for " + "key: " + entry.key + ", but the corresponding entry in the store was " + "not of type: " + ElementDataType.number.name()); } try { return Double.parseDouble(entry.value); } catch (NumberFormatException e) { throw new IllegalArgumentException( "requested int entry for " + "key: " + entry.key + ", but the value in the store failed to " + "parse to type: " + ElementDataType.number.name()); } }
From source file:com.biz.report.domain.MappingEngine.java
public List<Report1> getList(List list) { if (list != null) { for (Object o : list) { Object[] obj = (Object[]) o; Report1 r = new Report1(); if (obj[0] != null && !obj[0].equals("")) { r.setMonthName(getMonthName(obj[0].toString().trim())); }/*w ww . j a va 2 s. co m*/ if (obj[1] != null) { r.setTypeName(obj[1].toString().trim()); } if (obj[2] != null) { r.setSellingPrice(Double.parseDouble(obj[2].toString().trim())); } logger.info(o); logger.info(r); report.add(r); } } return report; }
From source file:com.glaf.core.util.converter.DoubleConverter.java
public Object convert(Class type, Object value) { if (value == null) { return null; }//from w w w .ja v a 2 s . co m if (value instanceof String) { String tmp = (String) value; if (tmp.trim().length() == 0) { return null; } else { return Double.parseDouble(tmp); } } return null; }
From source file:Main.java
/** * Read a double[] object from an XmlPullParser. The XML data could * previously have been generated by writeDoubleArrayXml(). The XmlPullParser * must be positioned <em>after</em> the tag that begins the list. * * @param parser The XmlPullParser from which to read the list data. * @param endTag Name of the tag that will end the list, usually "double-array". * @param name An array of one string, used to return the name attribute * of the list's tag./*from w w w . j av a 2 s .c om*/ * @return Returns a newly generated double[]. * @see #readListXml */ public static final double[] readThisDoubleArrayXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, IOException { int num; try { num = Integer.parseInt(parser.getAttributeValue(null, "num")); } catch (NullPointerException e) { throw new XmlPullParserException("Need num attribute in double-array"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in num attribute in double-array"); } parser.next(); double[] array = new double[num]; int i = 0; int eventType = parser.getEventType(); do { if (eventType == parser.START_TAG) { if (parser.getName().equals("item")) { try { array[i] = Double.parseDouble(parser.getAttributeValue(null, "value")); } catch (NullPointerException e) { throw new XmlPullParserException("Need value attribute in item"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in value attribute in item"); } } else { throw new XmlPullParserException("Expected item tag at: " + parser.getName()); } } else if (eventType == parser.END_TAG) { if (parser.getName().equals(endTag)) { return array; } else if (parser.getName().equals("item")) { i++; } else { throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName()); } } eventType = parser.next(); } while (eventType != parser.END_DOCUMENT); throw new XmlPullParserException("Document ended before " + endTag + " end tag"); }