List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:com.spoledge.audao.parser.gql.impl.ParserUtils.java
public static Float argFloat(Object o) { if (o == null) return null; if (o instanceof Float) return (Float) o; if (o instanceof Number) return new Float(((Number) o).floatValue()); return new Float(o.toString()); }
From source file:com.manning.androidhacks.hack042.MainActivity.java
public void onSearchClick(View v) { Float lat = null;/* w w w . ja v a2 s . c o m*/ Float lon = null; try { lat = new Float(mLatitudeEditText.getText().toString()); lon = new Float(mLongitudeEditText.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(this, "Couldn't convert search fields to coordinates", Toast.LENGTH_SHORT).show(); return; } DatabaseHelper dbHelper = new DatabaseHelper(this); mPois.clear(); List<Poi> pois = dbHelper.getNear(lat, lon); mPois.addAll(pois); mAdapter.notifyDataSetChanged(); }
From source file:com.base.dao.sql.ReflectionUtils.java
public static Object convertValue(Object value, Class toType) { Object result = null;/* www .ja va 2 s. co m*/ if (value != null) { if (value.getClass().isArray() && toType.isArray()) { Class componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) result = Integer.valueOf((int) longValue(value)); if ((toType == Double.class) || (toType == Double.TYPE)) result = new Double(doubleValue(value)); if ((toType == Boolean.class) || (toType == Boolean.TYPE)) result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; if ((toType == Byte.class) || (toType == Byte.TYPE)) result = Byte.valueOf((byte) longValue(value)); if ((toType == Character.class) || (toType == Character.TYPE)) result = new Character((char) longValue(value)); if ((toType == Short.class) || (toType == Short.TYPE)) result = Short.valueOf((short) longValue(value)); if ((toType == Long.class) || (toType == Long.TYPE)) result = Long.valueOf(longValue(value)); if ((toType == Float.class) || (toType == Float.TYPE)) result = new Float(doubleValue(value)); if (toType == BigInteger.class) result = bigIntValue(value); if (toType == BigDecimal.class) result = bigDecValue(value); if (toType == String.class) result = stringValue(value); if (toType == Date.class) { result = DateUtils.toDate(stringValue(value)); } if (Enum.class.isAssignableFrom(toType)) result = enumValue((Class<Enum>) toType, value); } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:org.hdiv.web.servlet.tags.form.RadioButtonTagTests.java
public void testWithUncheckedObjectValue() throws Exception { Float value = new Float("99.45"); this.tag.setPath("myFloat"); this.tag.setValue(value); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); assertTagOpened(output);//from w w w.ja v a 2s . c o m assertTagClosed(output); assertContainsAttribute(output, "name", "myFloat"); assertContainsAttribute(output, "type", "radio"); String hdivValue = this.confidentiality ? "0" : value.toString(); assertContainsAttribute(output, "value", hdivValue); assertAttributeNotPresent(output, "checked"); }
From source file:com.nfwork.dbfound.json.JSONDynaBean.java
public Object get(String name) { Object value = dynaValues.get(name); if (value != null) { return value; }//from w w w. j a va 2 s . co m Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("Unspecified property type for " + name); } if (!type.isPrimitive()) { return value; } if (type == Boolean.TYPE) { return Boolean.FALSE; } else if (type == Byte.TYPE) { return new Byte((byte) 0); } else if (type == Character.TYPE) { return new Character((char) 0); } else if (type == Short.TYPE) { return new Short((short) 0); } else if (type == Integer.TYPE) { return new Integer(0); } else if (type == Long.TYPE) { return new Long(0); } else if (type == Float.TYPE) { return new Float(0.0); } else if (type == Double.TYPE) { return new Double(0); } return null; }
From source file:blue.soundObject.pianoRoll.PianoNote.java
public void setStart(float start) { PropertyChangeEvent pce = new PropertyChangeEvent(this, "start", new Float(this.start), new Float(start)); this.start = start; firePropertyChange(pce);// ww w . j a v a2s .com }
From source file:org.hdiv.web.servlet.tags.form.HiddenInputTagTests.java
protected TestBean createTestBean() { this.bean = new TestBean(); bean.setName("Sally Greenwood"); bean.setMyFloat(new Float("12.34")); return bean;/*from w ww. j a v a2 s . c om*/ }
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.excel.ExcelUtility.java
public static Float getFloat(HSSFSheet sheet, int row, short col) { HSSFRow hssfRow = getRow(sheet, row); if (hssfRow == null) { return null; }/*www. j a va2s . c om*/ HSSFCell cell = getRow(sheet, row).getCell(col); if (isNull(cell)) { return null; } return new Float(cell.getNumericCellValue()); }
From source file:com.cloudera.recordbreaker.learnstructure.test.GenerateRandomData.java
Object generateData(Schema s) { Schema.Type stype = s.getType(); if (stype == Schema.Type.ARRAY) { Schema arrayS = s.getElementType(); int numElts = 1 + r.nextInt(100); GenericData.Array result = new GenericData.Array(numElts, arrayS); for (int i = 0; i < numElts; i++) { result.add(generateData(arrayS)); }/*w w w . j a v a 2 s . com*/ return arrayS; } else if (stype == Schema.Type.BOOLEAN) { return r.nextInt(2) == 0 ? new Boolean(true) : new Boolean(false); } else if (stype == Schema.Type.BYTES) { return ByteBuffer.wrap(new byte[16]); } else if (stype == Schema.Type.DOUBLE) { return new Double(r.nextDouble()); } else if (stype == Schema.Type.ENUM) { List<String> symbols = s.getEnumSymbols(); return symbols.get(r.nextInt(symbols.size())); } else if (stype == Schema.Type.FIXED) { return new GenericData.Fixed(s, new byte[16]); } else if (stype == Schema.Type.FLOAT) { return new Float(r.nextFloat()); } else if (stype == Schema.Type.INT) { return new Integer(r.nextInt()); } else if (stype == Schema.Type.LONG) { return new Long(r.nextLong()); } else if (stype == Schema.Type.MAP) { HashMap<Utf8, Object> result = new HashMap<Utf8, Object>(); Schema valType = s.getValueType(); int maxElts = 1 + r.nextInt(100); for (int i = 0; i < maxElts; i++) { result.put(new Utf8("label-" + i), generateData(valType)); } return result; } else if (stype == Schema.Type.NULL) { return null; } else if (stype == Schema.Type.RECORD) { GenericData.Record result = new GenericData.Record(s); for (Schema.Field f : s.getFields()) { result.put(f.name(), generateData(f.schema())); } return result; } else if (stype == Schema.Type.STRING) { return new Utf8("Rand-" + r.nextInt()); } else if (stype == Schema.Type.UNION) { List<Schema> types = s.getTypes(); return generateData(types.get(r.nextInt(types.size()))); } return null; }
From source file:Main.java
private static final Object readThisValueXml(XmlPullParser parser, String[] name) throws XmlPullParserException, java.io.IOException { final String valueName = parser.getAttributeValue(null, "name"); final String tagName = parser.getName(); //System.out.println("Reading this value tag: " + tagName + ", name=" + valueName); Object res;/*from ww w. j a va 2s .c om*/ if (tagName.equals("null")) { res = null; } else if (tagName.equals("string")) { String value = ""; int eventType; while ((eventType = parser.next()) != parser.END_DOCUMENT) { if (eventType == parser.END_TAG) { if (parser.getName().equals("string")) { name[0] = valueName; //System.out.println("Returning value for " + valueName + ": " + value); return value; } throw new XmlPullParserException("Unexpected end tag in <string>: " + parser.getName()); } else if (eventType == parser.TEXT) { value += parser.getText(); } else if (eventType == parser.START_TAG) { throw new XmlPullParserException("Unexpected start tag in <string>: " + parser.getName()); } } throw new XmlPullParserException("Unexpected end of document in <string>"); } else if (tagName.equals("int")) { res = Integer.parseInt(parser.getAttributeValue(null, "value")); } else if (tagName.equals("long")) { res = Long.valueOf(parser.getAttributeValue(null, "value")); } else if (tagName.equals("float")) { res = new Float(parser.getAttributeValue(null, "value")); } else if (tagName.equals("double")) { res = new Double(parser.getAttributeValue(null, "value")); } else if (tagName.equals("boolean")) { res = Boolean.valueOf(parser.getAttributeValue(null, "value")); } else if (tagName.equals("int-array")) { parser.next(); res = readThisIntArrayXml(parser, "int-array", name); name[0] = valueName; //System.out.println("Returning value for " + valueName + ": " + res); return res; } else if (tagName.equals("map")) { parser.next(); res = readThisMapXml(parser, "map", name); name[0] = valueName; //System.out.println("Returning value for " + valueName + ": " + res); return res; } else if (tagName.equals("list")) { parser.next(); res = readThisListXml(parser, "list", name); name[0] = valueName; //System.out.println("Returning value for " + valueName + ": " + res); return res; } else { throw new XmlPullParserException("Unknown tag: " + tagName); } // Skip through to end tag. int eventType; while ((eventType = parser.next()) != parser.END_DOCUMENT) { if (eventType == parser.END_TAG) { if (parser.getName().equals(tagName)) { name[0] = valueName; //System.out.println("Returning value for " + valueName + ": " + res); return res; } throw new XmlPullParserException("Unexpected end tag in <" + tagName + ">: " + parser.getName()); } else if (eventType == parser.TEXT) { throw new XmlPullParserException("Unexpected text in <" + tagName + ">: " + parser.getName()); } else if (eventType == parser.START_TAG) { throw new XmlPullParserException("Unexpected start tag in <" + tagName + ">: " + parser.getName()); } } throw new XmlPullParserException("Unexpected end of document in <" + tagName + ">"); }