List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:gwap.rest.UserPicture.java
protected ArtResource createPicture(JSONObject payload) { ArtResource artResource = new ArtResource(); Query query = entityManager.createNamedQuery("person.byDeviceId"); query.setParameter("deviceId", payload.get("userid").toString()); Person person = (Person) query.getSingleResult(); artResource.setArtist(person);// ww w .jav a2 s. c o m Calendar now = GregorianCalendar.getInstance(); artResource.setDateCreated(new SimpleDateFormat("dd.MM.yyyy").format(now.getTime())); artResource.setSkip(true); // should not show up for artigo tagging Location location = new Location(); location.setType(LocationType.APP); if (payload.containsKey("name")) location.setName(payload.get("name").toString()); GeoPoint geoPoint = new GeoPoint(); geoPoint.setLatitude(Float.parseFloat(payload.get("latitude").toString())); geoPoint.setLongitude(Float.parseFloat(payload.get("longitude").toString())); entityManager.persist(geoPoint); entityManager.persist(location); entityManager.flush(); LocationGeoPoint locationGeoPoint = new LocationGeoPoint(); locationGeoPoint.setGeoPoint(geoPoint); locationGeoPoint.setLocation(location); entityManager.persist(locationGeoPoint); entityManager.flush(); location.getGeoRepresentation().add(locationGeoPoint); artResource.setShownLocation(location); entityManager.persist(artResource); entityManager.flush(); return artResource; }
From source file:com.owly.srv.BasicDataMetricInJson.java
/** * This method is used to create the data in this object based in the array of Basic Stats captured from database previously. * The data has two components : the label will be used to showe in the flot plugin, and the array of data with value,time. * @param ListBasicStats is the list of captured metris from database * @param offset is the offset obtained with timezone in the customer browser *//*from w w w. j a v a 2 s . com*/ public void insertDataMetrics(ArrayList<BasicStat> ListBasicStats, Integer offset) { //Clean the data till now inserted. this.jsonDataArray.clear(); Iterator it = ListBasicStats.iterator(); //Process all values from the list of metrics to save in a format valid for flot. while (it.hasNext()) { Date d2 = new Date(); BasicStat s = (BasicStat) it.next(); Date d = s.getDate(); //Change offset to milisseconds long msecOffset = ((long) offset) * 60 * 1000; Float v = Float.parseFloat(s.getValue()); d2.setTime(d.getTime() - msecOffset); //logger.debug("date = " + d + ";date_offset = "+d2+";value = "+v ); this.addJsonDataArray(d2, v); } }
From source file:it.readbeyond.minstrel.mediarb.AudioHandler.java
/** * Executes the request and returns PluginResult. * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return A PluginResult object with a status and message. *///from w w w . jav a2 s . c o m public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { CordovaResourceApi resourceApi = webView.getResourceApi(); PluginResult.Status status = PluginResult.Status.OK; String result = ""; if (action.equals("startPlayingAudio")) { String target = args.getString(1); String fileUriStr; try { Uri targetUri = resourceApi.remapUri(Uri.parse(target)); fileUriStr = targetUri.toString(); } catch (IllegalArgumentException e) { fileUriStr = target; } this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr)); } else if (action.equals("seekToAudio")) { this.seekToAudio(args.getString(0), args.getInt(1)); } else if (action.equals("pausePlayingAudio")) { this.pausePlayingAudio(args.getString(0)); } else if (action.equals("stopPlayingAudio")) { this.stopPlayingAudio(args.getString(0)); } else if (action.equals("setPlaybackSpeed")) { try { this.setPlaybackSpeed(args.getString(0), Float.parseFloat(args.getString(1))); } catch (NumberFormatException nfe) { //no-op } } else if (action.equals("setVolume")) { try { this.setVolume(args.getString(0), Float.parseFloat(args.getString(1))); } catch (NumberFormatException nfe) { //no-op } } else if (action.equals("getCurrentPositionAudio")) { float f = this.getCurrentPositionAudio(args.getString(0)); callbackContext.sendPluginResult(new PluginResult(status, f)); return true; } else if (action.equals("getDurationAudio")) { float f = this.getDurationAudio(args.getString(0), args.getString(1)); callbackContext.sendPluginResult(new PluginResult(status, f)); return true; } else if (action.equals("create")) { String id = args.getString(0); String src = FileHelper.stripFileProtocol(args.getString(1)); this.mMode = args.getString(2); getOrCreatePlayer(id, src); } else if (action.equals("release")) { boolean b = this.release(args.getString(0)); callbackContext.sendPluginResult(new PluginResult(status, b)); return true; } else if (action.equals("messageChannel")) { messageChannel = callbackContext; return true; } else { // Unrecognized action. return false; } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:me.willowcheng.makerthings.model.OpenHABItem.java
public Float getStateAsFloat() { // For uninitialized/null state return zero if (state == null) { return new Float(0); }// w w w. j a v a 2 s . c om if ("ON".equals(state)) { return new Float(100); } if ("OFF".equals(state)) { return new Float(0); } try { Float result = Float.parseFloat(state); } catch (NumberFormatException e) { if (e != null) { Crittercism.logHandledException(e); Log.e(TAG, e.getMessage()); } } return Float.parseFloat(state); }
From source file:com.netflix.subtitles.ttml.TtmlTimeConverter.java
/** * Parses ttml timeExpression.//w w w.j av a 2 s .co m * <p></p> * <pre> * <timeExpression> * : clock-time * | offset-time * * clock-time * : hours ":" minutes ":" seconds ( fraction | ":" frames ( "." sub-frames )? )? * * offset-time * : time-count fraction? metric * * hours * : <digit> <digit> * | <digit> <digit> <digit>+ * * minutes | seconds * : <digit> <digit> * * frames * : <digit> <digit> * | <digit> <digit> <digit>+ * * sub-frames * : <digit>+ * * fraction * : "." <digit>+ * * time-count * : <digit>+ * * metric * : "h" // hours * | "m" // minutes * | "s" // seconds * | "ms" // milliseconds * | "f" // frames * | "t" // ticks * </pre> * * @param timeExpression string representation of q ttml time expression * @return parsed time expression in millis or 0 */ public long parseTimeExpression(String timeExpression) { int mSeconds = 0; if (timeExpression == null || timeExpression.isEmpty()) { return mSeconds; } if (timeExpression.contains(":")) { // clock time String[] parts = timeExpression.split(":"); if (parts.length == 3) { int h, m; float s; h = Integer.parseInt(parts[0]); m = Integer.parseInt(parts[1]); s = Float.parseFloat(parts[2]); mSeconds = h * 3600000 + m * 60000 + (int) (s * 1000); } else if (parts.length == 4) { // TODO: dropMode should be considered int h, m, s; float f; String[] fParts = (parts[3].contains(".")) ? parts[3].split("\\.") : new String[] { parts[3], "0" }; h = Integer.parseInt(parts[0]); m = Integer.parseInt(parts[1]); s = Integer.parseInt(parts[2]); f = Float.parseFloat(fParts[0]) + Float.parseFloat(fParts[1]) / subFrameRate; mSeconds = h * 3600000 + m * 60000 + s * 1000 + (int) (f * 1000 * frDenominator / (frameRate * frNumerator)); } else { // unrecognized clock time format, nothing to do } } else { // offset time int metricLength = (timeExpression.contains("ms")) ? 2 : 1; String metric = timeExpression.substring(timeExpression.length() - metricLength); timeExpression = timeExpression.substring(0, timeExpression.length() - metricLength).replace(',', '.') .trim(); double time; try { time = Double.parseDouble(timeExpression); if (metric.equalsIgnoreCase("h")) { mSeconds = (int) (time * 3600000); } else if (metric.equalsIgnoreCase("m")) { mSeconds = (int) (time * 60000); } else if (metric.equalsIgnoreCase("s")) { mSeconds = (int) (time * 1000); } else if (metric.equalsIgnoreCase("ms")) { mSeconds = (int) time; } else if (metric.equalsIgnoreCase("f")) { mSeconds = (int) (time * 1000 * frDenominator / (frameRate * frNumerator)); } else if (metric.equalsIgnoreCase("t")) { mSeconds = (int) (time * 1000 / tickRate); } else { //invalid metric } } catch (NumberFormatException e) { //incorrect format for offset time } } return mSeconds; }
From source file:com.googlecode.jtiger.modules.ecside.util.ECSideUtils.java
public static float parseFloat(String value) { float result = 0.0f; try {/* w w w .j a va 2s .c o m*/ result = Float.parseFloat(value); } catch (Exception ex) { } return result; }
From source file:org.yamj.core.configuration.ConfigService.java
/** * Return the key property as a float//from ww w . j a v a 2s. c o m * * @param key * @param defaultValue * @return */ public float getFloatProperty(String key, float defaultValue) { String value = cachedProperties.get(key); if (value != null) { try { return Float.parseFloat(value.trim()); } catch (NumberFormatException nfe) { } } return defaultValue; }
From source file:com.frostwire.search.yify.YifySearchResult.java
private static long buildSize(String str) { long result = 0; Matcher matcher = SIZE_PATTERN.matcher(str); if (matcher.find()) { String amount = matcher.group(1); String unit = matcher.group(2); long multiplier = BYTE_MULTIPLIERS[UNIT_TO_BYTE_MULTIPLIERS_MAP.get(unit)]; //fractional size if (amount.indexOf(".") > 0) { float floatAmount = Float.parseFloat(amount); result = (long) (floatAmount * multiplier); }//w w w .j a v a2 s . c o m //integer based size else { int intAmount = Integer.parseInt(amount); result = intAmount * multiplier; } } return result; }
From source file:ancat.visualizers.EdgeTransformers.java
/** * Configuration of the Stroke used for drawing edges. It processes the * following values:/*from w w w . j a v a 2 s . c om*/ * * <code> edge:style </code> may be set to solid, dashed or dotted. By default * the edge style is set to dashed. * * <code> edge:stroke-width </code> The width of the stroke used for * rendering. * * <code> edge:dash-pattern</code> Contains an array of float values * describing the dash pattern. See documentation of Java Stroke class to * understand the pattern style</code> */ protected void setupStroke() { String style = "solid"; float width = 0.5f; float dash[] = null; Map<String, String> edgeConfig = _renderConfig.edgeConfiguration(); if (edgeConfig.containsKey("edge:style")) { style = edgeConfig.get("edge:style"); if (!style.equalsIgnoreCase("solid") && !style.equalsIgnoreCase("dashed") && !style.equalsIgnoreCase("dotted")) { _logger.error("unsupported edge style attribute: " + style + " allowed is solid, dashed, dotted"); style = "solid"; } } if (edgeConfig.containsKey("edge:stroke-width")) { try { width = Float.parseFloat(edgeConfig.get("edge:stroke-width")); } catch (Exception e) { _logger.error("unsupported specification of float value for edge width, changing to default"); } } if (edgeConfig.containsKey("edge:dash-pattern")) { try { StringTokenizer tokenizer = new StringTokenizer(edgeConfig.get("edge:dash-pattern"), ","); dash = new float[tokenizer.countTokens()]; int counter = 0; while (tokenizer.hasMoreElements()) { dash[counter] = Float.parseFloat(tokenizer.nextToken().trim()); counter += 1; } } catch (Exception e) { _logger.error("Error while parsing dash style, changing to default"); dash = new float[] { 10.0f }; } } if (style.equalsIgnoreCase("dashed")) { _edgeStroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f); } else if (style.equalsIgnoreCase("dotted")) { dash = new float[] { 2.0f, 2.0f }; _edgeStroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f); } else if (style.equalsIgnoreCase("solid")) { _edgeStroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); } }
From source file:org.chos.transaction.controller.ProductController.java
@RequestMapping(value = "item/add") @ResponseBody/*from w ww.j a v a 2s . c o m*/ public Object add(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> json = new HashMap<String, Object>(); String name = request.getParameter("name"); if (StringUtils.isBlank(name)) { json.put("code", 1000); return json; } String price = request.getParameter("price"); if (StringUtils.isBlank(price)) { json.put("code", 1000); return json; } String stock = request.getParameter("stock"); if (StringUtils.isBlank(stock)) { json.put("code", 1000); return json; } String description = request.getParameter("content"); if (StringUtils.isBlank(description)) { json.put("code", 1000); return json; } Session session = httpContextSessionManager.getSession(request); Product product = new Product(); product.setName(name); product.setUserId(session.getUserId()); product.setPrice(StringUtils.isBlank(price) ? 0 : Float.parseFloat(price)); product.setStock(Integer.parseInt(stock)); product.setCategory(6); product.setDescription(description); product.setCreation(new Date()); itemService.addProduct(product); json.put("code", 0); return json; }