List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:gov.nih.nci.cacisweb.util.LoggableStatement.java
public void setFloat(int parameterIndex, float x) throws SQLException { wrappedStatement.setFloat(parameterIndex, x); saveQueryParamValue(parameterIndex, new Float(x)); }
From source file:com.scit.sling.test.MockValueMap.java
@SuppressWarnings("unchecked") private <T> T convertType(Object o, Class<T> type) { if (o == null) { return null; }//from w w w .j av a2 s . c o m if (o.getClass().isArray() && type.isArray()) { if (type.getComponentType().isAssignableFrom(o.getClass().getComponentType())) { return (T) o; } else { // we need to convert the elements in the array Object array = Array.newInstance(type.getComponentType(), Array.getLength(o)); for (int i = 0; i < Array.getLength(o); i++) { Array.set(array, i, convertType(Array.get(o, i), type.getComponentType())); } return (T) array; } } if (o.getClass().isAssignableFrom(type)) { return (T) o; } if (String.class.isAssignableFrom(type)) { // Format dates if (o instanceof Calendar) { return (T) formatDate((Calendar) o); } else if (o instanceof Date) { return (T) formatDate((Date) o); } else if (o instanceof DateTime) { return (T) formatDate((DateTime) o); } return (T) String.valueOf(o); } else if (o instanceof DateTime) { DateTime dt = (DateTime) o; if (Calendar.class.isAssignableFrom(type)) { return (T) dt.toCalendar(Locale.getDefault()); } else if (Date.class.isAssignableFrom(type)) { return (T) dt.toDate(); } else if (Number.class.isAssignableFrom(type)) { return convertType(dt.getMillis(), type); } } else if (o instanceof Number && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) (Byte) ((Number) o).byteValue(); } else if (Double.class.isAssignableFrom(type)) { return (T) (Double) ((Number) o).doubleValue(); } else if (Float.class.isAssignableFrom(type)) { return (T) (Float) ((Number) o).floatValue(); } else if (Integer.class.isAssignableFrom(type)) { return (T) (Integer) ((Number) o).intValue(); } else if (Long.class.isAssignableFrom(type)) { return (T) (Long) ((Number) o).longValue(); } else if (Short.class.isAssignableFrom(type)) { return (T) (Short) ((Number) o).shortValue(); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal(o.toString()); } } else if (o instanceof Number && type.isPrimitive()) { final Number num = (Number) o; if (type == byte.class) { return (T) new Byte(num.byteValue()); } else if (type == double.class) { return (T) new Double(num.doubleValue()); } else if (type == float.class) { return (T) new Float(num.floatValue()); } else if (type == int.class) { return (T) new Integer(num.intValue()); } else if (type == long.class) { return (T) new Long(num.longValue()); } else if (type == short.class) { return (T) new Short(num.shortValue()); } } else if (o instanceof String && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) new Byte((String) o); } else if (Double.class.isAssignableFrom(type)) { return (T) new Double((String) o); } else if (Float.class.isAssignableFrom(type)) { return (T) new Float((String) o); } else if (Integer.class.isAssignableFrom(type)) { return (T) new Integer((String) o); } else if (Long.class.isAssignableFrom(type)) { return (T) new Long((String) o); } else if (Short.class.isAssignableFrom(type)) { return (T) new Short((String) o); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal((String) o); } } throw new NotImplementedException( "Can't handle conversion from " + o.getClass().getName() + " to " + type.getName()); }
From source file:cm.aptoide.pt.RssHandler.java
@Override public void characters(final char[] ch, final int start, final int length) throws SAXException { super.characters(ch, start, length); if (apk_name) { tmp_apk.name = new String(ch).substring(start, start + length); } else if (apk_id) { tmp_apk.apkid = new String(ch).substring(start, start + length); } else if (apk_path) { tmp_apk.path = new String(ch).substring(start, start + length); } else if (apk_ver) { tmp_apk.ver = new String(ch).substring(start, start + length); } else if (apk_vercode) { try {/*from w w w.j ava 2s . c o m*/ tmp_apk.vercode = new Integer(new String(ch).substring(start, start + length)); } catch (Exception e) { tmp_apk.vercode = 0; } } else if (apk_icon) { IconNode a = new IconNode(new String(ch).substring(start, start + length), tmp_apk.apkid); synchronized (iconFetchList) { iconFetchList.add(a); } /*new Thread() { public void run() { try{ getIcon(new String(ch).substring(start, start + length), tmp_apk.apkid); } catch (Exception e) { } } }.start();*/ } else if (apk_date) { tmp_apk.date = new String(ch).substring(start, start + length); } else if (apk_rat) { try { tmp_apk.rat = new Float(new String(ch).substring(start, start + length)); } catch (Exception e) { tmp_apk.rat = 3.0f; } } else if (apk_md5hash) { tmp_apk.md5hash = new String(ch).substring(start, start + length); } }
From source file:com.netspective.commons.text.ExpressionTextTest.java
public void testJavaExpressionText() { // Java Expression Test JavaExpressionText jetOne = new JavaExpressionText(); assertNotNull(jetOne);/*from www .j a v a2 s . co m*/ JexlContext jc = jetOne.getJexlContext(); assertNotNull(jc); String javaExpInputOne = "2 + 2 = ${2 + 2}"; String javaExpOutput = jetOne.getFinalText(null, javaExpInputOne); assertEquals("2 + 2 = 4", javaExpOutput); jc.getVars().put("pinky", new String("pinky")); String javaExpInputTwo = "'pinky' uppercased is ${pinky.toUpperCase()}"; String javaExpOutputTwo = jetOne.getFinalText(null, javaExpInputTwo); assertEquals("'pinky' uppercased is PINKY", javaExpOutputTwo); Map vars = new HashMap(); vars.put("theBrain", new String("The Brain")); vars.put("pi", new Float(3.14)); vars.put("radius", new Float(2.5)); JavaExpressionText jetTwo = new JavaExpressionText("static expression"); assertNotNull(jetTwo); JexlContext jcTwo = jetTwo.getJexlContext(); assertNotNull(jcTwo); jetTwo.init(vars); String javaExpInputThree = "Area = pi * radius^2 = ${pi * radius * radius}"; String javaExpOutputThree = jetTwo.getFinalText(null, javaExpInputThree); assertEquals("Area = pi * radius^2 = 19.625", javaExpOutputThree); assertEquals("static expression", jetTwo.getFinalText(null)); assertEquals("static expression", jetTwo.getStaticExpr()); JavaExpressionText jetThree = new JavaExpressionText("${theBrain} is a static expression", vars); assertNotNull(jetThree); String javaExpInputFour = "Pinky's smarter half: ${theBrain}"; String javaExpOutputFour = jetThree.getFinalText(null, javaExpInputFour); assertEquals("Pinky's smarter half: The Brain", javaExpOutputFour); assertEquals("The Brain is a static expression", jetThree.getFinalText(null)); assertEquals("${theBrain} is a static expression", jetThree.getStaticExpr()); JavaExpressionText jetFour = new JavaExpressionText(vars); assertNotNull(jetFour); String javaExpInputFive = "Tom and Jerry like ${pi}"; String javaExpOutputFive = jetFour.getFinalText(null, javaExpInputFive); assertEquals("Tom and Jerry like 3.14", javaExpOutputFive); assertNull(jetFour.getStaticExpr()); ValueContext testVC = new DefaultValueContext(); testVC.setAttribute("test-attribute", new String("Test Attribute - Do NOT Use")); assertEquals(javaExpOutputFive, jetFour.getFinalText(testVC, javaExpInputFive)); }
From source file:alma.acs.monitoring.blobber.BlobData.java
/** * Calculates the statistics and stores it in {@link #statistics} * if our monitor point data is represented as Number objects; * otherwise this call is ignored.//from w w w .j a va 2s . co m * * @param inDataList */ void calculateStatistics() { if (getDataSize() > 0) { // We trust that the data is homogeneous and check only the first MonitorPointValue MonitorPointValue sampleMonitorPointValue = mpTs.getDataList().get(0); if (sampleMonitorPointValue.getData().isEmpty()) { logger.finer( "Ignoring calculateStatistics() call for a time series of MonitorPointValue objects that hold no data."); return; } // TODO: Should we also compute statistics for multi-valued properties? // This was not done in the original (= pre-ACS 12.0) implementation of BlobberWorker#calculateStatistics // and so far we keep this behavior. if (sampleMonitorPointValue.isMultiValued()) { logger.finer( "Ignoring calculateStatistics() call for a time series of multi-valued MonitorPointValue objects."); return; } // After the above checks, there should be a single data item in our sampleMonitorPointValue // We now verify that it has one of the expected numeric types. Object sampleData = sampleMonitorPointValue.getData().get(0); if (!(sampleData instanceof Integer || sampleData instanceof Long || sampleData instanceof Float || sampleData instanceof Double)) { logger.finer( "Ignoring calculateStatistics() call for data type " + sampleData.getClass().getName()); return; } // Now we calculate the statistics, // using apache math lib that works only with 'double' type SummaryStatistics stat = new SummaryStatistics(); for (MonitorPointValue blobData : mpTs.getDataList()) { Number value = (Number) blobData.getData().get(0); stat.addValue(value.doubleValue()); } statistics = new ComponentStatistics(); // We store the results in a ComponentStatistics object, // converting to original data types where it makes sense if (sampleData instanceof Integer) { statistics.min = new Integer((int) Math.round(stat.getMin())); statistics.max = new Integer((int) Math.round(stat.getMax())); statistics.mean = new Double(stat.getMean()); // or Float, to indicate lower precision? statistics.stdDev = new Double(stat.getStandardDeviation()); // or Float, to indicate lower precision? } else if (sampleData instanceof Long) { statistics.min = new Long(Math.round(stat.getMin())); statistics.max = new Long(Math.round(stat.getMax())); statistics.mean = new Double(stat.getMean()); statistics.stdDev = new Double(stat.getStandardDeviation()); } else if (sampleData instanceof Float) { statistics.min = new Float(stat.getMin()); statistics.max = new Float(stat.getMax()); statistics.mean = new Float(stat.getMean()); statistics.stdDev = new Float(stat.getStandardDeviation()); } else if (sampleData instanceof Double) { statistics.min = new Double(stat.getMin()); statistics.max = new Double(stat.getMax()); statistics.mean = new Double(stat.getMean()); statistics.stdDev = new Double(stat.getStandardDeviation()); } } }
From source file:edu.utah.further.core.api.collections.ToParameterMapBuilder.java
/** * Append a float field value./*from w w w. j a v a2 s . c o m*/ * * @param fieldName * the name of the field, usually the member variable name * @param value * the field value * @return this, to support call-chaining */ public ToParameterMapBuilder append(final String fieldName, final float value) { return append(fieldName, new Float(value)); }
From source file:app.order.OrderMetier.java
@Override public void makePayment(float avanceEspece, float avanceCheque, Date dueDate, Bank bank, String checkName, int nbrCheque) { createBill();/* w w w . j av a 2 s . co m*/ this.order.setPaidAmount(new Float(0)); if (avanceEspece != 0) { this.cash = (Cash) ApplicationContextProvider.getContext().getBean("cash"); this.cash.setAvance(Boolean.TRUE); this.cash.setAmount(avanceEspece); this.cash.setCashTendered(this.order.getTotalAmount());//To Change this.cash.addBill(this.bill); this.cash.setPaymentState(PaymentState.NONPAYE); this.bill.addPayment(this.cash); paymentMetier.makePersistent(this.cash); } if (avanceCheque != 0) { this.check = (Check) ApplicationContextProvider.getContext().getBean("check"); this.check.setAvance(true); this.check.setAmount(avanceCheque); this.check.setBank(bank); this.check.setDueDate(dueDate); this.check.setName(checkName); this.check.addBill(this.bill); //this.check.setState(CheckState.NONPAYE.toString()); this.check.setPaymentState(PaymentState.NONPAYE); this.bill.addPayment(this.check); paymentMetier.makePersistent(this.check); } if (nbrCheque != 0) { float deferenceAmount = this.order.getTotalAmount() - avanceCheque - avanceEspece; createChecks(nbrCheque, bank, checkName, dueDate, deferenceAmount); } this.billMetier.makePersistent(this.bill); super.makePersistent(this.order); }
From source file:es.eucm.eadandroid.homeapp.repository.resourceHandler.RepoResourceHandler.java
/** * Downloads any kind of file/*from www . jav a 2s .c o m*/ */ public static void downloadFile(String url_from, String path_to, String fileName, ProgressNotifier pt) { try { HttpGet httpGet = new HttpGet(url_from); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 20000); HttpConnectionParams.setSoTimeout(httpParameters, 42000); HttpClient httpclient = new DefaultHttpClient(httpParameters); // Execute HTTP Get Request HttpResponse response = httpclient.execute(httpGet); pt.notifyProgress(0, "Connection established"); File file = new File(path_to, fileName); FileOutputStream fos; try { fos = new FileOutputStream(file); InputStream in; try { float fileSize = response.getEntity().getContentLength(); Log.d("fileSize", String.valueOf(fileSize)); float iterNum = new Float(fileSize / (DOWNLOAD_BUFFER_SIZE) + 1).intValue(); Log.d("numIter", String.valueOf(iterNum)); float prIncrement = 100 / iterNum; Log.d("prIncrement", String.valueOf(prIncrement)); Float progress = new Float(0); in = response.getEntity().getContent(); byte[] buffer = new byte[DOWNLOAD_BUFFER_SIZE]; int len1 = 0; while ((len1 = in.read(buffer)) != -1) { fos.write(buffer, 0, len1); progress += len1 / fileSize * 100; pt.notifyProgress(progress.intValue(), "Downloading " + fileName); Log.d("progress", String.valueOf(progress)); } fos.close(); in.close(); } catch (IOException e) { pt.notifyError("Repository connection error"); e.printStackTrace(); } } catch (FileNotFoundException e) { pt.notifyError("Destination file error"); e.printStackTrace(); } } catch (Exception e1) { pt.notifyError("Repository connection error"); e1.printStackTrace(); } }
From source file:com.springsource.greenhouse.events.JdbcEventRepositoryTest.java
@Test public void rate() throws RatingPeriodClosedException { eventRepository.rate(2L, 6, 1L, new Rating((short) 5, "Rocked")); eventRepository.rate(2L, 6, 2L, new Rating((short) 4, "Rocked")); Float rating = eventRepository.rate(2L, 6, 3L, new Rating((short) 2, "Rocked")); assertEquals(new Float(3.5), rating); }
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * Return compatible class for typedValue based on untypedValueClass * //from w w w . j a v a 2s . c o m * @param untypedValueClass * @param typedValue * @return */ public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) { Log LOG = LogFactory.getLog(DataTypeHelper.class); if (typedValue == null) { return null; } if (untypedValueClass == null) { return typedValue; } if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) { return typedValue; } String strTypedValue = null; boolean isStringTypedValue = typedValue instanceof String; Number numTypedValue = null; boolean isNumberTypedValue = typedValue instanceof Number; Boolean boolTypedValue = null; boolean isBooleanTypedValue = typedValue instanceof Boolean; Date dateTypedValue = null; boolean isDateTypedValue = typedValue instanceof Date; if (isStringTypedValue) { strTypedValue = (String) typedValue; } if (isNumberTypedValue) { numTypedValue = (Number) typedValue; } if (isBooleanTypedValue) { boolTypedValue = (Boolean) typedValue; } if (isDateTypedValue) { dateTypedValue = (Date) typedValue; } Object v = null; if (String.class.equals(untypedValueClass)) { v = ObjectUtils.toString(typedValue); } else if (BigDecimal.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createBigDecimal(strTypedValue); } else if (isNumberTypedValue) { v = new BigDecimal(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new BigDecimal(dateTypedValue.getTime()); } } else if (Boolean.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = BooleanUtils.toBooleanObject(strTypedValue); } else if (isNumberTypedValue) { v = BooleanUtils.toBooleanObject(numTypedValue.intValue()); } else if (isDateTypedValue) { v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime()); } } else if (Byte.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = Byte.valueOf(strTypedValue); } else if (isNumberTypedValue) { v = new Byte(numTypedValue.byteValue()); } else if (isBooleanTypedValue) { v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Byte((byte) dateTypedValue.getTime()); } } else if (byte[].class.equals(untypedValueClass)) { if (isStringTypedValue) { v = strTypedValue.getBytes(); } } else if (Double.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createDouble(strTypedValue); } else if (isNumberTypedValue) { v = new Double(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Double(dateTypedValue.getTime()); } } else if (Float.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createFloat(strTypedValue); } else if (isNumberTypedValue) { v = new Float(numTypedValue.floatValue()); } else if (isBooleanTypedValue) { v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Float(dateTypedValue.getTime()); } } else if (Short.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Integer.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Long.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createLong(strTypedValue); } else if (isNumberTypedValue) { v = new Long(numTypedValue.longValue()); } else if (isBooleanTypedValue) { v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Long(dateTypedValue.getTime()); } } else if (java.sql.Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Date(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Date(dateTypedValue.getTime()); } } else if (java.sql.Time.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Time(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Time(dateTypedValue.getTime()); } } else if (java.sql.Timestamp.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Timestamp(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Timestamp(dateTypedValue.getTime()); } } else if (Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new Date(numTypedValue.longValue()); } else if (isStringTypedValue) { try { v = DateFormat.getDateInstance().parse(strTypedValue); } catch (ParseException e) { LOG.error("Unable to parse the date : " + strTypedValue); LOG.debug(e.getMessage()); } } } return v; }