List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:Main.java
private static final Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName) throws XmlPullParserException, java.io.IOException { try {/* w w w. j a v a 2 s. co m*/ if (tagName.equals("int")) { return Integer.parseInt(parser.getAttributeValue(null, "value")); } else if (tagName.equals("long")) { return Long.valueOf(parser.getAttributeValue(null, "value")); } else if (tagName.equals("float")) { return new Float(parser.getAttributeValue(null, "value")); } else if (tagName.equals("double")) { return new Double(parser.getAttributeValue(null, "value")); } else if (tagName.equals("boolean")) { return Boolean.valueOf(parser.getAttributeValue(null, "value")); } else { return null; } } catch (NullPointerException e) { throw new XmlPullParserException("Need value attribute in <" + tagName + ">"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in value attribute in <" + tagName + ">"); } }
From source file:Main.java
public static Object getPropertyValue(Element element) { NamedNodeMap map = element.getAttributes(); map.removeNamedItem(NAME_ATTR);//w w w . ja va 2 s.co m if (map.item(0).getNodeName().equals(STRING_ATTR)) { return map.item(0).getNodeValue(); } else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) { return new Integer(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) { return new Double(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) { return new Float(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) { return Boolean.valueOf(map.item(0).getNodeValue()); } else if (map.item(0).getNodeName().equals(COLOR_ATTR)) { String[] rgb = map.item(0).getNodeValue().split(","); return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2])); } else if (map.item(0).getNodeName().equals(FONT_ATTR)) { String[] font = map.item(0).getNodeValue().split(","); return new Font(font[0], new Integer(font[1]), new Integer(font[2])); } else { return null; } }
From source file:Main.java
private static final Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName) throws XmlPullParserException, IOException { try {//from ww w . j a v a 2 s . co m if (tagName.equals("int")) { return Integer.parseInt(parser.getAttributeValue(null, "value")); } else if (tagName.equals("long")) { return Long.valueOf(parser.getAttributeValue(null, "value")); } else if (tagName.equals("float")) { return new Float(parser.getAttributeValue(null, "value")); } else if (tagName.equals("double")) { return new Double(parser.getAttributeValue(null, "value")); } else if (tagName.equals("boolean")) { return Boolean.valueOf(parser.getAttributeValue(null, "value")); } else { return null; } } catch (NullPointerException e) { throw new XmlPullParserException("Need value attribute in <" + tagName + ">"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in value attribute in <" + tagName + ">"); } }
From source file:Main.java
/** * Given an array of objects, traverses the array and determines the most * suitable data type to perform the calculation in. An empty object of * the correct class is returned;/*from ww w . jav a2 s .c om*/ * * @param objects * */ static Object getObject(Object[] objects) { Class bestClass = bestClass(objects); if (bestClass == String.class) { return new String(""); //$NON-NLS-1$ } else if (bestClass == Double.class) { return new Double(0); } else if (bestClass == Float.class) { return new Float(0); } else if (bestClass == Long.class) { return new Long(0); } else if (bestClass == Integer.class) { return new Integer(0); } else { //it's a type we don't have here yet return null; } }
From source file:Main.java
public static ContentValues listToContentValues(List<String> values, String type) { ContentValues contentvalues = new ContentValues(); //Place values into contentvalue structure for (int i = 0; i < values.size(); i++) { String current = values.get(i); try {/*from w w w. j ava2 s .co m*/ //Separate the value by = in order to get key:value Integer indexOfEquals = current.indexOf("="); String key = current.substring(0, indexOfEquals); String value = current.substring(indexOfEquals + 1); if (type.toUpperCase().equals("STRING")) contentvalues.put(key, value); if (type.toUpperCase().equals("BOOLEAN")) contentvalues.put(key, Boolean.valueOf(value)); if (type.toUpperCase().equals("INTEGER")) contentvalues.put(key, new Integer(value)); if (type.toUpperCase().equals("DOUBLE")) contentvalues.put(key, new Double(value)); if (type.toUpperCase().equals("FLOAT")) contentvalues.put(key, new Float(value)); if (type.toUpperCase().equals("LONG")) contentvalues.put(key, new Long(value)); if (type.toUpperCase().equals("SHORT")) contentvalues.put(key, new Short(value)); } catch (Exception e) { Log.e("mercury", "Error with argument " + current); } } return contentvalues; }
From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java
public static double[] calculateSummaryStatistics(Number[] x) { logger.fine("entering calculate summary statistics (" + x.length + " Number values);"); double[] nx = new double[8]; //("mean", "medn", "mode", "vald", "invd", "min", "max", "stdev"); Float testNanValue = new Float(Float.NaN); Number testNumberValue = testNanValue; if (Double.isNaN(testNumberValue.doubleValue())) { logger.fine("Float test NaN value is still recognized as a Double NaN."); }/*from w w w . j a v a 2 s . co m*/ int invalid = countInvalidValues(x); nx[4] = invalid; logger.fine("counted invalid values: " + nx[4]); nx[3] = x.length - invalid; logger.fine("counted valid values: " + nx[3]); //double[] newx = prepareForSummaryStats(x); double[] newx = prepareForSummaryStatsAlternative(x, x.length - invalid); logger.fine("prepared double vector for summary stats calculation (" + newx.length + " double values);"); ////nx[0] = StatUtils.mean(newx); nx[0] = calculateMean(newx); logger.fine("calculated mean: " + nx[0]); ////nx[1] = StatUtils.percentile(newx, 50); nx[1] = calculateMedian(newx); logger.fine("calculated medn: " + nx[1]); nx[2] = 0.0; //getMode(newx); nx[5] = StatUtils.min(newx); logger.fine("calculated min: " + nx[5]); nx[6] = StatUtils.max(newx); logger.fine("calculated max: " + nx[6]); nx[7] = Math.sqrt(StatUtils.variance(newx)); logger.fine("calculated stdev: " + nx[7]); return nx; }
From source file:com.bstek.dorado.data.type.PrimitiveFloatDataType.java
@Override public Object fromText(String text) { if (StringUtils.isEmpty(text)) { return new Float(0); }// w w w .jav a2 s . c o m return super.fromText(text); }
From source file:SimpleFTF.java
public SimpleFTF() { JFormattedTextField ftf[] = new JFormattedTextField[7]; String des[] = new String[ftf.length]; // description of each field des[0] = "Date"; ftf[0] = new JFormattedTextField(new java.util.Date()); des[1] = "Integer"; ftf[1] = new JFormattedTextField(new Integer(90032221)); des[2] = "Float"; ftf[2] = new JFormattedTextField(new Float(3.14)); des[3] = "Float work-around"; // manually specify a NumberFormat ftf[3] = new JFormattedTextField(java.text.NumberFormat.getInstance()); ftf[3].setValue(new Float(3.14)); des[4] = "currency"; ftf[4] = new JFormattedTextField(java.text.NumberFormat.getCurrencyInstance()); ftf[4].setValue(new Float(5.99)); des[5] = "percent"; ftf[5] = new JFormattedTextField(java.text.NumberFormat.getPercentInstance()); ftf[5].setValue(new Float(0.33)); des[6] = "java.net.URL"; // works via 1-arg String constructor and // toString() java.net.URL u = null;//from w w w . ja v a 2 s . co m try { u = new java.net.URL("http://www.ora.com/"); } catch (java.net.MalformedURLException ignored) { } ftf[6] = new JFormattedTextField(u); ftf[6].setColumns(24); // add each ftf[] to a BoxLayout setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); for (int j = 0; j < ftf.length; j += 1) { JPanel borderPanel = new JPanel(new java.awt.BorderLayout()); borderPanel.setBorder(new javax.swing.border.TitledBorder(des[j])); borderPanel.add(ftf[j], java.awt.BorderLayout.CENTER); add(borderPanel); } }
From source file:com.bstek.dorado.data.type.PrimitiveFloatDataType.java
@Override public Object fromObject(Object value) { if (value == null) { return new Float(0); }//from ww w.j a v a2 s . com return super.fromObject(value); }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
private static Object nullValue(Class type) { if (type.isPrimitive()) { if (type == boolean.class) return Boolean.FALSE; if (type == byte.class) return new Byte((byte) 0); if (type == char.class) return new Character((char) 0); if (type == short.class) return new Short((short) 0); if (type == int.class) return new Integer(0); if (type == long.class) return new Long(0); if (type == float.class) return new Float(0); if (type == double.class) return new Double(0); }/* w w w . j a v a2 s. c o m*/ return null; }