List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:com.w20e.socrates.model.ExpressionCompiler.java
/** * Implement number creation./*ww w . j av a 2 s . c o m*/ * * @return an XNumber object * @param arg0 * numeric value */ @Override public Object number(final String arg0) { if (arg0.indexOf('.') == -1) { return new XNumber(Long.valueOf(arg0)); } return new XNumber(new Float(arg0)); }
From source file:io.jeandavid.projects.vod.entities.DvdOrder.java
public void addDvd(Dvd dvd, int quantity, Session session) { DvdOrderDvd temp = new DvdOrderDvd(); temp.setQuantity(quantity);/* w w w . j av a 2 s.co m*/ session.persist(temp); dvd.addDvdOrderDvd(temp); this.addDvdOrderDvd(temp); session.saveOrUpdate(session.merge(temp)); session.saveOrUpdate(session.merge(dvd)); float price = temp.computePrice(); temp.setPrice(price); session.saveOrUpdate(session.merge(temp)); this.price = new Float(this.price + price); session.saveOrUpdate(session.merge(this)); }
From source file:org.hdiv.web.servlet.tags.form.OptionsTagTests.java
public void testWithCollectionAndCustomEditor() throws Exception { PropertyEditor propertyEditor = new SimpleFloatEditor(); TestBean target = new TestBean(); target.setMyFloat(new Float("12.34")); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(target, COMMAND_NAME); errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor); exposeBindingResult(errors);//from w ww.j ava 2s .c om getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.myFloat", false)); this.tag.setItems("${floats}"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); List children = rootElement.elements(); assertEquals("Incorrect number of children", 6, children.size()); Element element = (Element) rootElement.selectSingleNode("option[text() = '12.34f']"); assertNotNull("Option node should not be null", element); assertEquals("12.34 node not selected", "selected", element.attribute("selected").getValue()); assertNull("No id rendered", element.attribute("id")); element = (Element) rootElement.selectSingleNode("option[text() = '12.35f']"); assertNotNull("Option node should not be null", element); assertNull("12.35 node incorrectly selected", element.attribute("selected")); assertNull("No id rendered", element.attribute("id")); }
From source file:org.wso2.carbon.governance.registry.extensions.executors.utils.Utils.java
public static void copyRatings(Registry registry, String newPath, String path) throws RegistryException { float averageRating = registry.getAverageRating(path); registry.rateResource(newPath, new Float(averageRating).intValue()); }
From source file:io.starter.datamodel.Sys.java
/** * add a counter to the system stats/* w ww . j a v a 2s. co m*/ * * @param name * @param ct */ public void incrementCounter(String name, Object ct) { Object existing = counters.get(name); if (existing != null) { // attempt to treat as a number, fail to String try { if (existing instanceof Float) { float fnf = Float.parseFloat(existing.toString()); float fnadd = Float.parseFloat(ct.toString()); // increment by new value fnf += fnadd; // update the counter counters.put(name, new Float(fnf)); } else if (existing instanceof Integer) { int fni = Integer.parseInt(existing.toString()); int fnadd = Integer.parseInt(ct.toString()); // increment by new value fni += fnadd; // update the counter counters.put(name, new Integer(fni)); } // is it an integer or a real float? } catch (NumberFormatException xf) { // cannot be "added", if it's a string append or replace? counters.put(name, ct); } } else { counters.put(name, ct); } }
From source file:NumberUtil.java
/** * Convert an Object to a Float.//from w w w . j a va 2 s . co m */ public static Float toFloat(Object value) { if (value == null) return null; if (value instanceof Float) return (Float) value; if (value instanceof String) { if ("".equals((String) value)) return null; return new Float((String) value); } if (value instanceof Number) return new Float(((Number) value).floatValue()); return new Float(value.toString()); }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!/*from w w w . j a va 2 s.com*/ * * @param name DOCUMENT ME! * * @return DOCUMENT ME! */ public Object get(String name) { Object value = dynaValues.get(name); if (value != null) { return value; } 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:app.order.OrderMetier.java
@Override public void makePayment() { createBill();/*www.j a v a 2 s. c o m*/ this.cash = (Cash) ApplicationContextProvider.getContext().getBean("cash"); this.cash.setAvance(Boolean.FALSE); this.cash.setAmount(this.order.getTotalAmount()); this.cash.setCashTendered(this.order.getTotalAmount());//To Change this.cash.addBill(this.bill); this.cash.setPaymentState(PaymentState.NONPAYE); this.paymentMetier.makePersistent(this.cash); this.bill.addPayment(this.cash); this.billMetier.makePersistent(this.bill); this.order.setPaidAmount(new Float(0)); this.order.setBill(this.bill); super.makePersistent(this.order); }
From source file:net.sf.ij_plugins.util.DialogUtil.java
/** * Utility to automatically create ImageJ's GenericDialog for editing bean properties. It uses BeanInfo to extract * display names for each field. If a fields type is not supported irs name will be displayed with a tag * "[Unsupported type: class_name]".// w w w .j a va 2 s.c om * * @param bean * @return <code>true</code> if user closed bean dialog using OK button, <code>false</code> otherwise. */ static public boolean showGenericDialog(final Object bean, final String title) { final BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(bean.getClass()); } catch (IntrospectionException e) { throw new IJPluginsRuntimeException("Error extracting bean info.", e); } final GenericDialog genericDialog = new GenericDialog(title); // Create generic dialog fields for each bean's property final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); try { for (int i = 0; i < propertyDescriptors.length; i++) { final PropertyDescriptor pd = propertyDescriptors[i]; final Class type = pd.getPropertyType(); if (type.equals(Class.class) && "class".equals(pd.getName())) { continue; } final Object o = PropertyUtils.getSimpleProperty(bean, pd.getName()); if (type.equals(Boolean.TYPE)) { boolean value = ((Boolean) o).booleanValue(); genericDialog.addCheckbox(pd.getDisplayName(), value); } else if (type.equals(Integer.TYPE)) { int value = ((Integer) o).intValue(); genericDialog.addNumericField(pd.getDisplayName(), value, 0); } else if (type.equals(Float.TYPE)) { double value = ((Float) o).doubleValue(); genericDialog.addNumericField(pd.getDisplayName(), value, 6, 10, ""); } else if (type.equals(Double.TYPE)) { double value = ((Double) o).doubleValue(); genericDialog.addNumericField(pd.getDisplayName(), value, 6, 10, ""); } else { genericDialog.addMessage(pd.getDisplayName() + "[Unsupported type: " + type + "]"); } } } catch (IllegalAccessException e) { throw new IJPluginsRuntimeException(e); } catch (InvocationTargetException e) { throw new IJPluginsRuntimeException(e); } catch (NoSuchMethodException e) { throw new IJPluginsRuntimeException(e); } // final Panel helpPanel = new Panel(); // helpPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); // final Button helpButton = new Button("Help"); //// helpButton.addActionListener(this); // helpPanel.add(helpButton); // genericDialog.addPanel(helpPanel, GridBagConstraints.EAST, new Insets(15,0,0,0)); // Show modal dialog genericDialog.showDialog(); if (genericDialog.wasCanceled()) { return false; } // Read fields from generic dialog into bean's properties. try { for (int i = 0; i < propertyDescriptors.length; i++) { final PropertyDescriptor pd = propertyDescriptors[i]; final Class type = pd.getPropertyType(); final Object propertyValue; if (type.equals(Boolean.TYPE)) { boolean value = genericDialog.getNextBoolean(); propertyValue = Boolean.valueOf(value); } else if (type.equals(Integer.TYPE)) { int value = (int) Math.round(genericDialog.getNextNumber()); propertyValue = new Integer(value); } else if (type.equals(Float.TYPE)) { double value = genericDialog.getNextNumber(); propertyValue = new Float(value); } else if (type.equals(Double.TYPE)) { double value = genericDialog.getNextNumber(); propertyValue = new Double(value); } else { continue; } PropertyUtils.setProperty(bean, pd.getName(), propertyValue); } } catch (IllegalAccessException e) { throw new IJPluginsRuntimeException(e); } catch (InvocationTargetException e) { throw new IJPluginsRuntimeException(e); } catch (NoSuchMethodException e) { throw new IJPluginsRuntimeException(e); } return true; }
From source file:com.orange.ngsi2.server.FakeNgsi2ControllerHelper.java
@Override protected Object retrieveAttributeValue(String entityId, String attrName, String type) { if (attrName.equals("temperature")) { return new Float(25.0); } else if (attrName.equals("on")) { return true; } else if (attrName.equals("color")) { return null; } else if (attrName.equals("hello")) { return "hello, world"; } else {//from w w w. j a v a 2s . c om return createValueReference(); } }