/** * Get current value as double. * * @return double value * @throws NumberFormatException when current value cannot be parsed as double * value. */ public double getDouble() throws NumberFormatException { return FormatUtil.parseDouble(input, start, end); }
/** * Parse a double from a character sequence. * * In contrast to Javas {@link Double#parseDouble}, this will <em>not</em> * create an object and thus is expected to put less load on the garbage * collector. It will accept some more spellings of NaN and infinity, thus * removing the need for checking for these independently. * * @param str String * @return Double value */ public static double parseDouble(final CharSequence str) { return parseDouble(str, 0, str.length()); }
@Override public double getTextSize(String key) { Double lw = getCached(key, TEXT_SIZE, Double.class); if (lw == null) { try { lw = Double.valueOf(FormatUtil.parseDouble(getPropertyValue(key, TEXT_SIZE)) * SCALE); } catch (NullPointerException e) { throw new AbortException("Missing/invalid value in style library: " + key + '.' + TEXT_SIZE); } } return lw.doubleValue(); }
@Override protected double[] parseValue(Object obj) throws ParameterException { if(obj instanceof double[]) { return double[].class.cast(obj); } if(obj instanceof String) { String[] values = SPLIT.split((String) obj); double[] doubleValue = new double[values.length]; for(int i = 0; i < values.length; i++) { doubleValue[i++] = FormatUtil.parseDouble(values[i]); } return doubleValue; } if(obj instanceof Double) { return new double[] { (Double) obj }; } throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of Double values!"); }
@Override public double getSize(String key) { Double lw = getCached(key, GENERIC_SIZE, Double.class); if (lw == null) { try { lw = Double.valueOf(FormatUtil.parseDouble(getPropertyValue(key, GENERIC_SIZE)) * SCALE); } catch (NullPointerException e) { throw new AbortException("Missing/invalid value in style library: " + key + '.' + GENERIC_SIZE); } } return lw.doubleValue(); }
@Override public double getOpacity(String key) { Double lw = getCached(key, OPACITY, Double.class); if (lw == null) { try { lw = Double.valueOf(FormatUtil.parseDouble(getPropertyValue(key, OPACITY))); } catch (NullPointerException e) { throw new AbortException("Missing/invalid value in style library: " + key + '.' + OPACITY); } } return lw.doubleValue(); }
@Override public double getLineWidth(String key) { Double lw = getCached(key, LINE_WIDTH, Double.class); if (lw == null) { try { lw = Double.valueOf(FormatUtil.parseDouble(getPropertyValue(key, LINE_WIDTH)) * SCALE); } catch (NullPointerException e) { throw new AbortException("Missing/invalid value in style library: " + key + '.' + LINE_WIDTH); } } return lw.doubleValue(); }
/** * Parse a string into a vector. * * TODO: move this into utility package? * * @param s String to parse * @return Vector * @throws UnableToComplyException */ private Vector parseVector(String s) throws UnableToComplyException { String[] entries = WHITESPACE_PATTERN.split(s); double[] d = new double[entries.length]; for(int i = 0; i < entries.length; i++) { try { d[i] = FormatUtil.parseDouble(entries[i]); } catch(NumberFormatException e) { throw new UnableToComplyException("Could not parse vector."); } } return new Vector(d); }
min = FormatUtil.parseDouble(minstr); max = FormatUtil.parseDouble(maxstr);
@Override protected Double parseValue(Object obj) throws WrongParameterValueException { if(obj instanceof Double) { return (Double) obj; } try { return FormatUtil.parseDouble(obj.toString()); } catch(NullPointerException e) { throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a double value, read: " + obj + "!\n"); } catch(NumberFormatException e) { throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a double value, read: " + obj + "!\n"); } }
String meanstr = ((Element) cur).getAttribute(ATTR_MEAN); if(meanstr != null && meanstr.length() > 0) { mean = FormatUtil.parseDouble(meanstr); stddev = FormatUtil.parseDouble(stddevstr);
@Override protected List<double[]> parseValue(Object obj) throws ParameterException { if(obj instanceof String) { String[] vectors = VECTOR_SPLIT.split((String) obj); if(vectors.length == 0) { throw new WrongParameterValueException("Wrong parameter format! Given list of vectors for parameter \"" + getName() + "\" is empty!"); } ArrayList<double[]> vecs = new ArrayList<>(); double[] buf = new double[11]; int used = 0; for(String vector : vectors) { used = 0; String[] coordinates = SPLIT.split(vector); for(String coordinate : coordinates) { try { if(used == buf.length) { buf = Arrays.copyOf(buf, buf.length << 1); } buf[used++] = FormatUtil.parseDouble(coordinate); } catch(NumberFormatException e) { throw new WrongParameterValueException("Wrong parameter format! Coordinates of vector \"" + vector + "\" are not valid!"); } } vecs.add(Arrays.copyOf(buf, used)); } return vecs; } throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of double values!"); }
min = FormatUtil.parseDouble(minstr); max = FormatUtil.parseDouble(maxstr);
String kstr = ((Element) cur).getAttribute(ATTR_K); if(kstr != null && kstr.length() > 0) { k = FormatUtil.parseDouble(kstr); theta = FormatUtil.parseDouble(thetastr);
v.add(FormatUtil.parseDouble(tokenizer.sval)); // Read & store 1st throw new java.io.IOException("Row " + v.size() + " is too long."); row[j++] = FormatUtil.parseDouble(tokenizer.sval);
overweight = FormatUtil.parseDouble(dcostr);
angle = FormatUtil.parseDouble(anstr);
if(m.find()) { try { double c1 = FormatUtil.parseDouble(m.group(1)); double c2 = FormatUtil.parseDouble(m.group(2)); if(m.group(3) != null) { double c3 = FormatUtil.parseDouble(m.group(3)); coords.add(new Vector(new double[] { c1, c2, c3 }));
Element c = checkbox.renderCheckBox(svgp, 1., 5. + FormatUtil.parseDouble(clrInfo.getAttribute(SVGConstants.SVG_HEIGHT_ATTRIBUTE)), 11); ctrlLayer.appendChild(clrInfo); ctrlLayer.appendChild(c);
cur[k] = FormatUtil.parseDouble(tokenizer.sval);