List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:de.dmxcontrol.executor.EntityExecutor.java
public static EntityExecutor Receive(JSONObject o) { EntityExecutor entity = null;//w ww .j ava 2s . com try { if (o.getString("Type").equals(NetworkID)) { entity = new EntityExecutor(o.getInt("Number"), o.getString("Name")); entity.guid = o.getString("GUID"); if (o.has("Value")) { entity.value = Float.parseFloat(o.getString("Value").replace(",", ".")); } if (o.has("Flash")) { entity.flash = o.getBoolean("Flash"); } if (o.has("Toggle")) { entity.toggle = o.getBoolean("Toggle"); } if (o.has("FaderMode")) { entity.faderMode = o.getInt("FaderMode"); } } } catch (Exception e) { Log.e("UDP Listener", e.getMessage()); DMXControlApplication.SaveLog(); } o = null; if (o == null) { ; } return entity; }
From source file:MasterRoomControllerFx.rooms.charts.RoomChartController.java
public void getTempData() { try {/* w w w .j a va2s.c o m*/ File csvData = new File("tempHistory" + roomRow + roomColumn + ".csv"); if (csvData.exists()) { CSVParser parser = CSVParser.parse(csvData, StandardCharsets.UTF_8, CSVFormat.EXCEL.withDelimiter(';')); for (CSVRecord csvRecord : parser) { for (int i = 0; i < csvRecord.size(); i++) { if (i == 0) temp.add(Float.parseFloat(csvRecord.get(i))); if (i == 1) time.add(csvRecord.get(i)); } } } } catch (IOException ex) { Logger.getLogger(RoomChartController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:AdminPackage.AdminAddProductController.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w .ja va2s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HProductDao pDao = new HProductDao(); Product product = new Product(); Categories c = new Categories(); try { DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (item.isFormField()) { String name = item.getFieldName(); String value = item.getString(); switch (name) { case "productName": product.setProductName(value); break; case "productDesc": product.setProductDescription(value); break; case "productPrice": product.setProductPrice(Float.parseFloat(value)); break; case "productQuantityAvailable": product.setProductQuntityavailable(Integer.parseInt(value)); break; case "productQuantitySold": product.setProductQuntitysold(Integer.parseInt(value)); break; case "productCategory": c.setIdcategory(Integer.parseInt(value)); product.setCategories(c); break; } } else { if (!item.isFormField()) { item.write(new File("C:/images/" + item.getName())); product.setProductImg(item.getName()); } } } } catch (FileUploadException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } pDao.insert(product); /* PrintWriter out = response.getWriter(); out.write("Done");*/ response.sendRedirect("/WebProjectServletJsp/AdminProductController"); }
From source file:com.appglu.impl.util.StringUtils.java
public static Float stringToFloat(String string) { if (isEmpty(string)) { return null; }// ww w . j av a2 s.c o m try { return Float.parseFloat(string); } catch (NumberFormatException e) { return null; } }
From source file:com.joliciel.talismane.machineLearning.maxent.custom.RealValueFileEventStream2.java
@Override public Event next() { StringTokenizer st = new StringTokenizer(line); String outcome = st.nextToken(); if (outcome.equals("&null;")) outcome = ""; else if (outcome.equals("&space;")) outcome = " "; int count = st.countTokens(); // Assaf update: read real values from file boolean hasValues = line.contains("="); String[] context = new String[count]; float[] values = null; if (hasValues) values = new float[count]; for (int ci = 0; ci < count; ci++) { String token = st.nextToken(); if (hasValues) { int equalsPos = token.lastIndexOf('='); if (equalsPos < 0) { LOG.error("Missing value"); LOG.error("Line: " + line); LOG.error("Token: " + token); throw new RuntimeException("Missing value, on token \"" + token + "\""); }// w w w.ja va 2s. c om context[ci] = token.substring(0, equalsPos); values[ci] = Float.parseFloat(token.substring(equalsPos + 1)); } else { context[ci] = token; } } Event event = null; if (hasValues) event = new Event(outcome, context, values); else event = new Event(outcome, context); return event; }
From source file:com.xpn.xwiki.plugin.image.ImagePlugin.java
@Override public void init(XWikiContext context) { super.init(context); initCache(context);//from ww w .j av a 2 s. co m String defaultQualityParam = context.getWiki().Param("xwiki.plugin.image.defaultQuality"); if (!StringUtils.isBlank(defaultQualityParam)) { try { this.defaultQuality = Math.max(0, Math.min(1, Float.parseFloat(defaultQualityParam.trim()))); } catch (NumberFormatException e) { LOG.warn("Failed to parse xwiki.plugin.image.defaultQuality configuration parameter. " + "Using {} as the default image quality.", this.defaultQuality); } } }
From source file:de.avanux.smartapplianceenabler.appliance.HttpElectricityMeter.java
@Override public float getPower() { CloseableHttpResponse response = null; try {//from w w w. j ava 2 s . c o m response = sendHttpRequest(url, data, getContentType(), getUsername(), getPassword()); if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String responseString = EntityUtils.toString(response.getEntity()); String valueString = extractPowerValueFromResponse(responseString, powerValueExtractionRegex); logger.debug("Power value extracted from HTTP response: " + valueString); return Float.parseFloat(valueString) * factorToWatt; } } catch (Exception e) { logger.error("Error reading HTTP response", e); } finally { try { if (response != null) { response.close(); } } catch (IOException e) { logger.error("Error closing HTTP response", e); } } return 0; }
From source file:com.frostwire.search.bitsnoop.BitSnoopSearchResult.java
private long parseSize(String group) { String[] size = group.trim().split(" "); String amount = size[0].trim(); String unit = size[1].trim(); long multiplier = BYTE_MULTIPLIERS[UNIT_TO_BYTE_MULTIPLIERS_MAP.get(unit)]; //fractional size if (amount.indexOf(".") > 0) { float floatAmount = Float.parseFloat(amount); return (long) (floatAmount * multiplier); }/*from w w w . jav a 2s . co m*/ //integer based size else { int intAmount = Integer.parseInt(amount); return (long) (intAmount * multiplier); } }
From source file:info.plugmania.mazemania.Util.java
public static Location Str2Loc(String input) { if (input == null) { return null; }/*from ww w. j a va 2 s . c o m*/ Location loc; String[] parts = input.split(","); World world = plugin.getServer().getWorld(parts[0]); if (world == null) { Util.debug("WARNING: Str2Loc() world was invalid: " + input); return null; } loc = new Location(world, Double.parseDouble(parts[1]), Double.parseDouble(parts[2]), Double.parseDouble(parts[3]), Float.parseFloat(parts[4]), Float.parseFloat(parts[5])); return loc; }
From source file:au.org.ala.delta.intkey.directives.SetReliabilitiesDirective.java
@Override protected BasicIntkeyDirectiveInvocation doProcess(IntkeyContext context, String data) throws Exception { StringBuilder stringRepresentationBuilder = new StringBuilder(); stringRepresentationBuilder.append(getControlWordsAsString()); stringRepresentationBuilder.append(" "); IntkeyDataset dataset = context.getDataset(); Map<Character, Float> reliabilitiesMap = new HashMap<Character, Float>(); if (data == null || data.toUpperCase().startsWith(IntkeyDirectiveArgument.DEFAULT_DIALOG_WILDCARD) || data.toUpperCase().startsWith(IntkeyDirectiveArgument.KEYWORD_DIALOG_WILDCARD) || data.toUpperCase().startsWith(IntkeyDirectiveArgument.LIST_DIALOG_WILDCARD)) { SelectionMode selectionMode = context.displayKeywords() ? SelectionMode.KEYWORD : SelectionMode.LIST; if (data != null && data.startsWith(IntkeyDirectiveArgument.DEFAULT_DIALOG_WILDCARD)) { // do nothing - default selection mode is already set above. } else if (data != null && data.startsWith(IntkeyDirectiveArgument.KEYWORD_DIALOG_WILDCARD)) { selectionMode = SelectionMode.KEYWORD; } else if (data != null && data.startsWith(IntkeyDirectiveArgument.LIST_DIALOG_WILDCARD)) { selectionMode = SelectionMode.LIST; }//from w w w. j a va 2 s . c o m List<Character> characters; List<String> selectedKeywords = new ArrayList<String>(); // not // used, // but // needs to // be // supplied // as an // argument if (selectionMode == SelectionMode.KEYWORD) { characters = context.getDirectivePopulator().promptForCharactersByKeyword(getControlWordsAsString(), true, false, selectedKeywords); } else { characters = context.getDirectivePopulator().promptForCharactersByList(getControlWordsAsString(), false, selectedKeywords); } if (characters == null) { // cancelled return null; } Float reliability = Float.parseFloat(context.getDirectivePopulator().promptForString( UIUtils.getResourceString("ReliabilityPrompt.caption"), null, getControlWordsAsString())); for (Character ch : characters) { reliabilitiesMap.put(ch, reliability); } if (!selectedKeywords.isEmpty()) { for (int i = 0; i < selectedKeywords.size(); i++) { if (i != 0) { stringRepresentationBuilder.append(" "); } String keyword = selectedKeywords.get(i); if (keyword.contains(" ")) { stringRepresentationBuilder.append("\"" + selectedKeywords.get(i) + "\""); } else { stringRepresentationBuilder.append(selectedKeywords.get(i)); } stringRepresentationBuilder.append(","); stringRepresentationBuilder.append(reliability); } } else { } } else { List<String> subCmds = ParsingUtils.tokenizeDirectiveCall(data); for (String subCmd : subCmds) { String[] tokens = subCmd.split(","); String strCharacters = tokens[0]; String strReliability = tokens[1]; List<Character> characters = new ArrayList<Character>(); IntRange charRange = ParsingUtils.parseIntRange(strCharacters); if (charRange != null) { for (int index : charRange.toArray()) { characters.add(dataset.getCharacter(index)); } } else { characters = context.getCharactersForKeyword(strCharacters); } float reliability = Float.parseFloat(strReliability); for (Character ch : characters) { reliabilitiesMap.put(ch, reliability); } } stringRepresentationBuilder.append(data); } SetReliabilitiesDirectiveInvocation invoc = new SetReliabilitiesDirectiveInvocation(reliabilitiesMap); invoc.setStringRepresentation(stringRepresentationBuilder.toString()); return invoc; }