List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:de.avanux.livetracker.mobile.LocationReceiver.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *///from ww w . j a va 2 s . co m protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String trackingID = request.getParameter(LocationMessage.TRACKING_ID); String lat = request.getParameter(LocationMessage.LAT); String lon = request.getParameter(LocationMessage.LON); String time = request.getParameter(LocationMessage.TIME); String speed = request.getParameter(LocationMessage.SPEED); if ((trackingID != null) && (lat != null) && (lon != null) && (time != null) && (speed != null)) { PrintWriter out = null; try { LocationMessage locationMessage = new LocationMessage(Integer.parseInt(trackingID), new DateTime(Long.parseLong(time)), Float.parseFloat(lat), Float.parseFloat(lon), Float.parseFloat(speed)); log.debug(locationMessage.getTrackingID() + " Location message received: " + locationMessage); Tracking tracking = TrackingManager.getTracking(locationMessage.getTrackingID()); tracking.setLocationMessage(locationMessage); out = response.getWriter(); Properties configuration = buildResponse(tracking); configuration.store(out, null); } catch (Exception e) { log.error("Error receiving location message:", e); } finally { if (out != null) { out.close(); } } } else { log.error("Incomplete location message ignored."); } }
From source file:account.management.controller.ProjectReportController.java
/** * Initializes the controller class.//from ww w .jav a 2 s . c o m */ @Override public void initialize(URL url, ResourceBundle rb) { new AutoCompleteComboBoxListener<>(select_project); select_project.setOnHiding((e) -> { Project a = select_project.getSelectionModel().getSelectedItem(); select_project.setEditable(false); select_project.getSelectionModel().select(a); }); select_project.setOnShowing((e) -> { select_project.setEditable(true); }); project = FXCollections.observableArrayList(); new Thread(() -> { try { HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/project/all").asJson(); JSONArray array = res.getBody().getArray(); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); long id = obj.getLong("id"); String name = obj.getString("name"); String investment = String.valueOf(Float.parseFloat(obj.getString("investment"))); String party = obj.getString("related_party"); String operation_date = obj.getString("operation_date"); String start_date = obj.getString("starting_date"); String dimilish_date = obj.getString("dimilish_date"); project.add(new Project(String.valueOf(id), name, investment, party, start_date, operation_date, dimilish_date)); } } catch (UnirestException ex) { Logger.getLogger(LCReportController.class.getName()).log(Level.SEVERE, null, ex); } finally { this.select_project.getItems().addAll(project); } }).start(); }
From source file:com.cloudera.oryx.rdf.computation.WineQualityIT.java
private static List<Example> readWineQualityExamples() throws IOException { List<Example> allExamples = Lists.newArrayList(); Pattern delimiter = Pattern.compile(";"); File dataFile = new File(TEST_TEMP_INBOUND_DIR, "winequality-white.csv"); for (CharSequence line : new FileLineIterable(dataFile)) { if (line.length() == 0) { continue; }/* ww w .j a va 2 s. com*/ String[] tokens = delimiter.split(line); Feature[] features = new Feature[11]; for (int i = 0; i < features.length; i++) { features[i] = NumericFeature.forValue(Float.parseFloat(tokens[i])); } Example trainingExample = new Example(NumericFeature.forValue(Float.parseFloat(tokens[11])), features); allExamples.add(trainingExample); } return allExamples; }
From source file:com.google.jenkins.flakyTestHandler.junit.FlakyCaseResult.java
private static float parseTime(Element testCase) { String time = testCase.attributeValue("time"); if (time != null) { time = time.replace(",", ""); try {//from ww w . j ava2 s. c om return Float.parseFloat(time); } catch (NumberFormatException e) { try { return new DecimalFormat().parse(time).floatValue(); } catch (ParseException x) { // hmm, don't know what this format is. } } } return 0.0f; }
From source file:com.arubadesignweb.app.appoverview.util.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();//from w w w .ja va 2 s . c o m GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (extras.getString("radius") != null && Float.parseFloat(extras.getString("radius")) != 0 && extras.getString("latitude") != null && extras.getString("longitude") != null) { Log.e(TAG, extras.toString()); String target_latitude = extras.getString("latitude"); String target_longitude = extras.getString("longitude"); double target_radius = Double.parseDouble(extras.getString("radius")) * 1000; Location target_location = new Location("target"); target_location.setLatitude(Double.parseDouble(target_latitude)); target_location.setLongitude(Double.parseDouble(target_longitude)); Log.e(TAG, "TargetLocation: " + target_location); if (CommonUtilities.isInsideLocation(this, null, target_location, target_radius)) { Log.e(TAG, "isInsideRegion, send push notification"); sendNotificationSuccess(extras); } else { addProximityAlert(extras, target_location, target_radius); } } else { Log.e("NORMAL", "normal notif"); if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotificationSuccess(extras); Log.i(TAG, "Received: " + extras.toString()); } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:br.com.blackhubos.commandteleporter.Framework.java
public static Location toLocation(final String serial) { final Pattern pattern = Pattern.compile( "^World\\s*\\[([a-zA-Z0-9_-]+)\\]\\s*X\\s*\\[([0-9-]+)\\]\\s*Y\\s*\\[([0-9-]+)\\]\\s*Z\\s*\\[([0-9-]+)\\](\\s*Yaw\\s*\\[([0-9-\\.]+)\\]\\s*Pitch\\s*\\[([0-9-\\.]+)\\])?"); final Matcher m = pattern.matcher(serial); if (m.matches()) { if ((m.groupCount() >= 5) && (m.group(5) != null) && (m.group(6) != null) && (m.group(7) != null)) { return new Location(Framework.getWorld(m.group(1)), Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3)), Integer.parseInt(m.group(4)), Float.parseFloat(m.group(6)), Float.parseFloat(m.group(7))); } else {//from w w w .j a v a 2s .co m return new Location(Framework.getWorld(m.group(1)), Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3)), Integer.parseInt(m.group(4))); } } else { return null; } }
From source file:com.apress.prospringintegration.customadapters.inbound.pollerdriven.StockPollingMessageSource.java
protected Stock getStockInformationFor(final String symbol) { String url = String.format(this.stockServiceUrl, symbol); Stock stock = restTemplate.execute(url, HttpMethod.GET, null, new ResponseExtractor<Stock>() { @Override//from w ww . j a va2s. c o m public Stock extractData(ClientHttpResponse clientHttpResponse) throws IOException { String fragPattern = String.format(jsonFragmentTemplate, symbol, symbol); String bodyAsText = IOUtils.toString(clientHttpResponse.getBody()); int indexOfMatch = bodyAsText.indexOf(fragPattern); if (indexOfMatch != -1) { String sectionContainingPrice = bodyAsText.substring(indexOfMatch); Matcher matcher = symbolSize.matcher(sectionContainingPrice); StringBuilder stringBuilder = new StringBuilder(); while (matcher.find()) { stringBuilder.append(matcher.group(1)).append(".").append(matcher.group(2)); } String response = stringBuilder.toString(); Float fl = Float.parseFloat(response); return new Stock(symbol, fl); } return null; } }); return stock; }
From source file:com.alvermont.terraj.fracplanet.io.ColourFile.java
private static FloatRGBA parseColour(String line) throws IOException { final StringTokenizer tok = new StringTokenizer(line, ","); if (tok.countTokens() != 3) { throw new IOException("Line should be in the form x,y,z: " + line); }/*from www . j ava 2 s . c o m*/ final float[] floats = new float[3]; for (int b = 0; b < 3; ++b) floats[b] = Float.parseFloat(tok.nextToken().trim()); return new FloatRGBA(floats[0], floats[1], floats[2]); }
From source file:gaffer.accumulo.splitpoints.EstimateSplitPointsDriver.java
@Override public int run(String[] args) throws Exception { if (args.length < 5) { System.err.println("Usage: " + this.getClass().getName() + " <mapred_output_directory> <proportion_to_sample> <number_of_tablet_servers> <resulting_split_file> <input_path1>..."); return 1; }// w w w. j a v a 2s.co m // Parse arguments Path outputPath = new Path(args[0]); float proportionToSample = Float.parseFloat(args[1]); int numberTabletServers = Integer.parseInt(args[2]); Path resultingSplitsFile = new Path(args[3]); Path[] inputPaths = new Path[args.length - 4]; for (int i = 0; i < inputPaths.length; i++) { inputPaths[i] = new Path(args[i + 4]); } // Conf and job Configuration conf = getConf(); conf.setFloat("proportion_to_sample", proportionToSample); String jobName = "Estimate split points: input = "; for (int i = 0; i < inputPaths.length; i++) { jobName += inputPaths[i] + ", "; } jobName += "output = " + outputPath; Job job = Job.getInstance(conf, jobName); job.setJarByClass(getClass()); // Input job.setInputFormatClass(SequenceFileInputFormat.class); for (int i = 0; i < inputPaths.length; i++) { SequenceFileInputFormat.addInputPath(job, inputPaths[i]); } // Mapper job.setMapperClass(EstimateSplitPointsMapper.class); job.setMapOutputKeyClass(Key.class); job.setMapOutputValueClass(Value.class); // Reducer job.setReducerClass(EstimateSplitPointsReducer.class); job.setOutputKeyClass(Key.class); job.setOutputValueClass(Value.class); job.setNumReduceTasks(1); // Output job.setOutputFormatClass(SequenceFileOutputFormat.class); SequenceFileOutputFormat.setOutputPath(job, outputPath); SequenceFileOutputFormat.setCompressOutput(job, true); SequenceFileOutputFormat.setOutputCompressorClass(job, GzipCodec.class); SequenceFileOutputFormat.setOutputCompressionType(job, CompressionType.BLOCK); // Run job job.waitForCompletion(true); // Successful? if (!job.isSuccessful()) { System.err.println("Error running job"); return 1; } // Number of records output // NB In the following line use mapred.Task.Counter.REDUCE_OUTPUT_RECORDS rather than // mapreduce.TaskCounter.REDUCE_OUTPUT_RECORDS as this is more compatible with earlier // versions of Hadoop. @SuppressWarnings("deprecation") Counter counter = job.getCounters() .findCounter(org.apache.hadoop.mapred.Task.Counter.REDUCE_OUTPUT_RECORDS); long recordsOutput = counter.getValue(); System.out.println("Number of records output = " + recordsOutput); // Work out when to output a split point. The number of split points // needed is the number of tablet servers minus 1 (because you don't // have to output the start of the first tablet or the end of the // last tablet). long outputEveryNthRecord = recordsOutput / (numberTabletServers - 1); // Read through resulting file, pick out the split points and write to // file. FileSystem fs = FileSystem.get(conf); Path resultsFile = new Path(outputPath, "part-r-00000"); @SuppressWarnings("deprecation") SequenceFile.Reader reader = new SequenceFile.Reader(fs, resultsFile, conf); PrintStream splitsWriter = new PrintStream(new BufferedOutputStream(fs.create(resultingSplitsFile, true))); Key key = new Key(); Value value = new Value(); long count = 0; int numberSplitPointsOutput = 0; while (reader.next(key, value) && numberSplitPointsOutput < numberTabletServers - 1) { count++; if (count % outputEveryNthRecord == 0) { numberSplitPointsOutput++; splitsWriter.println(new String(Base64.encodeBase64(key.getRow().getBytes()))); System.out.println("Written split point: " + key.getRow()); } } reader.close(); splitsWriter.close(); System.out.println("Number of split points output = " + numberSplitPointsOutput); return 0; }
From source file:com.thoughtworks.go.legacywrapper.TestSuiteExtractor.java
private BuildTestSuite createSingleTestSuite(Attributes attributes) { String name = attributes.getValue("name"); float duration = Float.parseFloat(StringUtils.defaultString(attributes.getValue("time"), "0.0")); int tests = Integer.parseInt(StringUtils.defaultString(attributes.getValue("tests"), "0")); int failures = Integer.parseInt(StringUtils.defaultString(attributes.getValue("failures"), "0")); int errors = Integer.parseInt(StringUtils.defaultString(attributes.getValue("errors"), "0")); return new BuildTestSuite(name, duration); }