List of usage examples for java.lang Double toString
public String toString()
From source file:us.mschmidt.komo.CalcEngine.java
/** * Performs the computations.//from w w w. ja v a 2s. c o m * * @param numStringA the displayed value * @param numStringB the stored value * @param opVal the operation to be performed * @return the solution as a string variable */ private String doComputation(final String numStringA, final String numStringB, final char opVal) { String valStringA = numStringA; String valStringB = numStringB; char opChar = opVal; Double valA = 0.0; Double valB = 0.0; Double valAnswer = 0.0; // Make sure register strings are numbers if (valStringA.length() > 0 && valStringB.length() > 0) { try { valA = Double.parseDouble(numStringA); valB = Double.parseDouble(numStringB); } catch (final NumberFormatException e) { return nanErr; } } else { return ""; } switch (opChar) { case '+': // Addition valAnswer = valA + valB; break; case '-': // Subtraction valAnswer = valA - valB; break; case '/': // Division valAnswer = valA / valB; break; case '*': // Multiplication valAnswer = valA * valB; break; default: // Do nothing - this should never happen break; } // Convert answer to properly formatted string. return trimString(valAnswer.toString()); }
From source file:eu.optimis.ecoefficiencytool.rest.client.EcoEfficiencyToolRESTClientIP.java
/** * Specifies the minimum eco-efficiency thresholds at infrastructure level. * If any of them are surpassed, a proactive notification will be generated. * Note that setting a value of -1.0 to any of the thresholds will disable * them (separately)./* w w w.j a v a2s . c o m*/ * @param energyEfficiencyTH Energy efficiency threshold. * @param ecologicalEfficiencyTH Ecological efficiency threshold. */ public void setInfrastructureEcoThreshold(Double energyEfficiencyTH, Double ecologicalEfficiencyTH) { try { WebResource resource = client.resource(this.getAddress()).path("proactive/infrastructure/setth"); if (energyEfficiencyTH != null) { resource = resource.queryParam("enEffTH", energyEfficiencyTH.toString()); } if (ecologicalEfficiencyTH != null) { resource = resource.queryParam("ecoEffTH", ecologicalEfficiencyTH.toString()); } resource.post(); } catch (UniformInterfaceException ex) { ClientResponse cr = ex.getResponse(); log.error(cr.getStatus()); ex.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:knop.psfj.FovDataSet.java
/** * Format value.// w w w. j ava 2 s . c o m * * @param d the d * @return the string */ protected String formatValue(Double d) { String s = d.toString(); if (s.endsWith(".0")) { return s.substring(0, s.length() - 2); } else { return new Double(DataTricks.round(d, 3)).toString(); } }
From source file:com.likethecolor.alchemy.api.entity.AlchemyEntityTest.java
@Test public void testLatitude_String() { final Double expectedLatitude = 35.123D; final String latitude = expectedLatitude.toString(); final AlchemyEntity entity = new AlchemyEntity(); entity.setLatitude(latitude);/*from ww w . ja v a 2 s . c o m*/ assertEquals(expectedLatitude, entity.getLatitude()); // null - should not change value entity.setLatitude(latitude); entity.setLatitude(null); assertEquals(expectedLatitude, entity.getLatitude()); // empty string - should not change value entity.setLatitude(latitude); entity.setLatitude(""); assertEquals(expectedLatitude, entity.getLatitude()); // empty white space string - should not change value entity.setLatitude(latitude); entity.setLatitude("\t \r\n "); assertEquals(expectedLatitude, entity.getLatitude()); // should be trimmed entity.setLatitude("\t \r\n \n\n" + latitude + " "); assertEquals(expectedLatitude, entity.getLatitude()); // non-number - should not change value entity.setLatitude(latitude); entity.setLatitude("foo"); assertEquals(expectedLatitude, entity.getLatitude()); }
From source file:com.likethecolor.alchemy.api.entity.AlchemyEntityTest.java
@Test public void testLongitude_String() { final Double expectedLongitude = -22.87D; final String longitude = expectedLongitude.toString(); final AlchemyEntity entity = new AlchemyEntity(); entity.setLongitude(longitude);//from w w w. j a va 2s. c om assertEquals(expectedLongitude, entity.getLongitude()); // null - should not change value entity.setLongitude(longitude); entity.setLongitude(null); assertEquals(expectedLongitude, entity.getLongitude()); // empty string - should not change value entity.setLongitude(longitude); entity.setLongitude(""); assertEquals(expectedLongitude, entity.getLongitude()); // empty white space string - should not change value entity.setLongitude(longitude); entity.setLongitude("\t \r\n "); assertEquals(expectedLongitude, entity.getLongitude()); // should be trimmed entity.setLongitude("\t \r\n \n\n" + longitude + " "); assertEquals(expectedLongitude, entity.getLongitude()); // non-number - should not change value entity.setLongitude(longitude); entity.setLongitude("foo"); assertEquals(expectedLongitude, entity.getLongitude()); }
From source file:org.obiba.onyx.jade.instrument.holologic.APEXScanDataExtractor.java
/** * Called by extractData(). Computes T- and Z-score and adds to data collection. * * @param data/*from w ww . j a v a2 s . co m*/ */ protected void computeTZScore(Map<String, Data> data) throws DataAccessException, IllegalArgumentException, ParseException { if (null == data || data.isEmpty()) return; Map<String, Double> bmdData = new HashMap<String, Double>(); String prefix = getResultPrefix() + "_"; String type = getRefType(); String source = getRefSource(); // AP lumbar spine: // - identify the included vertebral levels // - sum the area and sum the bmc of the included vertebral levels // - compute the revised total bmd from summed bmc / summed area // - provide the proper bone range code for total bmd // if (type.equals("S")) { boolean[] included_array = { false, false, false, false }; double[] area_array = { 0.0, 0.0, 0.0, 0.0 }; double[] bmc_array = { 0.0, 0.0, 0.0, 0.0 }; double tot_bmd = 0.0; for (Map.Entry<String, Data> entry : data.entrySet()) { String key = entry.getKey(); int index = -1; if (key.startsWith("L1")) { index = 0; } else if (key.startsWith("L2")) { index = 1; } else if (key.startsWith("L3")) { index = 2; } else if (key.startsWith("L4")) { index = 3; } if (-1 != index) { if (key.endsWith("_INCLUDED")) { included_array[index] = entry.getValue().getValue(); } else if (key.endsWith("_AREA")) { area_array[index] = entry.getValue().getValue(); } else if (key.endsWith("_BMC")) { bmc_array[index] = entry.getValue().getValue(); } } if (key.endsWith("_BMD")) { log.info("key pre: " + key + ", new key: " + key.replace(prefix, "")); key = key.replace(prefix, ""); if (key.equals("TOT_BMD")) { tot_bmd = entry.getValue().getValue(); } else { if (ranges.containsKey(key)) { bmdData.put(key, (Double) entry.getValue().getValue()); log.info("ranges contains key: " + key); } } } } double tot_area = 0.0; double tot_bmc = 0.0; for (int i = 0; i < 4; i++) { if (included_array[i]) { tot_area += area_array[i]; tot_bmc += bmc_array[i]; } } if (0. != tot_area) { double last_tot_bmd = tot_bmd; tot_bmd = tot_bmc / tot_area; log.info("updating ap lumbar spine total bmd from " + ((Double) last_tot_bmd).toString() + " to " + ((Double) tot_bmd).toString()); } String tot_key = "TOT_BMD"; if (included_array[0] && !(included_array[1] || included_array[2] || included_array[3])) { //_bonerange="1..." tot_key = "TOT_L1_BMD"; } else if (included_array[1] && !(included_array[0] || included_array[2] || included_array[3])) { // bonerange=".2.." tot_key = "TOT_L2_BMD"; } else if (included_array[2] && !(included_array[0] || included_array[1] || included_array[3])) { // bonerange="..3." tot_key = "TOT_L3_BMD"; } else if (included_array[3] && !(included_array[0] || included_array[1] || included_array[2])) { // bonerange="...4" tot_key = "TOT_L4_BMD"; } else if (included_array[0] && included_array[1] && !(included_array[2] || included_array[3])) { // bonerange="12.." tot_key = "TOT_L1L2_BMD"; } else if (included_array[0] && included_array[2] && !(included_array[1] || included_array[3])) { // bonerange="1.3." tot_key = "TOT_L1L3_BMD"; } else if (included_array[0] && included_array[3] && !(included_array[1] || included_array[2])) { // bonerange="1..4" tot_key = "TOT_L1L4_BMD"; } else if (included_array[1] && included_array[2] && !(included_array[0] || included_array[3])) { // bonerange=".23." tot_key = "TOT_L2L3_BMD"; } else if (included_array[1] && included_array[3] && !(included_array[0] || included_array[2])) { // bonerange=".2.4" tot_key = "TOT_L2L4_BMD"; } else if (included_array[2] && included_array[3] && !(included_array[0] || included_array[1])) { // bonerange="..34" tot_key = "TOT_L3L4_BMD"; } else if (included_array[0] && included_array[1] && included_array[2] && !included_array[3]) { // bonerange="123." tot_key = "TOT_L1L2L3_BMD"; } else if (included_array[0] && included_array[1] && included_array[3] && !included_array[2]) { // bonerange="12.4" tot_key = "TOT_L1L2L4_BMD"; } else if (included_array[0] && included_array[2] && included_array[3] && !included_array[1]) { // bonerange="1.34" tot_key = "TOT_L1L3L4_BMD"; } else if (included_array[1] && included_array[2] && included_array[3] && !included_array[0]) { // bonerange=".234" tot_key = "TOT_L2L3L4_BMD"; } else { // bonerange="1234" tot_key = "TOT_BMD"; } if (ranges.containsKey(tot_key)) { bmdData.put(tot_key, (Double) tot_bmd); log.info("ranges contains key: " + tot_key); } } else { for (Map.Entry<String, Data> entry : data.entrySet()) { String key = entry.getKey(); if (key.endsWith("_BMD")) { log.info("key pre: " + key + ", new key: " + key.replace(prefix, "")); key = key.replace(prefix, ""); if (ranges.containsKey(key)) { bmdData.put(key, (Double) entry.getValue().getValue()); log.info("ranges contains key: " + key); } } } } log.info(prefix + " data contains: " + Integer.toString(data.size()) + " possible entries to get bmd values from"); log.info(prefix + " bmddata contains: " + Integer.toString(bmdData.size()) + " entries to get tz"); DecimalFormat format = new DecimalFormat("#.0"); ageBracket bracket = new ageBracket(); // Determine the participant's age (at the time of the scan). // Double age = null; try { age = computeYearsDifference(getScanDate(), getParticipantDOB()); } catch (ParseException e) { throw e; } log.info("computed age from scandate and dob: " + age.toString()); for (Map.Entry<String, Double> entry : bmdData.entrySet()) { String bmdBoneRangeKey = entry.getKey(); Double bmdValue = entry.getValue(); log.info("working on range key:" + bmdBoneRangeKey + " with value: " + bmdValue.toString()); // T- and Z-scores are interpolated from X, Y reference curve data. // A curve depends on the type of scan, gender, ethnicity, and // the coded anatomic region that bmd was measured in. // Determine the unique curve ID along with the age at which // peak bmd occurs. Implementation of T-score assumes ethnicity is always Caucasian // and gender is always female in accordance with WHO and // Osteoporosis Canada guidelines. // String method = " AND METHOD IS NULL"; if (type.equals("S") && (bmdBoneRangeKey.contains("L1_") || bmdBoneRangeKey.contains("L4_"))) { method = " AND METHOD = 'APEX'"; } String sql = "SELECT UNIQUE_ID, AGE_YOUNG FROM ReferenceCurve"; sql += " WHERE REFTYPE = '" + type + "'"; sql += " AND IF_CURRENT = 1 AND SEX = 'F' AND ETHNIC IS NULL"; sql += method; sql += " AND SOURCE LIKE '%" + source + "%'"; sql += " AND Y_LABEL = 'IDS_REF_LBL_BMD'"; sql += " AND BONERANGE "; sql += (ranges.get(bmdBoneRangeKey).equals("NULL") ? ("IS NULL") : ("= '" + ranges.get(bmdBoneRangeKey) + "'")); log.info("first query (T score): " + sql); Map<String, Object> mapResult; try { mapResult = refCurveDb.queryForMap(sql); } catch (DataAccessException e) { throw e; } String curveId = mapResult.get("UNIQUE_ID").toString(); Double ageYoung = new Double(mapResult.get("AGE_YOUNG").toString()); // Determine the bmd, skewness factor and standard deviation // at the peak bmd age value. // sql = "SELECT Y_VALUE, L_VALUE, STD FROM Points WHERE UNIQUE_ID = " + curveId; sql += " AND X_VALUE = " + ageYoung; log.info("second query (T score): " + sql); mapResult.clear(); try { mapResult = refCurveDb.queryForMap(sql); } catch (DataAccessException e) { throw e; } List<Double> bmdValues = new ArrayList<Double>(); bmdValues.add(new Double(mapResult.get("Y_VALUE").toString())); bmdValues.add(new Double(mapResult.get("L_VALUE").toString())); bmdValues.add(new Double(mapResult.get("STD").toString())); Double X_value = bmdValue; Double M_value = bmdValues.get(0); Double L_value = bmdValues.get(1); Double sigma = bmdValues.get(2); Double T_score = M_value * (Math.pow(X_value / M_value, L_value) - 1.) / (L_value * sigma); T_score = Double.valueOf(format.format(T_score)); if (0. == Math.abs(T_score)) T_score = 0.; String varName = getResultPrefix() + "_"; if (type.equals("S") && bmdBoneRangeKey.startsWith("TOT_")) { varName += "TOT_T"; } else { varName += bmdBoneRangeKey.replace("_BMD", "_T"); } if (data.keySet().contains(varName)) { throw new IllegalArgumentException("Instrument variable name already defined: " + varName); } data.put(varName, DataBuilder.buildDecimal(T_score)); log.info(varName + " = " + T_score.toString()); Double Z_score = null; varName = getResultPrefix() + "_"; if (type.equals("S") && bmdBoneRangeKey.startsWith("TOT_")) { varName += "TOT_Z"; } else { varName += bmdBoneRangeKey.replace("_BMD", "_Z"); } if (data.keySet().contains(varName)) { throw new IllegalArgumentException("Instrument variable name already defined: " + varName); } // APEX reference curve db has no ultra distal ulna data for males // String gender = getParticipantGender().toUpperCase(); if (0 == gender.length() || gender.startsWith("F")) gender = " AND SEX = 'F'"; else if (gender.startsWith("M")) { if (bmdBoneRangeKey.equals("U_UD_BMD")) { data.put(varName, DataBuilder.buildDecimal((Double) null)); continue; } gender = " AND SEX = 'M'"; } // APEX reference curve db has no forearm data for black or hispanic ethnicity // String ethnicity = getParticipantEthnicity(); if (null == ethnicity) ethnicity = ""; ethnicity.toUpperCase(); if (0 == ethnicity.length() || ethnicity.equals("W") || ethnicity.equals("O") || ethnicity.equals("P") || ethnicity.equals("I") || (type.equals("R") && (ethnicity.equals("H") || ethnicity.equals("B")))) { ethnicity = " AND ETHNIC IS NULL"; } else { ethnicity = " AND ETHNIC = '" + ethnicity + "'"; } sql = "SELECT UNIQUE_ID, AGE_YOUNG FROM ReferenceCurve"; sql += " WHERE REFTYPE = '" + getRefType() + "'"; sql += " AND IF_CURRENT = 1"; sql += gender; sql += ethnicity; sql += method; sql += " AND SOURCE LIKE '%" + getRefSource() + "%'"; sql += " AND Y_LABEL = 'IDS_REF_LBL_BMD'"; sql += " AND BONERANGE "; sql += (ranges.get(bmdBoneRangeKey).equals("NULL") ? ("IS NULL") : ("= '" + ranges.get(bmdBoneRangeKey) + "'")); log.info("first query (Z score): " + sql); try { mapResult = refCurveDb.queryForMap(sql); } catch (DataAccessException e) { throw e; } curveId = mapResult.get("UNIQUE_ID").toString(); // Determine the age values (X axis variable) of the curve // sql = "SELECT X_VALUE FROM Points WHERE UNIQUE_ID = " + curveId; log.info("second query (Z score): " + sql); List<Map<String, Object>> listResult; try { listResult = refCurveDb.queryForList(sql); } catch (DataAccessException e) { throw e; } List<Double> ageTable = new ArrayList<Double>(); for (Map<String, Object> row : listResult) { ageTable.add(new Double(row.get("X_VALUE").toString())); } bracket.compute(age, ageTable); if (0. != bracket.ageSpan) { // Determine the bmd, skewness factor and standard deviation // at the bracketing and peak bmd age values. // sql = "SELECT Y_VALUE, L_VALUE, STD FROM Points WHERE UNIQUE_ID = " + curveId; sql += " AND X_VALUE = "; Double[] x_value_array = { bracket.ageMin, bracket.ageMax }; bmdValues.clear(); for (int i = 0; i < x_value_array.length; i++) { log.info("third query (Z score) iter " + ((Integer) i).toString() + " : " + sql + x_value_array[i].toString()); mapResult.clear(); try { mapResult = refCurveDb.queryForMap(sql + x_value_array[i].toString()); } catch (DataAccessException e) { throw e; } bmdValues.add(new Double(mapResult.get("Y_VALUE").toString())); bmdValues.add(new Double(mapResult.get("L_VALUE").toString())); bmdValues.add(new Double(mapResult.get("STD").toString())); } Double u = (age - bracket.ageMin) / bracket.ageSpan; List<Double> interpValues = new ArrayList<Double>(); for (int i = 0; i < bmdValues.size() / 2; i++) interpValues.add((1. - u) * bmdValues.get(i) + u * bmdValues.get(i + 3)); M_value = interpValues.get(0); L_value = interpValues.get(1); sigma = interpValues.get(2); Z_score = M_value * (Math.pow(X_value / M_value, L_value) - 1.) / (L_value * sigma); Z_score = Double.valueOf(format.format(Z_score)); if (0. == Math.abs(Z_score)) Z_score = 0.; } data.put(varName, DataBuilder.buildDecimal(Z_score)); if (null != Z_score) { log.info(varName + " = " + Z_score.toString()); } else { log.info(varName + " = null"); } log.info("finished current key: " + bmdBoneRangeKey); } }
From source file:fr.gouv.culture.vitam.eml.PstExtract.java
private Element extractInfoTask(PSTTask task) { Element root = XmlDom.factory.createElement("task"); String value = null;//www.ja v a 2s .c om Integer ival = task.getTaskStatus(); root.add(XmlDom.factory.createElement("TaskStatus").addText(ival.toString())); Double dval = task.getPercentComplete(); root.add(XmlDom.factory.createElement("PercentComplete").addText(dval.toString())); Boolean bval = task.isTeamTask(); root.add(XmlDom.factory.createElement("isTeamTask").addText(bval.toString())); Date date = task.getTaskStartDate(); if (date != null) { root.add(XmlDom.factory.createElement("TaskStartDate").addText(date.toString())); } date = task.getTaskDueDate(); if (date != null) { root.add(XmlDom.factory.createElement("TaskDueDate").addText(date.toString())); } date = task.getTaskDateCompleted(); if (date != null) { root.add(XmlDom.factory.createElement("TaskDateCompleted").addText(date.toString())); } ival = task.getTaskActualEffort(); root.add(XmlDom.factory.createElement("TaskActualEffort").addText(ival.toString())); ival = task.getTaskEstimatedEffort(); root.add(XmlDom.factory.createElement("TaskEstimatedEffort").addText(ival.toString())); ival = task.getTaskVersion(); root.add(XmlDom.factory.createElement("TaskVersion").addText(ival.toString())); bval = task.isTaskComplete(); root.add(XmlDom.factory.createElement("isTaskComplete").addText(bval.toString())); value = task.getTaskOwner(); if (value != null && !value.isEmpty()) { root.add(XmlDom.factory.createElement("TaskOwner").addText(value)); } value = task.getTaskAssigner(); if (value != null && !value.isEmpty()) { root.add(XmlDom.factory.createElement("TaskAssigner").addText(value)); } value = task.getTaskLastUser(); if (value != null && !value.isEmpty()) { root.add(XmlDom.factory.createElement("TaskLastUser").addText(value)); } ival = task.getTaskOrdinal(); root.add(XmlDom.factory.createElement("TaskOrdinal").addText(ival.toString())); bval = task.isTaskFRecurring(); root.add(XmlDom.factory.createElement("isTaskFRecurring").addText(bval.toString())); value = task.getTaskRole(); if (value != null && !value.isEmpty()) { root.add(XmlDom.factory.createElement("TaskRole").addText(value)); } ival = task.getTaskOwnership(); root.add(XmlDom.factory.createElement("TaskOwnership").addText(ival.toString())); ival = task.getAcceptanceState(); root.add(XmlDom.factory.createElement("AcceptanceState").addText(ival.toString())); return root; }
From source file:com.seatgeek.placesautocompletedemo.MainFragment.java
public void OnActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) { if (resultCode == getActivity().RESULT_OK) { com.google.android.gms.location.places.Place place = PlaceAutocomplete.getPlace(getContext(), data); LatLng placeLatLng = place.getLatLng(); Double lat = placeLatLng.latitude; Double lng = placeLatLng.longitude; sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("LATITUDE", lat.toString()); editor.putString("LONGITUDE", lng.toString()); editor.commit();// w w w. jav a2 s.c o m mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(placeLatLng, 15f), 50, null); Log.i("", "Place: " + place.getName()); } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { Status status = PlaceAutocomplete.getStatus(getContext(), data); Log.i("", status.getStatusMessage()); } else if (resultCode == getActivity().RESULT_CANCELED) { // The user canceled the operation. } } }
From source file:com.seatgeek.placesautocompletedemo.MainFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) { if (resultCode == getActivity().RESULT_OK) { com.google.android.gms.location.places.Place place = PlaceAutocomplete.getPlace(getContext(), data); LatLng placeLatLng = place.getLatLng(); Double lat = placeLatLng.latitude; Double lng = placeLatLng.longitude; sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("LATITUDE", lat.toString()); editor.putString("LONGITUDE", lng.toString()); editor.commit();//from ww w.j a va 2 s .c o m mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(placeLatLng, 15f), 50, null); Log.i("", "Place: " + place.getName()); } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { Status status = PlaceAutocomplete.getStatus(getContext(), data); Log.i("", status.getStatusMessage()); } else if (resultCode == getActivity().RESULT_CANCELED) { // The user canceled the operation. } } }
From source file:gui.EspecificacionesAnimal.java
public void setPeso(Double aPeso) { tf_pesoBascula.setText(aPeso.toString()); }