List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:eg.agrimarket.controller.ProductController.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w . j av a 2s. co m PrintWriter out = response.getWriter(); eg.agrimarket.model.pojo.Product product = new eg.agrimarket.model.pojo.Product(); Product productJPA = new Product(); DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> it = items.iterator(); while (it.hasNext()) { FileItem item = it.next(); if (!item.isFormField()) { byte[] image = item.get(); if (image != null && image.length != 0) { product.setImage(image); productJPA.setImage(image); } } else { switch (item.getFieldName()) { case "name": product.setName(item.getString()); productJPA.setName(item.getString()); System.out.println("name" + item.getString()); break; case "price": product.setPrice(Float.valueOf(item.getString())); productJPA.setPrice(Float.valueOf(item.getString())); break; case "quantity": product.setQuantity(Integer.valueOf(item.getString())); productJPA.setQuantity(Integer.valueOf(item.getString())); break; case "desc": product.setDesc(item.getString()); productJPA.setDesc(item.getString()); System.out.println("desc: " + item.getString()); break; default: Category category = new Category(); category.setId(Integer.valueOf(item.getString())); product.setCategoryId(category); productJPA.setCategoryId(category.getId()); } } } ProductDao daoImp = new ProductDaoImp(); boolean check = daoImp.addProduct(product); if (check) { List<Product> products = (List<Product>) request.getServletContext().getAttribute("products"); if (products != null) { products.add(productJPA); request.getServletContext().setAttribute("products", products); } response.sendRedirect("http://" + request.getServerName() + ":" + request.getServerPort() + "/AgriMarket/admin/getProducts?success=Successfully#header3-41"); } else { response.sendRedirect("http://" + request.getServerName() + ":" + request.getServerPort() + "/AgriMarket/admin/getProducts?status=Exist!#header3-41"); } } catch (FileUploadException ex) { Logger.getLogger(ProductController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:strat.mining.multipool.stats.jersey.client.impl.BitfinexCurrencyTickerClient.java
@Override public CurrencyTickerDTO getCurrencyTicker(String currencyCode) { CurrencyTickerDTO result = new CurrencyTickerDTO(); try {/*from w w w.j a v a2s . c o m*/ LOGGER.debug("Retrieving ticker from Bitfinex for currency USD."); long start = System.currentTimeMillis(); BitfinexTicker responseTicker = client.target("https://api.bitfinex.com").path("v1/ticker/btcusd") .request(MediaType.APPLICATION_JSON).get(BitfinexTicker.class); PERF_LOGGER.info("Ticker retrieved from Bitfinex for currency USD in {} ms.", System.currentTimeMillis() - start); start = System.currentTimeMillis(); BitfinexToday responseToday = client.target("https://api.bitfinex.com").path("v1/today/btcusd") .request(MediaType.APPLICATION_JSON).get(BitfinexToday.class); PERF_LOGGER.info("Today info retrieved from Bitfinex for currency USD in {} ms.", System.currentTimeMillis() - start); if (responseTicker != null) { result.setCurrencyCode(currencyCode); result.setRefreshTime(new Date()); result.setLast(Float.valueOf(responseTicker.getLast_price())); result.setBuy(Float.valueOf(responseTicker.getBid())); result.setSell(Float.valueOf(responseTicker.getAsk())); } else { LOGGER.warn("Failed to retrieve the Bitfinex ticker for currency USD with no reason."); } if (responseToday != null) { result.setLow(Float.valueOf(responseToday.getLow())); result.setHigh(Float.valueOf(responseToday.getHigh())); result.setVolume(Float.valueOf(responseToday.getVolume())); } else { LOGGER.warn("Failed to retrieve the Bitfinex today for currency USD with no reason."); } } catch (Exception e) { LOGGER.error("Failed to retrieve the Bitfinex ticker for currency USD.", e); } return result; }
From source file:com.ghy.common.util.reflection.ReflectionUtils.java
/** * value String// ww w .j a v a 2s .co m * , private/protected, ??setter. */ public static void setFieldsValues(final Object obj, final String fieldName, final Object value) { Field field = getAccessibleField(obj, fieldName); if (field == null) { return; } try { Class<?> type = field.getType(); if (type.equals(Integer.class) || type.equals(int.class)) { field.set(obj, Integer.valueOf((String) value)); } else if (type.equals(Long.class) || type.equals(long.class)) { field.set(obj, Long.valueOf((String) value)); } else if (type.equals(Double.class) || type.equals(double.class)) { field.set(obj, Double.valueOf((String) value)); } else if (type.equals(Float.class) || type.equals(float.class)) { field.set(obj, Float.valueOf((String) value)); } else if (type.equals(Boolean.class) || type.equals(boolean.class)) { field.set(obj, Boolean.valueOf((String) value)); } else if (type.equals(Date.class)) { field.set(obj, new SimpleDateFormat("yyyyMMddHHmmsssss").parse((String) value)); } else { field.set(obj, value); } } catch (IllegalAccessException e) { logger.error(":{}", e.getMessage()); } catch (IllegalArgumentException e) { logger.error(":{}", e.getMessage()); e.printStackTrace(); } catch (ParseException e) { logger.error(":{}", e.getMessage()); e.printStackTrace(); } }
From source file:strat.mining.multipool.stats.jersey.client.impl.KrakenCurrencyTickerClient.java
@SuppressWarnings("unchecked") @Override/*from w w w. ja v a2s . c o m*/ public CurrencyTickerDTO getCurrencyTicker(String currencyCode) { CurrencyTickerDTO result = new CurrencyTickerDTO(); try { LOGGER.debug("Retrieving ticker from Kraken for currency {}.", currencyCode); long start = System.currentTimeMillis(); KrakenTicker response = client.target("https://api.kraken.com").path("0/public/Ticker") .queryParam("pair", "XBT" + currencyCode).request(MediaType.APPLICATION_JSON) .get(KrakenTicker.class); PERF_LOGGER.info("Ticker retrieved from Kraken for currency {} in {} ms.", currencyCode, System.currentTimeMillis() - start); if (response != null) { result.setCurrencyCode(currencyCode); result.setRefreshTime(new Date()); // Treat only the first value (there should be only one) for (Entry<String, Map<String, Object>> entry : response.getResult().entrySet()) { Map<String, Object> values = entry.getValue(); List<String> list = (List<String>) values.get("a"); result.setSell(Float.valueOf(list.get(0))); list = (List<String>) values.get("b"); result.setBuy(Float.valueOf(list.get(0))); list = (List<String>) values.get("v"); result.setVolume(Float.valueOf(list.get(0))); list = (List<String>) values.get("l"); result.setLow(Float.valueOf(list.get(0))); list = (List<String>) values.get("h"); result.setHigh(Float.valueOf(list.get(0))); list = (List<String>) values.get("c"); result.setLast(Float.valueOf(list.get(0))); } } else { LOGGER.warn("Failed to retrieve the Kraken ticker for currency {} with no reason.", currencyCode); } } catch (Exception e) { LOGGER.error("Failed to retrieve the Kraken ticker for currency {}.", currencyCode, e); } return result; }
From source file:org.codelibs.fess.es.config.exentity.DataConfig.java
@Override public String getDocumentBoost() { return Float.valueOf(getBoost().floatValue()).toString(); }
From source file:com.beetle.framework.util.ObjectUtil.java
public final static void populate(Object obj, Map<String, Object> map) { Set<?> s = map.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { String key = ""; Object o = null;/*from w w w . j a v a 2s .c o m*/ @SuppressWarnings("rawtypes") Map.Entry me = (Map.Entry) it.next(); try { key = me.getKey().toString(); o = me.getValue(); if (o == null) { continue; } setValue(key, obj, o); } catch (IllegalArgumentException e) { Class<Object> type = ObjectUtil.getType(key, obj); String tstr = type.toString(); if (tstr.equals(Integer.class.toString())) { ObjectUtil.setValue(key, obj, Integer.valueOf(o.toString())); } else if (tstr.equals(Long.class.toString())) { ObjectUtil.setValue(key, obj, Long.valueOf(o.toString())); } else if (tstr.equals(Float.class.toString())) { ObjectUtil.setValue(key, obj, Float.valueOf(o.toString())); } else if (tstr.equals(Double.class.toString())) { ObjectUtil.setValue(key, obj, Double.valueOf(o.toString())); } else if (tstr.equals(Short.class.toString())) { ObjectUtil.setValue(key, obj, Short.valueOf(o.toString())); } else if (tstr.equals(Byte.class.toString())) { ObjectUtil.setValue(key, obj, Byte.valueOf(o.toString())); } else if (tstr.equals(Date.class.toString())) { if (o instanceof Date) { ObjectUtil.setValue(key, obj, (Date) o); } else { long time = ((Double) o).longValue(); ObjectUtil.setValue(key, obj, new Date(time)); } } else if (tstr.equals(java.sql.Timestamp.class.toString())) { if (o instanceof java.sql.Timestamp) { ObjectUtil.setValue(key, obj, (Date) o); } else { long time = ((Double) o).longValue(); ObjectUtil.setValue(key, obj, new java.sql.Timestamp(time)); } } else { throw e; } tstr = null; type = null; } } }
From source file:org.brekka.stillingar.example.FieldTypesDOMTest.java
/** * // w w w. j a v a 2s.c o m */ private void verify() throws Exception { ConfiguredFieldTypes t = configuredFieldTypes; assertEquals(new URI(testing.getAnyURI()), t.getUri()); assertEquals(testing.getBoolean(), t.isBooleanPrimitive()); assertEquals(Byte.valueOf(testing.getByte()), t.getByteValue()); assertEquals(testing.getByte(), t.getBytePrimitive()); assertEquals(testing.getDate().getTime(), t.getDateAsCalendar().getTime()); assertEquals(testing.getDate().getTime(), t.getDateAsDate()); assertEquals(testing.getDateTime().getTime(), t.getDateTimeAsCalendar().getTime()); assertEquals(testing.getDateTime().getTime(), t.getDateTimeAsDate()); assertEquals(testing.getDecimal(), t.getDecimal()); assertEquals(Double.valueOf(testing.getDouble()), t.getDoubleValue()); assertEquals(testing.getDouble(), t.getDoublePrimitive(), 1d); assertEquals(testing.getFloat(), t.getFloatPrimitive(), 1f); assertEquals(Float.valueOf(testing.getFloat()), t.getFloatValue()); assertEquals(testing.getInt(), t.getIntPrimitive()); assertEquals(Integer.valueOf(testing.getInt()), t.getIntValue()); assertEquals(testing.getLanguage(), t.getLanguage().toString()); assertEquals(testing.getLong(), t.getLongPrimitive()); assertEquals(Long.valueOf(testing.getLong()), t.getLongValue()); assertEquals(testing.getShort(), t.getShortPrimitive()); assertEquals(Short.valueOf(testing.getShort()), t.getShortValue()); assertEquals(testing.getString(), t.getString()); assertEquals(testing.getPeriod().toString(), t.getPeriod().toString()); assertEquals(new DateTime(testing.getDateTime()).toString(), t.getDateTime().toString()); assertEquals(new LocalDate(testing.getDate()).toString(), t.getLocalDate().toString()); assertEquals(new LocalTime(testing.getTime()).toString(), t.getLocalTime().toString()); assertEquals(String.format("%tT", testing.getTime()), String.format("%tT", t.getTimeAsCalendar().getTime())); assertTrue(Arrays.equals(t.getBinary(), testing.getBinary())); assertEquals(UUID.fromString(testing.getUUID()), t.getUuid()); assertNotNull(t.getTestingElement()); assertNotNull(t.getRoot()); }
From source file:org.brekka.stillingar.example.FieldTypesJAXBTest.java
/** * // w w w. j a v a 2 s. c o m */ private void verify() throws Exception { ConfiguredFieldTypes t = configuredFieldTypes; assertEquals(new URI(testing.getAnyURI()), t.getUri()); assertEquals(testing.getBoolean(), t.isBooleanPrimitive()); assertEquals(Byte.valueOf(testing.getByte()), t.getByteValue()); assertEquals(testing.getByte(), t.getBytePrimitive()); assertEquals(testing.getDate().getTime(), t.getDateAsCalendar().getTime()); assertEquals(testing.getDate().getTime(), t.getDateAsDate()); assertEquals(testing.getDateTime().getTime(), t.getDateTimeAsCalendar().getTime()); assertEquals(testing.getDateTime().getTime(), t.getDateTimeAsDate()); assertEquals(testing.getDecimal(), t.getDecimal()); assertEquals(Double.valueOf(testing.getDouble()), t.getDoubleValue()); assertEquals(testing.getDouble(), t.getDoublePrimitive(), 1d); assertEquals(testing.getFloat(), t.getFloatPrimitive(), 1f); assertEquals(Float.valueOf(testing.getFloat()), t.getFloatValue()); assertEquals(testing.getInt(), t.getIntPrimitive()); assertEquals(Integer.valueOf(testing.getInt()), t.getIntValue()); assertEquals(testing.getLanguage(), t.getLanguage().toString()); assertEquals(testing.getLong(), t.getLongPrimitive()); assertEquals(Long.valueOf(testing.getLong()), t.getLongValue()); assertEquals(testing.getShort(), t.getShortPrimitive()); assertEquals(Short.valueOf(testing.getShort()), t.getShortValue()); assertEquals(testing.getString(), t.getString()); assertEquals(testing.getPeriod().toString(), t.getPeriod().toString()); assertEquals(new DateTime(testing.getDateTime()).toString(), t.getDateTime().toString()); assertEquals(new LocalDate(testing.getDate()).toString(), t.getLocalDate().toString()); assertEquals(new LocalTime(testing.getTime()).toString(), t.getLocalTime().toString()); assertEquals(String.format("%tT", testing.getTime()), String.format("%tT", t.getTimeAsCalendar().getTime())); assertTrue(Arrays.equals(t.getBinary(), testing.getBinary())); assertEquals(UUID.fromString(testing.getUUID()), t.getUuid()); assertNotNull(t.getTestingObject() instanceof org.brekka.stillingar.example.Configuration.Testing); assertNotNull(t.getTestingElement()); assertNotNull(t.getRoot()); }
From source file:org.brekka.stillingar.example.FieldTypesXmlBeansTest.java
/** * /*w w w. j a v a 2 s . c om*/ */ private void verify() throws Exception { ConfiguredFieldTypes t = configuredFieldTypes; assertEquals(new URI(testing.getAnyURI()), t.getUri()); assertEquals(testing.getBoolean(), t.isBooleanPrimitive()); assertEquals(Byte.valueOf(testing.getByte()), t.getByteValue()); assertEquals(testing.getByte(), t.getBytePrimitive()); assertEquals(testing.getDate(), t.getDateAsCalendar()); assertEquals(testing.getDate().getTime(), t.getDateAsDate()); assertEquals(testing.getDateTime(), t.getDateTimeAsCalendar()); assertEquals(testing.getDateTime().getTime(), t.getDateTimeAsDate()); assertEquals(testing.getDecimal(), t.getDecimal()); assertEquals(Double.valueOf(testing.getDouble()), t.getDoubleValue()); assertEquals(testing.getDouble(), t.getDoublePrimitive(), 1d); assertEquals(testing.getFloat(), t.getFloatPrimitive(), 1f); assertEquals(Float.valueOf(testing.getFloat()), t.getFloatValue()); assertEquals(testing.getInt(), t.getIntPrimitive()); assertEquals(Integer.valueOf(testing.getInt()), t.getIntValue()); assertEquals(testing.getLanguage(), t.getLanguage().toString()); assertEquals(testing.getLong(), t.getLongPrimitive()); assertEquals(Long.valueOf(testing.getLong()), t.getLongValue()); assertEquals(testing.getShort(), t.getShortPrimitive()); assertEquals(Short.valueOf(testing.getShort()), t.getShortValue()); assertEquals(testing.getString(), t.getString()); assertEquals(testing.getTime(), t.getTimeAsCalendar()); assertEquals(testing.getPeriod().toString(), t.getPeriod().toString()); assertEquals(new DateTime(testing.getDateTime(), ISOChronology.getInstance()), t.getDateTime()); assertEquals(new LocalDate(testing.getDate(), ISOChronology.getInstance()), t.getLocalDate()); assertEquals(new LocalTime(testing.getTime(), ISOChronology.getInstance()), t.getLocalTime()); assertTrue(Arrays.equals(t.getBinary(), testing.getBinary())); assertEquals(UUID.fromString(testing.getUUID()), t.getUuid()); assertTrue(t.getTestingObject() instanceof Testing); assertNotNull(t.getTestingElement()); assertNotNull(t.getRoot()); }