List of usage examples for java.lang Double toString
public String toString()
From source file:com.jtech.iaf.CityBikesTransport.java
private void processJSON(JSONArray jsonArray) { try {//from w w w .j a v a 2s .com for (Object o : jsonArray) { JSONObject entry = (JSONObject) o; Long id = (Long) entry.get("id"); String name = (String) entry.get("name"); Pattern regex = Pattern.compile("^(\\d+)\\s?-\\s?(.*)"); Matcher regexMatcher = regex.matcher(name); while (regexMatcher.find()) { name = regexMatcher.group(2); } Double lat = Double.valueOf((Long) entry.get("lat")) / 1000000d; Double lng = Double.valueOf((Long) entry.get("lng")) / 1000000d; Long avail = (Long) entry.get("bikes"); Long empty = (Long) entry.get("free"); String updated = (String) entry.get("timestamp"); NormalisedEvent normalisedEvent = new NormalisedEvent(); normalisedEvent.addQuick("__type", "__station_update"); normalisedEvent.addQuick("city", cityName); normalisedEvent.addQuick("id", id.toString()); normalisedEvent.addQuick("name", name); normalisedEvent.addQuick("lat", lat.toString()); normalisedEvent.addQuick("lng", lng.toString()); normalisedEvent.addQuick("updated", updated); normalisedEvent.addQuick("ratio", String.format("%.2f", Double.valueOf(avail) / Double.valueOf((avail + empty)))); normalisedEvent.addQuick("docked", avail.toString()); normalisedEvent.addQuick("empty", empty.toString()); normalisedEvent.addQuick("timestamp", String.valueOf(System.currentTimeMillis() / 1000)); logger.info("Sending downstream transport event to data codec: " + normalisedEvent); TimestampSet timestampSet = new TimestampSet(); decoder.sendTransportEvent(normalisedEvent, timestampSet); totalReceived++; } } catch (Exception e) { logger.error(e.getMessage()); } }
From source file:epsi.i5.datamining.Traitement.java
public String calculPolarite(String commentaire) throws IOException, MalformedURLException, RepustateException, ParseException { String polarite;/*from w w w .ja v a2s.co m*/ Double score = null; Map map = new HashMap(); map.put("text1", commentaire); // System.out.println(RepustateClient.getSentimentBulk(map)); JSONParser jp = new JSONParser(); JSONObject json = (JSONObject) jp.parse(RepustateClient.getSentimentBulk(map)); // System.out.println(json.get("results")); JSONArray jsonArray = (JSONArray) json.get("results"); for (Object obj : jsonArray) { JSONObject jsonObject = (JSONObject) obj; score = new Double(jsonObject.get("score").toString()); score = score * 10; // System.out.println("Polarit : " + score); } polarite = score.toString(); return polarite; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java
public static String getDoubleString(Double val) { if (val == null) { return ("null"); } else {//from ww w . j a v a2 s.c o m return (val.toString()); } }
From source file:com.act.lcms.db.analysis.ChemicalToMapOfMetlinIonsToIntensityTimeValues.java
/** * This function plots a combination of positive and negative control intensity-time values. * @param searchMzs A list of mass charge values * @param plottingPath The wells used for the analysis. This variable is mainly used for * @param peakDataPos The postive intensity-time value * @param peakDataNegs The negative controls intensity-time values * @param plottingDirectory The directory where the plots are going to be placed in * @return//w w w. j a va 2 s . c om * @throws IOException */ public static Map<String, String> plotPositiveAndNegativeControlsForEachMZ(Set<Pair<String, Double>> searchMzs, String plottingPath, ChemicalToMapOfMetlinIonsToIntensityTimeValues peakDataPos, List<ChemicalToMapOfMetlinIonsToIntensityTimeValues> peakDataNegs, String plottingDirectory) throws IOException { Map<String, String> result = new HashMap<>(); Map<String, Double> individualMaxIntensities = new HashMap<>(); WriteAndPlotMS1Results plottingUtil = new WriteAndPlotMS1Results(); for (Pair<String, Double> mz : searchMzs) { LinkedHashMap<String, List<XZ>> ms1s = new LinkedHashMap<>(); Map<String, Double> metlinMasses = new HashMap<>(); Double maxIntensity = 0.0d; String chemicalAndIonName = mz.getLeft(); Double massChargeValue = mz.getRight(); // Get positive ion results String positiveChemicalName = AnalysisHelper.constructChemicalAndScanTypeName(chemicalAndIonName, ScanData.KIND.POS_SAMPLE); List<XZ> ionValuesPos = peakDataPos.peakData.get(positiveChemicalName).get(chemicalAndIonName); ms1s.put(positiveChemicalName, ionValuesPos); Double localMaxIntensityPos = findPeakMaxIntensity(ionValuesPos); maxIntensity = Math.max(maxIntensity, localMaxIntensityPos); individualMaxIntensities.put(positiveChemicalName, localMaxIntensityPos); metlinMasses.put(positiveChemicalName, massChargeValue); // Get negative control results Integer negNameCounter = 0; for (ChemicalToMapOfMetlinIonsToIntensityTimeValues peakDataNeg : peakDataNegs) { String negativeChemicalName = AnalysisHelper.constructChemicalAndScanTypeName(chemicalAndIonName, ScanData.KIND.NEG_CONTROL); String negativeChemicalNameId = negativeChemicalName + "_" + negNameCounter.toString(); List<XZ> ionValuesNeg = peakDataNeg.peakData.get(negativeChemicalName).get(chemicalAndIonName); ms1s.put(negativeChemicalNameId, ionValuesNeg); Double localMaxIntensityNeg = findPeakMaxIntensity(ionValuesNeg); maxIntensity = Math.max(maxIntensity, localMaxIntensityNeg); individualMaxIntensities.put(negativeChemicalNameId, localMaxIntensityNeg); metlinMasses.put(negativeChemicalNameId, massChargeValue); negNameCounter++; } String relativePath = massChargeValue.toString() + "_" + plottingPath + "_" + chemicalAndIonName; File absolutePathFileWithoutExtension = new File(plottingDirectory, relativePath); String absolutePathWithoutExtension = absolutePathFileWithoutExtension.getAbsolutePath(); String absolutePathWithExtension = absolutePathWithoutExtension + "." + FMT; // Check if the plotting file already exists. If it does, we should not overwrite it. Instead, we just change // the path name by appending a counter till the collision no longer exists. // TODO: Implement an elegant solution to this problem. File duplicateFile = new File(absolutePathWithExtension); Integer fileDuplicateCounter = 0; while (duplicateFile.exists() && !duplicateFile.isDirectory()) { LOGGER.warn("Duplicate file exists for %s, writing to another file", duplicateFile.getAbsolutePath()); fileDuplicateCounter++; relativePath = relativePath + "_" + fileDuplicateCounter.toString(); absolutePathFileWithoutExtension = new File(plottingDirectory, relativePath); absolutePathWithoutExtension = absolutePathFileWithoutExtension.getAbsolutePath(); absolutePathWithExtension = absolutePathWithoutExtension + "." + FMT; duplicateFile = new File(absolutePathWithExtension); } LOGGER.info("Wrote plot to %s", absolutePathWithoutExtension); plottingUtil.plotSpectra(ms1s, maxIntensity, individualMaxIntensities, metlinMasses, absolutePathWithoutExtension, FMT, false, false); result.put(mz.getLeft(), relativePath + "." + FMT); } return result; }
From source file:epsi.i5.datamining.Treatment.java
/** * Method will call the API to calculatethe rating of each comment * * @param commentaire//from w ww . ja va 2 s . c om * @return rating * @throws IOException * @throws MalformedURLException * @throws RepustateException * @throws ParseException */ public String calculPolarite(String commentaire) throws IOException, MalformedURLException, RepustateException, ParseException { String polarite; Double score = new Double("0"); Map map = new HashMap(); map.put("text1", commentaire); // System.out.println(RepustateClient.getSentimentBulk(map)); JSONParser jp = new JSONParser(); JSONObject json = (JSONObject) jp.parse(RepustateClient.getSentimentBulk(map)); // System.out.println(json.get("results")); JSONArray jsonArray = (JSONArray) json.get("results"); for (Object obj : jsonArray) { JSONObject jsonObject = (JSONObject) obj; score = new Double(jsonObject.get("score").toString()); //// score = score * 10; //// System.out.println("Polarit : " + score); } polarite = score.toString(); return polarite; }
From source file:au.org.ala.biocache.dto.OccurrenceIndex.java
private String safeDblToString(Double d) { if (d != null) return d.toString(); return null; }
From source file:de.bund.bfr.pmfml.sbml.PMFCoefficientImpl.java
/** * Creates a PMFCoefficientImpl fron an id, value, unit, P, error, t, * correlations and description./* ww w .j a v a 2 s . c o m*/ */ public PMFCoefficientImpl(final String id, final double value, final String unit, final Double P, final Double error, final Double t, final Correlation[] correlations, final String desc, final Boolean isStart) { param = new Parameter(id, LEVEL, VERSION); param.setValue(value); param.setUnits(unit); param.setConstant(true); if (P != null || error != null || t != null || correlations != null || desc != null) { // Builds metadata node final XMLNode metadataNode = new XMLNode(new XMLTriple(METADATA_TAG, null, METADATA_NS)); // Creates P annotation if (P != null) { final XMLNode pNode = new XMLNode(new XMLTriple(P_TAG, null, P_NS)); pNode.addChild(new XMLNode(P.toString())); metadataNode.addChild(pNode); } // Creates error annotation if (error != null) { final XMLNode errorNode = new XMLNode(new XMLTriple(ERROR_TAG, null, ERROR_NS)); errorNode.addChild(new XMLNode(error.toString())); metadataNode.addChild(errorNode); } // Creates t annotation if (t != null) { final XMLNode tNode = new XMLNode(new XMLTriple(T_TAG, null, T_NS)); tNode.addChild(new XMLNode(t.toString())); metadataNode.addChild(tNode); } // Creates correlation annotation if (correlations != null) { for (final Correlation correlation : correlations) { final XMLAttributes attrs = new XMLAttributes(); attrs.add(ATTRIBUTE_NAME, correlation.getName()); if (correlation.isSetValue()) { attrs.add(ATTRIBUTE_VALUE, Double.toString(correlation.getValue())); } final XMLTriple triple = new XMLTriple(CORRELATION_TAG, null, CORRELATION_NS); metadataNode.addChild(new XMLNode(triple, attrs)); } } // Creates annotation for description if (desc != null) { final XMLNode descNode = new XMLNode(new XMLTriple(DESC_TAG, null, DESC_NS)); descNode.addChild(new XMLNode(desc)); metadataNode.addChild(descNode); } // Creates annotation for isStart if (isStart != null) { final XMLNode isStartNode = new XMLNode(new XMLTriple(ISSTART_TAG, null, ISSTART_NS)); isStartNode.addChild(new XMLNode(isStart.toString())); metadataNode.addChild(isStartNode); } param.getAnnotation().setNonRDFAnnotation(metadataNode); } this.P = P; this.error = error; this.t = t; this.correlations = correlations; this.desc = desc; this.isStart = isStart; }
From source file:com.ephesoft.dcma.tablefinder.service.TableFinderServiceImpl.java
/** * Returns the value of the columnName passed for the table row. If <code>cuurencyCode</code> is not <code>NULL</code>, then * currencyExtraction rules are applied to the extracted value corresponding to the code. * //from w w w .j av a 2s. c o m * @param row {@link Row} row from which the values are to be extracted. * @param columnPassed {@link String} name of the column whose value is to be extracted. * @param currencyCode {@link CurrencyCode} implies the rules for currency extraction. If null currency extraction is not * performed. * @return {@link String} Value extracted corresponding to the column. */ private String getColumnValue(final Row row, final String columnPassed, final CurrencyCode currencyCode) { String extractedValue = getColumnValue(row, columnPassed); if (currencyCode != null) { Double currencyValue = CurrencyUtil.getDoubleValue(extractedValue, currencyCode.getRepresentationValue()); if (currencyValue != null) { extractedValue = currencyValue.toString(); } } LOGGER.info(EphesoftStringUtil.concatenate("Extracted value for ", columnPassed, " is ", extractedValue)); return extractedValue; }
From source file:com.viettel.logistic.wms.service.StockTransServiceImpl.java
private ResultDTO updateImportOtherTables(String oldStockTransId, StockTransDTO stockTransDTO, StockTransDetailDTO stockTransDetailDTO, Session session, Connection connection) { ResultDTO resultDTO;/*from w w w.ja v a 2 s .c o m*/ //Neu la hang hoa quan ly theo serial if (Constants.IS_SERIAL.equalsIgnoreCase(stockTransDetailDTO.getGoodsIsSerial())) { //Thuc hien them du lieu vao bang stock_goods_serial va stock_trans_serial //khoi tao list serial duoc nhap kho cho mat hang nay List<StockTransSerialDTO> lstStockTransSerials = getListStockTransSerials(oldStockTransId, stockTransDetailDTO); //Insert batch VAO KHO STOCK_GOODS_SERIAL resultDTO = importStockGoodsListSerial(stockTransDTO, (StockTransDetailDTO) DataUtil.cloneObject(stockTransDetailDTO), lstStockTransSerials, connection, ParamUtils.GOODS_IMPORT_STATUS.IMPORTED); //Cap nhat lai so luong hang hoa giao dich if (resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { Double amountIssue = resultDTO.getAmountIssue(); //CAP NHAT LAI STOCK_TRANS_DETAIL VOI SO LUONG INSERT THANH CONG stockTransDetailDTO.setAmountReal(amountIssue.toString().replace(".0", "")); int isUpdate = stockGoodsSerialBusiness2.updateStockTransDetail( stockTransDetailDTO.getStockTransDetailId(), amountIssue, connection); //neu update khong thanh cong if (isUpdate < 1) { resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey("UPDATE_STOCK_TRANS_DETAIL_ERROR"); rollback(session, null, connection); return resultDTO; } } } else { //Neu la hang hoa khong quan ly theo serial //Thuc hien cap nhat stock_goods resultDTO = importStockGoods(stockTransDTO, stockTransDetailDTO, session, ParamUtils.GOODS_IMPORT_STATUS.IMPORTED); } if (resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { resultDTO = importStockGoodsTotal(stockTransDTO, stockTransDetailDTO, session); } return resultDTO; }
From source file:com.likethecolor.alchemy.api.entity.ConceptAlchemyEntityTest.java
@Test public void testLatitude_String() { final Double expectedLatitude = 35.123D; final String latitude = expectedLatitude.toString(); final ConceptAlchemyEntity entity = new ConceptAlchemyEntity(); entity.setLatitude(latitude);//w w 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()); }