List of usage examples for java.lang Double Double
@Deprecated(since = "9") public Double(String s) throws NumberFormatException
From source file:com.discursive.jccook.collections.typed.TypedMapExample.java
public void start() { // Make sure that items added to this variables = TypedMap.decorate(new HashMap(), String.class, Number.class); // Add two String objects variables.put("maxThreads", new Integer(200)); variables.put("minThreads", new Integer(20)); variables.put("lightSpeed", new Double(2.99792458e8)); // Try to add a String value try {/*from w ww .j a va 2 s . co m*/ variables.put("server", "test.oreilly.com"); } catch (IllegalArgumentException iae) { System.out.println("Adding an String value Failed as expected"); } // Try to add an Integer key try { variables.put(new Integer(30), "test.oreilly.com"); } catch (IllegalArgumentException iae) { System.out.println("Adding an Integer key Failed as expected"); } // Now we can safely cast without the possibility of a ClassCastException Number reading = (Number) variables.get("lightSpeed"); }
From source file:org.openmrs.module.sync.SyncUtilTest.java
@Test public void getSetterMethod_shouldReturnMethodForPrimitiveDouble() { Method m = SyncUtil.getSetterMethod(new Xform().getClass(), "doubleField", new Double(1).getClass()); Assert.notNull(m);// w ww .java 2 s . c o m }
From source file:cv.mikusher.freechart.TimeSeries_AWT.java
private XYDataset createDataset() { final TimeSeries series = new TimeSeries("Random Data"); Second current = new Second(); double value = 100.0; for (int i = 0; i < 4000; i++) { try {//from w ww .j a v a 2 s.c o m value = value + Math.random() - 0.5; series.add(current, new Double(value)); current = (Second) current.next(); } catch (SeriesException e) { System.err.println("Error adding to series"); } } return new TimeSeriesCollection(series); }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateCompareTwoFields.java
/** * Compares the two fields using the given comparator * /*from w ww .j a v a 2 s .co m*/ * @param bean * @param va * @param field * @param errors * @param request * @param comparator * @return */ private static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, Comparator comparator) { String greaterInputString = ValidatorUtils.getValueAsString(bean, field.getProperty()); String secondProperty = field.getVarValue("secondProperty"); String lowerInputString = ValidatorUtils.getValueAsString(bean, secondProperty); if (!GenericValidator.isBlankOrNull(lowerInputString) && !GenericValidator.isBlankOrNull(greaterInputString)) { try { Double lowerInput = new Double(lowerInputString); Double greaterInput = new Double(greaterInputString); // if comparator result != VALUE then the condition is false if (comparator.compare(lowerInput, greaterInput) != VALUE) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } return true; } catch (NumberFormatException e) { errors.add(field.getKey(), new ActionMessage(va.getMsg())); return false; } } return true; }
From source file:net.fenyo.mail4hotspot.web.GMailOAuthStep1Servlet.java
private String nonce() { return new Integer(new Double(Math.random() * 100000000).intValue()).toString(); }
From source file:knop.psfj.utils.MathUtils.java
/** * Round to string./*w ww . java 2 s .c om*/ * * @param nb2round the nb2round * @param nbOfDigits the nb of digits * @return the string */ public static String roundToString(double nb2round, int nbOfDigits) { if (nbOfDigits == 0) return "" + Math.round(nb2round); return new Double(round(nb2round, nbOfDigits)).toString(); }
From source file:gda.plots.SimpleXYToolTipGenerator.java
/** * Generates a tool tip text item for a particular item within a series. * //from w ww .j ava 2 s .co m * @param data * the dataset. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @return the tool tip text. */ @Override public String generateToolTip(XYDataset data, int series, int item) { String result = data.getSeriesKey(series) + ", item " + item; Number x = new Double(data.getXValue(series, item)); result = result + " x: " + getXFormat().format(x); Number y = new Double(data.getYValue(series, item)); result = result + ", y: " + getYFormat().format(y); return result; }
From source file:Main.java
public static double getJavaVersion() { if (javaVersion == null) { try {//from w ww . j ava 2s . co m String ver = System.getProperties().getProperty("java.version"); String version = ""; boolean firstPoint = true; for (int i = 0; i < ver.length(); i++) { if (ver.charAt(i) == '.') { if (firstPoint) { version += ver.charAt(i); } firstPoint = false; } else if (Character.isDigit(ver.charAt(i))) { version += ver.charAt(i); } } javaVersion = new Double(version); } catch (Exception ex) { javaVersion = new Double(1.3); } } return javaVersion.doubleValue(); }
From source file:example.table.TableButton3.java
public TableButton3() { String[] columnNames = { "Date", "String", "Integer", "Decimal", "" }; Object[][] data = { { new Date(), "A", new Integer(1), new Double(5.1), "Delete0" }, { new Date(), "B", new Integer(2), new Double(6.2), "Delete1" }, { new Date(), "C", new Integer(3), new Double(7.3), "Delete2" }, { new Date(), "D", new Integer(4), new Double(8.4), "Delete3" } }; DefaultTableModel model = new DefaultTableModel(data, columnNames); JTable table = new JTable(model) { private static final long serialVersionUID = 1L; // Returning the Class of each column will allow different // renderers to be used based on Class public Class<?> getColumnClass(int column) { return getValueAt(0, column).getClass(); }/*w w w. j a v a2 s . c o m*/ }; JScrollPane scrollPane = new JScrollPane(table); getContentPane().add(scrollPane); // Create button column ButtonColumn buttonColumn = new ButtonColumn(table, 4); log.debug("buttonColumn = " + buttonColumn); }
From source file:Main.java
/** * Normalize decimal string/*w w w . ja v a2s . c o m*/ * exclude the Expo * @param numericStr * @param isDecimal * @param digits * @return */ public static String normalizeNumericString(String numericStr, boolean isDecimal, int digits) { if (isDecimal) { digits += 1; Double d = new Double(numericStr); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMinimumFractionDigits(7); numericStr = nf.format(d); int dotIndex = numericStr.indexOf("."); if (numericStr.length() <= (dotIndex + digits)) return numericStr; String result = numericStr.substring(0, dotIndex + digits); result = result.replace(",", ""); return result; } throw new RuntimeException(); }