List of usage examples for java.lang Double toString
public String toString()
From source file:org.mifos.androidclient.main.DepositDueDetailsActivity.java
private void updateContent(SavingsAccountDepositDue details) { mDetails = details;/* w ww . jav a 2 s. co m*/ TextView cell; Double nextDeposit, pastDepositAmount, pastDepositsSum = 0.0; cell = (TextView) findViewById(R.id.depositDueDetails_nextDeposit); nextDeposit = details.getNextDueDetail().getDueAmount(); cell.setText(nextDeposit.toString()); if (ValueUtils.hasElements(details.getPreviousDueDetails())) { TableLayout table = (TableLayout) findViewById(R.id.depositDueDetails_table); View view = findViewById(R.id.depositDueDetails_rowInsertPoint); int index = table.indexOfChild(view) + 1; view = findViewById(R.id.depositDueDetails_subTotal_label); TableLayoutHelper helper = new TableLayoutHelper(this, TableLayoutHelper.DEFAULT_TABLE_ROW_SEPARATOR_HEIGHT, view.getPaddingLeft(), view.getPaddingRight()); for (DueOnDate pastDeposit : details.getPreviousDueDetails()) { if (pastDeposit.getDueDate().before(details.getNextDueDetail().getDueDate())) { TableRow row = helper.createTableRow(); cell = helper.createTableCell(DateUtils.format(pastDeposit.getDueDate()), 1); row.addView(cell); pastDepositAmount = pastDeposit.getDueAmount(); cell = helper.createTableCell(pastDepositAmount.toString(), 2); row.addView(cell); table.addView(row, index); index++; table.addView(helper.createRowSeparator(), index); index++; pastDepositsSum += pastDepositAmount; } } } cell = (TextView) findViewById(R.id.depositDueDetails_subTotal); cell.setText(pastDepositsSum.toString()); cell = (TextView) findViewById(R.id.depositDueDetails_totalAmountDue_label); cell.setText(cell.getText() + DateUtils.format(details.getNextDueDetail().getDueDate())); cell = (TextView) findViewById(R.id.depositDueDetails_totalAmountDue); cell.setText(Double.toString(pastDepositsSum + nextDeposit)); }
From source file:com.esri.geoevent.test.tools.RunTcpInTcpOutTest.java
public void send(String server, Integer port, Long numEvents, Integer rate) { Random rnd = new Random(); BufferedReader br = null;/*from w w w . j a v a2 s.c o m*/ LocalDateTime st = null; try { Socket sckt = new Socket(server, port); OutputStream os = sckt.getOutputStream(); //PrintWriter sckt_out = new PrintWriter(os, true); Integer cnt = 0; st = LocalDateTime.now(); Double ns_delay = 1000000000.0 / (double) rate; long ns = ns_delay.longValue(); if (ns < 0) { ns = 0; } while (cnt < numEvents) { cnt += 1; LocalDateTime ct = LocalDateTime.now(); String dtg = ct.toString(); Double lat = 180 * rnd.nextDouble() - 90.0; Double lon = 360 * rnd.nextDouble() - 180.0; String line = "RandomPoint," + cnt.toString() + "," + dtg + ",\"" + lon.toString() + "," + lat.toString() + "\"," + cnt.toString() + "\n"; final long stime = System.nanoTime(); long etime = 0; do { etime = System.nanoTime(); } while (stime + ns >= etime); if (cnt % 1000 == 0) { //System.out.println(cnt); } //sckt_out.write(line); os.write(line.getBytes()); os.flush(); } if (st != null) { LocalDateTime et = LocalDateTime.now(); Duration delta = Duration.between(st, et); Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0; send_rate = (double) numEvents / elapsed_seconds; } //sckt_out.close(); sckt.close(); os = null; //sckt_out = null; } catch (Exception e) { System.err.println(e.getMessage()); send_rate = -1.0; } finally { try { br.close(); } catch (Exception e) { // } this.send_rate = send_rate; } }
From source file:org.aicer.hibiscus.http.client.HttpClient.java
/** * Used by Entity-Enclosing HTTP Requests to send Name-Value pairs in the body of the request * * @param param Name of Parameter/*ww w. ja va2s. co m*/ * @param value Value of Parameter * @return */ public final HttpClient addNameValuePair(final String param, final Double value) { return addNameValuePair(param, value.toString()); }
From source file:com.impala.servlet.Balance.java
/** * //ww w .ja v a2 s . c o m * @param request * @return * @throws IOException */ private String moneytransfer(HttpServletRequest request) throws IOException, JSONException { // joined json string String join = ""; JsonElement root = null; JsonElement root2 = null; JsonElement root3 = null; String responseobject = ""; String nickname = "KENDYIPL"; // These represent parameters received over the network String referenceid = "", customermsisdn = "", amount = "", batchref = "", username = "", password = "", narrative = ""; //referenceid, customermsisdn, nickname,amount, batchref, username, password, narrative // Get all parameters, the keys of the parameters are specified List<String> lines = IOUtils.readLines(request.getReader()); // used to format/join incoming JSon string join = StringUtils.join(lines.toArray(), ""); //############################################################################### // instantiate the JSon //Note //The = sign is encoded to \u003d. Hence you need to use disableHtmlEscaping(). //############################################################################### Gson g = new GsonBuilder().disableHtmlEscaping().create(); //Gson g = new Gson(); Map<String, String> expected = new HashMap<>(); try { // parse the JSon string //referenceid, customermsisdn, nickname,amount, batchref, username, password, narrative root = new JsonParser().parse(join); password = root.getAsJsonObject().get("password").getAsString(); username = root.getAsJsonObject().get("username").getAsString(); } catch (Exception e) { expected.put("command_status", "COMMANDSTATUS_INVALID_PARAMETERS"); String jsonResult = g.toJson(expected); System.out.println(e); return jsonResult; } // check for the presence of all required parameters if (StringUtils.isBlank(nickname) || StringUtils.isBlank(password) || StringUtils.isBlank(username)) { expected.put("username", username); expected.put("status_code", statuscode); expected.put("status_description", Statusdescription); String jsonResult = g.toJson(expected); return jsonResult; } //assign the remit url from properties.config String processtransaction = airtelbalance.AirtelBalance(nickname, username, password); //capture the switch respoinse. System.out.println(processtransaction); //pass the returned json string JsonElement roots = new JsonParser().parse(processtransaction); //exctract a specific json element from the object(status_code) Double balance = roots.getAsJsonObject().get("CheckBalanceResult").getAsDouble(); //add expected.put("username", username); expected.put("balance", balance.toString()); String jsonResult = g.toJson(expected); return jsonResult; }
From source file:edu.umn.msi.tropix.proteomics.sequest.SequestBeanParameterTranslator.java
private String getDiffSearchString(final Double value, final String residues) { if (value == null || value.doubleValue() == 0.00d || residues == null || residues.equals("")) { return "0.0 X "; } else {//from w w w . java 2 s . c om return value.toString() + " " + residues + " "; } }
From source file:com.chinamobile.bcbsp.bspcontroller.HDFSOperator.java
/** * serialize the WorkerManager Status/*from ww w . ja v a 2 s .com*/ * @param uri * BSPfile output uri * @param wmlist * workerManager list * @param staffsLoadFactor * for load balancing * @throws IOException * exceptions during handle BSPfile. */ public void serializeWorkerManagerStatus(String uri, Collection<WorkerManagerStatus> wmlist, double staffsLoadFactor) throws IOException { // synchronized(HDFSOperator.class){ // this.fs = FileSystem.get(URI.create(uri),conf); // this.isFSExist(); Double loadfactor = staffsLoadFactor; // Path path = new Path(uri); // out = fs.create(path); bspout = new BSPFSDataOutputStreamImpl(uri, 1, conf); Text factor = new Text(loadfactor.toString()); // factor.write(out); // for (WorkerManagerStatus wmStatus : wmlist) { // wmStatus.write(out); // } // out.flush(); // out.close(); factor.write(bspout.getOut()); for (WorkerManagerStatus wmStatus : wmlist) { wmStatus.write(bspout.getOut()); } bspout.flush(); bspout.close(); // fs.close(); // } }
From source file:com.discover.cls.processors.cls.GeoEnrichEnriched.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();// w w w .jav a 2s .com if (flowFile == null) { return; } final DatabaseReader dbReader = databaseReaderRef.get(); final String ipAttributeName = context.getProperty(IP_ADDRESS_ATTRIBUTE) .evaluateAttributeExpressions(flowFile).getValue(); final String ipAttributeValue = flowFile.getAttribute(ipAttributeName); if (StringUtils.isEmpty(ipAttributeName)) { //TODO need to add additional validation - should look like an IPv4 or IPv6 addr for instance session.transfer(flowFile, REL_NOT_FOUND); getLogger().warn("Unable to find ip address for {}", new Object[] { flowFile }); return; } InetAddress inetAddress = null; CityResponse response = null; try { inetAddress = InetAddress.getByName(ipAttributeValue); } catch (final IOException ioe) { session.transfer(flowFile, REL_NOT_FOUND); getLogger().warn("Could not resolve {} to ip address for {}", new Object[] { ipAttributeValue, flowFile }, ioe); return; } final StopWatch stopWatch = new StopWatch(true); try { response = dbReader.city(inetAddress); stopWatch.stop(); } catch (final IOException | GeoIp2Exception ex) { session.transfer(flowFile, REL_NOT_FOUND); getLogger().warn("Failure while trying to find enrichment data for {} due to {}", new Object[] { flowFile, ex }, ex); return; } if (response == null) { session.transfer(flowFile, REL_NOT_FOUND); return; } final Map<String, String> attrs = new HashMap<>(); attrs.put(new StringBuilder(ipAttributeName).append(".geo.lookup.micros").toString(), String.valueOf(stopWatch.getDuration(TimeUnit.MICROSECONDS))); attrs.put(new StringBuilder(ipAttributeName).append(".geo.city").toString(), response.getCity().getName()); final Double latitude = response.getLocation().getLatitude(); if (latitude != null) { attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), latitude.toString()); } final Double longitude = response.getLocation().getLongitude(); if (longitude != null) { attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString()); } int i = 0; for (final Subdivision subd : response.getSubdivisions()) { attrs.put(new StringBuilder(ipAttributeName).append(".geo.subdivision.").append(i).toString(), subd.getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.subdivision.isocode.").append(i).toString(), subd.getIsoCode()); i++; } attrs.put(new StringBuilder(ipAttributeName).append(".geo.country").toString(), response.getCountry().getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.country.isocode").toString(), response.getCountry().getIsoCode()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.postalcode").toString(), response.getPostal().getCode()); flowFile = session.putAllAttributes(flowFile, attrs); session.transfer(flowFile, REL_FOUND); }
From source file:frk.gpssimulator.service.impl.DefaultGpsdService.java
@Override public void updatePosition(PositionInfo position) { // an NMEA RMC position sentence (report) is of form: // $GPRMC,124426,A,5920.7019,N,02803.2893,E,,,121212,, Calendar cal = Calendar.getInstance(); Integer hour = cal.get(Calendar.HOUR_OF_DAY); Integer minute = cal.get(Calendar.MINUTE); Integer second = cal.get(Calendar.SECOND); Integer date = cal.get(Calendar.DATE); Integer month = cal.get(Calendar.MONTH) + 1; // java Calendar month // starts at 0 Integer year = cal.get(Calendar.YEAR) % 100; // convert to 2 digit year String sHour = String.format("%02d", hour); String sMinute = String.format("%02d", minute); String sSecond = String.format("%02d", second); String sDate = String.format("%02d", date); String sMonth = String.format("%02d", month); String sYear = String.format("%02d", year); String sentence = null;/* w ww . j a v a 2 s .co m*/ if (position == null) { sentence = "$GPRMC," + sHour + sMinute + sSecond + ",A,,,,,,," + sDate + sMonth + sYear + ",,"; } else { double lat = position.getPosition().getLatitude(); double lon = position.getPosition().getLongitude(); String latSuffix = "N"; if (lat < 0) { latSuffix = "S"; } lat = Math.abs(lat); String lonSuffix = "E"; if (lon < 0) { lonSuffix = "W"; } lon = Math.abs(lon); long latDeg = (long) lat; // degree part double latMin = (lat - latDeg) * 60; // minute part long latMinWhole = (long) latMin; // whole part of minute Double latMinFrac = latMin - latMinWhole; // fractional part of // minute String sLatDeg = String.format("%02d", latDeg); String sLatMinWhole = String.format("%02d", latMinWhole); String sLatMinFrac = latMinFrac.toString().replace("0.", "."); long lonDeg = (long) lon; // degree part double lonMin = (lon - lonDeg) * 60; // minute part long lonMinWhole = (long) lonMin; // whole part of minute Double lonMinFrac = lonMin - lonMinWhole; // fractional part of // minute String sLonDeg = String.format("%02d", lonDeg); String sLonMinWhole = String.format("%02d", lonMinWhole); String sLonMinFrac = lonMinFrac.toString().replace("0.", "."); sentence = "$GPRMC," + sHour + sMinute + sSecond + ",A," + sLatDeg + sLatMinWhole + sLatMinFrac + "," + latSuffix + "," + sLonDeg + sLonMinWhole + sLonMinFrac + "," + lonSuffix + ",,," + sDate + sMonth + sYear + ",,"; } try { pipeWriter.write(sentence + "\r\n"); pipeWriter.flush(); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:de.loercher.localpress.core.api.LocalPressController.java
@RequestMapping(value = "/articles/new", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<String> getNewArticlesAround(@RequestParam Double lat, @RequestParam Double lon) throws InterruptedException, ExecutionException, JsonProcessingException { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(GEO_URL).queryParam("lat", lat.toString()) .queryParam("lon", lon.toString()); RestTemplate template = new RestTemplate(); List<Map<String, Object>> geoResponse = template.getForObject(builder.build().encode().toUri(), List.class); Iterator<Map<String, Object>> it = geoResponse.iterator(); List<Future<ResponseEntity<Map>>> jobs = new ArrayList<>(); // to be able to merge answers from rating to geoitems there is a need // to map the article to its articleID // (articleID) => (articleItem) Map<String, Map<String, Object>> mappedResponseObjects = new HashMap<>(); while (it.hasNext()) { Map<String, Object> item = it.next(); AsyncRestTemplate async = new AsyncRestTemplate(); Future<ResponseEntity<Map>> futureResult = async.getForEntity((String) item.get("rating"), Map.class); jobs.add(futureResult);/*w w w.ja va 2 s.c o m*/ mappedResponseObjects.put((String) item.get("articleID"), item); } for (Future<ResponseEntity<Map>> job : jobs) { Map<String, Object> ratingMap = job.get().getBody(); String articleID = (String) ratingMap.get("articleID"); mappedResponseObjects.get(articleID).putAll(ratingMap); } WeightingPolicy policy = new WeightingPolicyImpl(); List<Map<String, Object>> orderedResponse = policy.sortExcludingRating(mappedResponseObjects.values()); List<Map<String, Object>> result = new ResponseMapFilterImpl().filter(orderedResponse); return new ResponseEntity<>(objectMapper.writeValueAsString(result), HttpStatus.OK); }
From source file:de.loercher.localpress.core.api.LocalPressController.java
@RequestMapping(value = "/articles", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<String> getArticlesAround(@RequestParam Double lat, @RequestParam Double lon) throws InterruptedException, ExecutionException, JsonProcessingException { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(GEO_URL).queryParam("lat", lat.toString()) .queryParam("lon", lon.toString()); RestTemplate template = new RestTemplate(); List<Map<String, Object>> geoResponse = template.getForObject(builder.build().encode().toUri(), List.class); Iterator<Map<String, Object>> it = geoResponse.iterator(); List<Future<ResponseEntity<Map>>> jobs = new ArrayList<>(); // to be able to merge answers from rating to geoitems there is a need // to map the article to its articleID // (articleID) => (articleItem) Map<String, Map<String, Object>> mappedResponseObjects = new HashMap<>(); while (it.hasNext()) { Map<String, Object> item = it.next(); AsyncRestTemplate async = new AsyncRestTemplate(); Future<ResponseEntity<Map>> futureResult = async.getForEntity((String) item.get("rating"), Map.class); jobs.add(futureResult);//w w w .j a v a2s .co m mappedResponseObjects.put((String) item.get("articleID"), item); } for (Future<ResponseEntity<Map>> job : jobs) { Map<String, Object> ratingMap = job.get().getBody(); String articleID = (String) ratingMap.get("articleID"); if ((Boolean) ratingMap.get("appropriate")) { mappedResponseObjects.get(articleID).putAll(ratingMap); } else { mappedResponseObjects.remove(articleID); } } WeightingPolicy policy = new WeightingPolicyImpl(); List<Map<String, Object>> orderedResponse = policy.sortIncludingRating(mappedResponseObjects.values()); List<Map<String, Object>> result = new ResponseMapFilterImpl().filter(orderedResponse); return new ResponseEntity<>(objectMapper.writeValueAsString(result), HttpStatus.OK); }