List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:org.cellcore.code.engine.page.extractor.mcc.MCCPageDataExtractor.java
@Override protected int getStock(Document doc) { Elements tr = doc.select("#blockContent").get(5).select("tr"); float iPrice = Float.MAX_VALUE; int iStock = 0; for (int i = 0; i < tr.size(); i++) { try {/*from w w w . j a va 2 s . c o m*/ String val = tr.get(i).getElementsByTag("td").get(3).childNodes().get(0).attr("text"); String stockV = tr.get(i).getElementsByTag("td").get(4).select("option").last().childNodes().get(0) .attr("text"); val = cleanPriceString(val); float price = Float.parseFloat(val); if (price < iPrice) { iPrice = price; iStock = Integer.parseInt(stockV.replaceAll("\\(", "").replaceAll("\\)", "")); } } catch (Throwable t) { } } return iStock; }
From source file:com.phonegap.accelerometer.Accelerometer.java
public PluginResult execute(String action, JSONArray args, String calbackId) { PluginResult result = null;/*w ww . j a v a 2 s.co m*/ if (!AccelerometerSensor.isSupported()) { result = new PluginResult(PluginResult.Status.ILLEGALACCESSEXCEPTION, "Accelerometer sensor not supported"); } else if (ACTION_GET_ACCELERATION.equals(action)) { JSONObject accel = new JSONObject(); try { AccelerometerData accelData = getCurrentAcceleration(); accel.put("x", (int) accelData.getLastXAcceleration()); accel.put("y", (int) accelData.getLastYAcceleration()); accel.put("z", (int) accelData.getLastZAcceleration()); accel.put("timestamp", accelData.getLastTimestamp()); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSONEXCEPTION, "JSONException:" + e.getMessage()); } result = new PluginResult(PluginResult.Status.OK, accel); } else if (ACTION_GET_TIMEOUT.equals(action)) { float f = this.getTimeout(); return new PluginResult(PluginResult.Status.OK, Float.toString(f)); } else if (ACTION_SET_TIMEOUT.equals(action)) { try { float t = Float.parseFloat(args.getString(0)); this.setTimeout(t); return new PluginResult(PluginResult.Status.OK, ""); } catch (NumberFormatException e) { return new PluginResult(PluginResult.Status.ERROR, e.getMessage()); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSONEXCEPTION, e.getMessage()); } } else if (ACTION_STOP.equals(action)) { this.stop(); return new PluginResult(PluginResult.Status.OK, ""); } else { result = new PluginResult(PluginResult.Status.INVALIDACTION, "Accelerometer: Invalid action:" + action); } return result; }
From source file:net.landora.video.mplayer.MPlayerParser.java
public Video handleFile(File f) { try {/*from w w w . j av a 2 s . co m*/ MPlayerInfoParse info = mplayerIdentify(f, null, null, null); detectTracks(info); file = new Video(); file.setFile(f); String length = info.getSingle("LENGTH"); if (length != null) { file.setLength(Float.parseFloat(length)); } while (!videoTracks.isEmpty() || !audioTracks.isEmpty() || !subtitleTracks.isEmpty()) { doPass(f); } return file; } catch (Exception e) { return null; } }
From source file:mase.vrep.VRepProblem.java
@Override public void setup(EvolutionState state, Parameter base) { super.setup(state, base); this.out = state.output; timeout = state.parameters.getInt(base.push(P_TIMEOUT), defaultBase().push(P_TIMEOUT)); retryDelay = state.parameters.getInt(base.push(P_RETRY_DELAY), defaultBase().push(P_RETRY_DELAY)); allowedFaults = state.parameters.getInt(base.push(P_ALLOWED_FAULTS), defaultBase().push(P_ALLOWED_FAULTS)); String gp = state.parameters.getString(base.push(P_GLOBALPAR), defaultBase().push(P_GLOBALPAR)); String[] values = gp.split("[\\;\\,]"); globalParams = new float[values.length]; for (int i = 0; i < values.length; i++) { globalParams[i] = Float.parseFloat(values[i]); }//from w w w .ja v a2 s.com int basePort = state.parameters.getInt(base.push(P_BASE_PORT), defaultBase().push(P_BASE_PORT)); // TODO: the configuration of the workers should be better, to allow for different baseports, etc String workers = state.parameters.getString(base.push(P_WORKERS), defaultBase().push(P_WORKERS)); String[] ips = workers.split("[;,]"); String[] remoteIps = new String[ips.length]; int[] remoteInstances = new int[ips.length]; for (int i = 0; i < ips.length; i++) { String[] split = ips[i].split("[\\-\\:]"); remoteIps[i] = split[0]; remoteInstances[i] = Integer.parseInt(split[1]); } VRepComm.terminateAll(); for (int r = 0; r < remoteIps.length; r++) { for (int i = 0; i < remoteInstances[r]; i++) { VRepClient c = new VRepClient(remoteIps[r], basePort + i); allClients.add(c); } } }
From source file:edu.teco.smartlambda.container.docker.HttpHijackingWorkaround.java
/** * Get a output stream that can be used to write into the standard input stream of docker container's running process * * @param stream the docker container's log stream * @param uri the URI to the docker socket * * @return a writable byte channel that can be used to write into the http web-socket output stream * * @throws Exception on any docker or reflection exception *///from w ww. j ava2s . co m static OutputStream getOutputStream(final LogStream stream, final String uri) throws Exception { // @formatter:off final String[] fields = new String[] { "reader", "stream", "original", "input", "in", "in", "in", "eofWatcher", "wrappedEntity", "content", "in", "instream" }; final String[] containingClasses = new String[] { "com.spotify.docker.client.DefaultLogStream", LogReader.class.getName(), "org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream", EntityInputStream.class.getName(), FilterInputStream.class.getName(), FilterInputStream.class.getName(), FilterInputStream.class.getName(), EofSensorInputStream.class.getName(), HttpEntityWrapper.class.getName(), BasicHttpEntity.class.getName(), IdentityInputStream.class.getName(), SessionInputBufferImpl.class.getName() }; // @formatter:on final List<String[]> fieldClassTuples = new LinkedList<>(); for (int i = 0; i < fields.length; i++) { fieldClassTuples.add(new String[] { containingClasses[i], fields[i] }); } if (uri.startsWith("unix:")) { fieldClassTuples.add(new String[] { ChannelInputStream.class.getName(), "ch" }); } else if (uri.startsWith("https:")) { final float jvmVersion = Float.parseFloat(System.getProperty("java.specification.version")); fieldClassTuples .add(new String[] { "sun.security.ssl.AppInputStream", jvmVersion < 1.9f ? "c" : "socket" }); } else { fieldClassTuples.add(new String[] { "java.net.SocketInputStream", "socket" }); } final Object res = getInternalField(stream, fieldClassTuples); if (res instanceof WritableByteChannel) { return Channels.newOutputStream((WritableByteChannel) res); } else if (res instanceof Socket) { return ((Socket) res).getOutputStream(); } else { throw new AssertionError("Expected " + WritableByteChannel.class.getName() + " or " + Socket.class.getName() + " but found: " + res.getClass().getName()); } }
From source file:org.cellcore.code.engine.page.extractor.mb.MBPageDataExtractor.java
@Override protected int getStock(Document doc) { if (!doc.getElementsContainingText("Cette carte n'est pas disponible en stock").isEmpty()) { return 0; }/*from w w w . ja va 2s. c o m*/ Elements tr = doc.select(".stock").get(0).getElementsByTag("tr"); float iPrice = Float.MAX_VALUE; int iStock = 0; for (int i = 1; i < tr.size(); i++) { String val = tr.get(i).getElementsByTag("td").get(3).childNodes().get(0).attr("text"); String stockV = tr.get(i).getElementsByTag("td").get(4).childNodes().get(1).attr("text"); val = cleanPriceString(val); float price = Float.parseFloat(val); if (price < iPrice) { iPrice = price; iStock = Integer.parseInt(stockV.replaceAll("\\(", "").replaceAll("\\)", "")); } } return iStock; }
From source file:io.galeb.router.handlers.completionListeners.AccessLogCompletionListener.java
@Override public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) { try {//from w w w . j a v a 2 s.c om final String remoteAddr = remoteIp().readAttribute(exchange); // %a final String host = localServerName().readAttribute(exchange); // %v final String requestElements[] = requestList().readAttribute(exchange).split(" "); // %r final String method = exchange.getRequestMethod().toString(); final String requestUri = exchange.getRequestURI(); final String proto = exchange.getProtocol().toString(); final String refer = requestElements.length > 3 ? requestElements[3] : null; final String xMobileGroup = requestElements.length > 4 ? requestElements[4] : null; final int originalStatusCode = Integer.parseInt(responseCode().readAttribute(exchange)); // %s final long responseBytesSent = exchange.getResponseBytesSent(); final String bytesSent = Long.toString(responseBytesSent); // %B final String bytesSentOrDash = responseBytesSent == 0L ? "-" : bytesSent; // %b final Integer responseTime = Math .round(Float.parseFloat(responseTimeAttribute.readAttribute(exchange))); // %D final String realDestAttached = exchange.getAttachment(HostSelector.REAL_DEST); final String realDest = extractUpstreamField(exchange.getResponseHeaders(), realDestAttached); final String userAgent = requestHeader(Headers.USER_AGENT).readAttribute(exchange); // %{i,User-Agent} final String requestId = !"".equals(REQUESTID_HEADER) ? requestHeader(RequestIDHandler.requestIdHeader()).readAttribute(exchange) : null; // %{i,?REQUEST_ID?} final String xForwardedFor = requestHeader(Headers.X_FORWARDED_FOR).readAttribute(exchange); // %{i,X-Forwarded-For} final int fakeStatusCode = getFakeStatusCode(realDestAttached, originalStatusCode, responseBytesSent, responseTime, MAX_REQUEST_TIME); final int statusCode = fakeStatusCode != ProcessorLocalStatusCode.NOT_MODIFIED ? fakeStatusCode : originalStatusCode; final String message = remoteAddr + TAB + host + TAB + method + TAB + requestUri + TAB + proto + TAB + (refer != null ? refer : "-") + TAB + (xMobileGroup != null ? xMobileGroup : "-") + TAB + "Local:" + TAB + statusCode + TAB + "*-" + TAB + bytesSent + TAB + responseTime + TAB + "Proxy:" + TAB + realDest + TAB + statusCode + TAB + "-" + TAB + bytesSentOrDash + TAB + "-" + TAB + "-" + TAB + "Agent:" + TAB + (userAgent != null ? userAgent : "-") + (requestId != null ? TAB + requestId : "") + TAB + "Fwd:" + TAB + (xForwardedFor != null ? xForwardedFor : "-") + TAB + "tags: " + TAGS; logger.info(message); } catch (Exception e) { logger.error(ExceptionUtils.getStackTrace(e)); } finally { nextListener.proceed(); } }
From source file:com.signavio.warehouse.business.util.jpdl4.Transition.java
public Transition(JSONObject transition) { this.dockers = new ArrayList<Docker>(); try {//from w w w . j a va 2 s. co m this.name = transition.getJSONObject("properties").getString("name"); } catch (JSONException e) { } try { this.condition = transition.getJSONObject("properties").getString("conditionexpression"); } catch (JSONException e) { } try { this.target = JsonToJpdl.getInstance() .getTargetName(transition.getJSONObject("target").getString("resourceId")); } catch (JSONException e) { } try { JSONArray dockerArray = transition.getJSONArray("dockers"); // Create path dockers. Start and end will be ignored. if (dockerArray.length() > 2) for (int i = 1; i < dockerArray.length() - 1; i++) { try { JSONObject docker = dockerArray.getJSONObject(i); int x = Math.round(Float.parseFloat(docker.getString("x"))); int y = Math.round(Float.parseFloat(docker.getString("y"))); dockers.add(new Docker(x, y)); } catch (JSONException e) { } } } catch (JSONException f) { } }
From source file:com.idean.atthack.api.Param.java
/** * Put value into bundle using the appropriate type for the value *//*w w w . j a va 2s.c o m*/ public void putBundleAsTypedVal(Bundle bundle, String val) { if (TextUtils.isEmpty(val)) { return; } try { switch (type) { case BOOLEAN: bundle.putBoolean(name(), Boolean.parseBoolean(val)); break; case FLOAT: bundle.putFloat(name(), Float.parseFloat(val)); break; case INTEGER: bundle.putFloat(name(), Integer.parseInt(val)); break; case STRING: bundle.putString(name(), val); break; default: throw new UnsupportedOperationException(); } } catch (Exception e) { Log.w(TAG, "Unable to put value into bundle " + this + ", val: " + val); } }
From source file:edu.indiana.d2i.datacatalog.dashboard.api.USStates.java
public static String getStates(String statesFilePath) throws ParserConfigurationException, IOException, SAXException { JSONObject statesFeatureCollection = new JSONObject(); statesFeatureCollection.put("type", "FeatureCollection"); JSONArray features = new JSONArray(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {/*from w w w .j av a 2s . c om*/ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document dom = documentBuilder.parse(new FileInputStream(new File(statesFilePath))); Element docElement = dom.getDocumentElement(); NodeList states = docElement.getElementsByTagName("state"); for (int i = 0; i < states.getLength(); i++) { Node state = states.item(i); JSONObject stateObj = new JSONObject(); stateObj.put("type", "Feature"); JSONObject geometry = new JSONObject(); geometry.put("type", "Polygon"); JSONArray coordinates = new JSONArray(); JSONArray coordinateSub = new JSONArray(); NodeList points = ((Element) state).getElementsByTagName("point"); for (int j = 0; j < points.getLength(); j++) { Node point = points.item(j); JSONArray pointObj = new JSONArray(); float lat = Float.parseFloat(((Element) point).getAttribute("lat")); float lng = Float.parseFloat(((Element) point).getAttribute("lng")); double trLng = lng * 20037508.34 / 180; double trLat = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); pointObj.add(lng); pointObj.add(lat); coordinateSub.add(pointObj); } geometry.put("coordinates", coordinates); coordinates.add(coordinateSub); stateObj.put("geometry", geometry); JSONObject name = new JSONObject(); name.put("Name", ((Element) state).getAttribute("name")); name.put("colour", "#FFF901"); stateObj.put("properties", name); features.add(stateObj); } statesFeatureCollection.put("features", features); return statesFeatureCollection.toJSONString(); } catch (ParserConfigurationException e) { log.error("Error while processing states.xml.", e); throw e; } catch (FileNotFoundException e) { log.error("Error while processing states.xml.", e); throw e; } catch (SAXException e) { log.error("Error while processing states.xml.", e); throw e; } catch (IOException e) { log.error("Error while processing states.xml.", e); throw e; } }