List of usage examples for java.lang Double parseDouble
public static double parseDouble(String s) throws NumberFormatException
From source file:web.Validator.RechercheValidator.java
@Override public void validate(Object o, Errors errors) { CommandSearch command = (CommandSearch) o; SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); if (!command.getDateNaissance().isEmpty()) { try {/*from w w w . j a v a2s . co 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"); } } }
From source file:org.ext4spring.parameter.converter.simple.DoubleConverter.java
@Override public <T> T toTypedValue(String stringValue, Class<T> type) { return (stringValue != null) ? type.cast(Double.parseDouble(stringValue)) : null; }
From source file:org.esxx.js.protocol.PreemptiveSchemes.java
public PreemptiveSchemes() { Properties p = ESXX.getInstance().getSettings(); maxEntries = Integer.parseInt(p.getProperty("esxx.cache.preemptive-http.max_entries", "32")); maxAge = (long) (Double.parseDouble(p.getProperty("esxx.cache.preemptive-http.max_age", "3600")) * 1000); }
From source file:com.whizzosoftware.hobson.json.TypedPropertyValueSerializer.java
static public Object createValueObject(TypedProperty.Type type, Object jsonValue, PropertyContextProvider cp) { switch (type) { case BOOLEAN: if (jsonValue instanceof Boolean) { return jsonValue; } else if (jsonValue instanceof String) { if ("true".equalsIgnoreCase((String) jsonValue) || "false".equalsIgnoreCase((String) jsonValue)) { return Boolean.parseBoolean((String) jsonValue); } else { throw new HobsonInvalidRequestException( "Boolean property is not a JSON string with \"true\" or \"false\":" + jsonValue); }/*w ww .j a va 2 s . c om*/ } else { throw new HobsonInvalidRequestException( "Boolean property is not a valid JSON boolean: " + jsonValue); } case NUMBER: if (jsonValue instanceof Double || jsonValue instanceof Integer) { return jsonValue; } else if (jsonValue instanceof String) { try { return Double.parseDouble((String) jsonValue); } catch (NumberFormatException e) { throw new HobsonInvalidRequestException("Number property is not a valid number: " + jsonValue); } } else { throw new HobsonInvalidRequestException("Number property is not a valid JSON number: " + jsonValue); } case STRING: if (jsonValue instanceof String) { return jsonValue; } else if (jsonValue instanceof Integer || jsonValue instanceof Double || jsonValue instanceof Boolean) { return jsonValue.toString(); } else if (JSONObject.NULL.equals(jsonValue)) { return null; } else { throw new HobsonInvalidRequestException("String property is not a valid JSON string: " + jsonValue); } case DEVICE: if (jsonValue instanceof JSONObject) { return createDeviceValueObject((JSONObject) jsonValue, cp); } else { throw new HobsonInvalidRequestException("Device property is not a JSON object: " + jsonValue); } case DEVICES: if (jsonValue instanceof JSONArray) { return createDevicesValueObject((JSONArray) jsonValue, cp); } else { throw new HobsonInvalidRequestException("Devices property is not a JSON array: " + jsonValue); } case PRESENCE_ENTITY: if (jsonValue instanceof JSONObject) { JSONObject json = (JSONObject) jsonValue; return cp.createPresenceEntityContext(json.getString(JSONAttributes.AID)); } else { throw new HobsonInvalidRequestException( "Presence entity property is not a JSON object: " + jsonValue); } case LOCATION: if (jsonValue instanceof JSONObject) { JSONObject json = (JSONObject) jsonValue; return cp.createPresenceLocationContext(json.getString(JSONAttributes.AID)); } else { throw new HobsonInvalidRequestException( "Presence location property is not a JSON object: " + jsonValue); } default: return jsonValue.toString(); } }
From source file:com.anhth12.lambda.ml.param.HyperParams.java
public static HyperParamValues<?> fromConfig(Config config, String key) { switch (config.getValue(key).valueType()) { case LIST:/*from w w w .j a v a2s. co m*/ List<String> stringValues = config.getStringList(key); try { return range(Integer.parseInt(stringValues.get(0)), Integer.parseInt(stringValues.get(1))); } catch (NumberFormatException nfe) { // continue } try { return range(Double.parseDouble(stringValues.get(0)), Double.parseDouble(stringValues.get(1))); } catch (NumberFormatException nfe) { // continue } return unorderedFromValues(stringValues); case STRING: case NUMBER: String stringValue = config.getString(key); try { return fixed(Integer.parseInt(stringValue)); } catch (NumberFormatException nfe) { } try { return fixed(Double.parseDouble(stringValue)); } catch (NumberFormatException nfe) { // continue } return unorderedFromValues(Collections.singletonList(stringValue)); default: throw new AssertionError(config.getValue(key).valueType().name()); } }
From source file:gedi.util.math.stat.kernel.GaussianKernel.java
public void setParameter(String name, String value) { if (name.equals("sd")) setSd(Double.parseDouble(value)); throw new IllegalArgumentException("Parameter " + name + " unknown!"); }
From source file:edu.msu.cme.rdp.framebot.stat.TaxonAbundance.java
public static HashMap<String, Double> parseKmerCoverage(String infile) throws IOException { HashMap<String, Double> countMap = new HashMap<String, Double>(); BufferedReader reader = new BufferedReader(new FileReader(new File(infile))); String line;/*from w w w . j a v a2 s.c om*/ while ((line = reader.readLine()) != null) { if (line.startsWith("#")) continue; String[] val = line.split("\\s+"); countMap.put(val[0], Double.parseDouble(val[1])); } reader.close(); return countMap; }
From source file:com.karki.spring.dao.impl.FacilitiesDaoImpl.java
@Override public void loadData(String path) throws IOException, ClassNotFoundException, SQLException { Facilities fa = new Facilities(); String line = ""; BufferedReader reader = new BufferedReader(new FileReader(new File(path))); while ((line = reader.readLine()) != null) { StringTokenizer tokenizer = new StringTokenizer(line, ","); fa.setFacilityId(Integer.parseInt(tokenizer.nextToken())); fa.setName(tokenizer.nextToken()); fa.setFee(Double.parseDouble(tokenizer.nextToken())); insert(fa);/*w ww.j a v a 2 s . c o m*/ } reader.close(); }
From source file:oct.util.Util.java
public static double parseNumberFromInput(String in) { if (in.matches("[0-9]+(\\.[0-9]+)*")) { return Double.parseDouble(in); } else {// w w w. j av a 2s . c o m return -1; } }
From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java
public static void readData(String inFile, File outdir, String xAxisLabel, String yAxisLabel) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); DefaultBoxAndWhiskerCategoryDataset scatterDataset = new DefaultBoxAndWhiskerCategoryDataset(); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = reader.readLine(); while ((line = reader.readLine()) != null) { String[] values = line.split("\\t"); XYSeries series = new XYSeries(values[2]); dataset.addSeries(series);/* w w w . j a v a 2 s .co m*/ double average = Double.parseDouble(values[4]); int Q1 = Integer.parseInt(values[6]); ; int median = Integer.parseInt(values[7]); int Q3 = Integer.parseInt(values[8]); int pct_98 = Integer.parseInt(values[9]); int pct_2 = Integer.parseInt(values[10]); int minOutlier = 0; // we don't care about the outliers int maxOutlier = 0; // BoxAndWhiskerItem item = new BoxAndWhiskerItem(average, median, Q1, Q3, pct_2, pct_98, minOutlier, maxOutlier, new ArrayList()); scatterDataset.add(item, values[2], ""); } String title = new File(inFile).getName(); int index = title.indexOf("."); if (index != -1) { title = title.substring(0, index); } Font lableFont = new Font("Helvetica", Font.BOLD, 28); createBoxplot(scatterDataset, new PrintStream(new File(outdir, title + ".boxchart.png")), title, xAxisLabel, yAxisLabel, lableFont); }