List of usage examples for java.lang Double toString
public String toString()
From source file:net.groupbuy.controller.admin.ProductController.java
/** * //from ww w . j a v a2s .c om * * @param price * */ private long calculateDefaultPoint(BigDecimal price) { Setting setting = SettingUtils.get(); Double defaultPointScale = setting.getDefaultPointScale(); return price.multiply(new BigDecimal(defaultPointScale.toString())).longValue(); }
From source file:de.ingrid.iplug.dsc.utils.BwstrLocUtil.java
/** * Checks and parses a String according to the pattern <Wasserstrassen ID>-<km_from>-<km_to>. * If the distance is > 1 km then the from to section is computed * with kmFrom = center-0.5km and kmTo = center+0.5km. * /*from w w w. j a v a 2s.c o m*/ * @param bwStrIdAndKm * @return Returns array with [Wasserstrassen ID, km_from, km_to]. */ public String[] parseCenterSectionFromBwstrIdAndKm(String bwStrIdAndKm) { String[] parts = parseBwstrIdAndKm(bwStrIdAndKm); if (parts != null) { Double from = Double.parseDouble(parts[1]); Double to = Double.parseDouble(parts[2]); Double distance = to - from; if (distance > 1.0) { Double center = from + (to - from) / 2; from = center - 0.5; to = center + 0.5; } return new String[] { parts[0], from.toString(), to.toString() }; } return null; }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.rdata.RTabFileParser.java
public int read(BufferedReader csvReader, SDIOMetadata smd, PrintWriter pwout) throws IOException { dbgLog.warning("RTabFileParser: Inside R Tab file parser"); //DataTable csvData = new DataTable(); int varQnty = 0; try {//from w ww. j a v a 2 s . c om varQnty = new Integer(smd.getFileInformation().get("varQnty").toString()); } catch (Exception ex) { //return -1; throw new IOException("R Tab File Parser: Could not obtain varQnty from the dataset metadata."); } if (varQnty == 0) { //return -1; throw new IOException("R Tab File Parser: varQnty=0 in the dataset metadata!"); } String[] caseRow = new String[varQnty]; String line; String[] valueTokens; int lineCounter = 0; boolean[] isCharacterVariable = smd.isStringVariable(); boolean[] isContinuousVariable = smd.isContinuousVariable(); boolean[] isDateVariable = smd.isDateVariable(); boolean[] isCategoricalVariable = smd.isCategoricalVariable(); boolean[] isBooleanVariable = smd.isBooleanVariable(); //Map<Integer, Map<String, String>> ReverseValueLabelTable = createReverseCatValueTable(smd); Map<String, String> valueLabelMappingTable = smd.getValueLabelMappingTable(); Map<String, Map<String, String>> valueLabelTable = smd.getValueLabelTable(); Map<String, String> valueLabelPairs = new LinkedHashMap<String, String>(); dbgLog.fine("CSV reader; varQnty: " + varQnty); dbgLog.fine("CSV reader; delimiter: " + delimiterChar); while ((line = csvReader.readLine()) != null) { // chop the line: line = line.replaceFirst("[\r\n]*$", ""); valueTokens = line.split("" + delimiterChar, -2); if (valueTokens == null) { throw new IOException("Failed to read line " + (lineCounter + 1) + " of the Data file."); } if (valueTokens.length != varQnty) { throw new IOException("Reading mismatch, line " + (lineCounter + 1) + " of the Data file: " + varQnty + " delimited values expected, " + valueTokens.length + " found."); } //dbgLog.fine("case: "+lineCounter); for (int i = 0; i < varQnty; i++) { //dbgLog.fine("value: "+valueTokens[i]); if (isCharacterVariable[i]) { // String. Adding to the table, quoted. // Empty strings stored as " " (one white space): if (valueTokens[i] != null && (!valueTokens[i].equals(""))) { String charToken = valueTokens[i]; // Dealing with quotes: // remove the leading and trailing quotes, if present: charToken = charToken.replaceFirst("^\"", ""); charToken = charToken.replaceFirst("\"$", ""); // escape the remaining ones: charToken = charToken.replace("\"", "\\\""); // final pair of quotes: if (isDateVariable == null || (!isDateVariable[i])) { charToken = "\"" + charToken + "\""; } caseRow[i] = charToken; } else { /* * Note the commented-out code below; it was converting * missing values into " " (a double-quoted space - ?) * I'm pretty positive that was a result of a misreading * of some spec many years ago. I'm also fairly positive * that the only way to store an NA unambiguously is as * an *empty* string, no quotes, no nothing! * TODO: * Not sure about the above anymore; need to figure it out. * -- L.A. */ /* if (isDateVariable==null || (!isDateVariable[i])) { caseRow[i] = " "; } else { */ caseRow[i] = ""; /*}*/ } } else if (isContinuousVariable[i]) { // Numeric, Double: // This is the major case of special/custom processing, // specific for R ingest. It was found to be impossible // to write a numeric/continuous column into the tab file // while unambiguously preserving both NA and NaNs, if both // are present. At least, not if using the standard // write.table function. So it seemed easier to treat this // as a special case, rather than write our own write.table // equivalent in R. On the R side, if any special values // are present in the columns, the values will be // converted into a character vector. The NAs and NaNs will // be replaced with the character tokens "NA" and "NaN" // respectively. Of course R will add double quotes around // the tokens, hence the post-processing - we'll just need // to remove all these quotes, and then we'll be fine. dbgLog.fine("R Tab File Parser; double value: " + valueTokens[i]); // Dealing with quotes: // remove the leading and trailing quotes, if present: valueTokens[i] = valueTokens[i].replaceFirst("^\"", ""); valueTokens[i] = valueTokens[i].replaceFirst("\"$", ""); if (valueTokens[i] != null && valueTokens[i].equalsIgnoreCase("NA")) { caseRow[i] = ""; } else if (valueTokens[i] != null && valueTokens[i].equalsIgnoreCase("NaN")) { caseRow[i] = "NaN"; } else if (valueTokens[i] != null && (valueTokens[i].equalsIgnoreCase("Inf") || valueTokens[i].equalsIgnoreCase("+Inf"))) { caseRow[i] = "Inf"; } else if (valueTokens[i] != null && valueTokens[i].equalsIgnoreCase("-Inf")) { caseRow[i] = "-Inf"; } else { try { Double testDoubleValue = new Double(valueTokens[i]); caseRow[i] = testDoubleValue.toString();//valueTokens[i]; } catch (Exception ex) { dbgLog.fine("caught exception reading numeric value; variable: " + i + ", case: " + lineCounter + "; value: " + valueTokens[i]); //dataTable[i][lineCounter] = (new Double(0)).toString(); caseRow[i] = ""; // TODO: // decide if we should rather throw an exception and exit here; // all the values in this file at this point must be // legit numeric values (?) -- L.A. } } } else if (isBooleanVariable[i]) { if (valueTokens[i] != null) { String charToken = valueTokens[i]; // remove the leading and trailing quotes, if present: charToken = charToken.replaceFirst("^\"", ""); charToken = charToken.replaceFirst("\"$", ""); if (charToken.equals("FALSE")) { caseRow[i] = "0"; } else if (charToken.equals("TRUE")) { caseRow[i] = "1"; } else if (charToken.equals("")) { // Legit case - Missing Value! caseRow[i] = charToken; } else { throw new IOException( "Unexpected value for the Boolean variable (" + i + "): " + charToken); } } else { throw new IOException("Couldn't read Boolean variable (" + i + ")!"); } } /* * [experimental] special case for categorical variables. * See the comment for the [commented-out] createReverseCatValueTable * method below for more info. -- L.A. else if (isCategoricalVariable[i]) { // an R factor: // The entry in the saved tab file is in fact the character // label of the factor. We want to replace it with the actual // numeric value in the final tab file. dbgLog.info("RTabFile reader; factor value: "+valueTokens[i]); if (valueTokens[i] != null && (!valueTokens[i].equals(""))) { String charToken = valueTokens[i]; // Dealing with quotes: // remove the leading and trailing quotes, if present: charToken = charToken.replaceFirst("^\"", ""); charToken = charToken.replaceFirst("\"$", ""); if (ReverseValueLabelTable.get(i).get(charToken) != null && !(ReverseValueLabelTable.get(i).get(charToken).equals(""))) { caseRow[i] = ReverseValueLabelTable.get(i).get(charToken); } else { // Not quite sure what to do if the label is NOT // on the map... - ?? // (this really should not happen...) caseRow[i] = ""; } } else { caseRow[i] = ""; } } */ else { // Numeric, Integer: // One special case first: R NA (missing value) needs to be // converted into the DVN's missing value - an empty String; // (strictly speaking, this isn't necessary - an attempt to // create an Integer object from the String "NA" would // result in an exception, that would be intercepted below, // with the same end result) dbgLog.fine("R Tab File Parser; integer value: " + valueTokens[i]); if (valueTokens[i] != null && valueTokens[i].equalsIgnoreCase("NA")) { caseRow[i] = ""; } else { try { Integer testIntegerValue = new Integer(valueTokens[i]); caseRow[i] = testIntegerValue.toString(); } catch (Exception ex) { dbgLog.fine("caught exception reading numeric value; variable: " + i + ", case: " + lineCounter + "; value: " + valueTokens[i]); //dataTable[i][lineCounter] = "0"; caseRow[i] = ""; } } } } pwout.println(StringUtils.join(caseRow, "\t")); lineCounter++; } //csvData.setData(dataTable); //return csvData; pwout.close(); return lineCounter; }
From source file:eu.optimis.ecoefficiencytool.rest.client.EcoEfficiencyToolValidatorRESTClient.java
/** * Logs a conditional-action-obtained forecast for further validation. * * @param deltaT Increment of time for which the forecast has been performed * with respect to the current time./* w w w. j av a 2 s.com*/ * @param value Forecasted value. * @param reason Potential action which was evaluated when performing the * forecast. Choose one of the provided: VM_DEPLOYMENT, VM_MIGRATION, * VM_CANCELLATION, SERVICE_DEPLOYMENT */ public void logConditionalAction(Long deltaT, Double value, String reason) { try { WebResource resource = client.resource(this.getAddress()).path("conditional"); if (deltaT != null) { resource = resource.queryParam("deltaT", deltaT.toString()); } else { log.error("Parameter \"deltaT\" must be specified."); return; } if (value != null) { resource = resource.queryParam("value", value.toString()); } else { log.error("Parameter \"value\" must be specified."); return; } if (reason != null) { resource = resource.queryParam("reason", reason); } else { log.error("Parameter \"reason\" must be specified."); return; } resource.post(); } catch (UniformInterfaceException ex) { ClientResponse cr = ex.getResponse(); log.error(cr.getStatus()); ex.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.ksimplecycle.KSimpleCycle_StoreInValue.java
@Override public void compute(Vertex<Text, TextAndHashes, NullWritable> vertex, Iterable<CustomMessage> messages) throws IOException { int k = 5; //circuiti chiusi di lunghezza k // LOG.info("LOG HASHES " + vertex.getValue().getGeneratedHash().size() + "\t" + vertex.getValue().getSeenHash().size()); if (getSuperstep() == 0) { for (Edge<Text, NullWritable> edge : vertex.getEdges()) { // int hsg = edge.hashCode();//TODO: da controllare String rnd = RandomStringUtils.random(32);//TODO: da controllare int hsg = rnd.hashCode(); // LOG.info("SEND TO ALL EDGE\t" + hsg); vertex.getValue().getGeneratedHash().add(hsg); CustomMessage msg = new CustomMessage(vertex.getId(), hsg); sendMessage(edge.getTargetVertexId(), msg); }//from www. j a v a 2s. c o m } else if (getSuperstep() > 0 && getSuperstep() < k) { for (CustomMessage message : messages) { // LOG.info(vertex.getId() + " RECEIVED MSG FROM " + message.getSource() + " CONTEINED " + message.getMessage()); //Scarto messaggi contenente l'id del vertice durante i passi intermedi //init set relativo arco entrante al primo messaggio ricevuto if (!vertex.getValue().getSeenHash().containsKey(message.getSource())) { vertex.getValue().getSeenHash().put(message.getSource(), new HashSet<Integer>()); } if (!vertex.getValue().getGeneratedHash().contains(message.getMessage()) && !vertex.getValue() .getSeenHash().get(message.getSource()).contains(message.getMessage())) { vertex.getValue().getSeenHash().get(message.getSource()).add(message.getMessage()); for (Edge<Text, NullWritable> edge : vertex.getEdges()) { //evito "rimbalzo" di messaggi tra 2 vertici vicini //ho eliminato controllo "rimbalzo" perche non puo piu accadare dopo l'introduzione controllo hash msg if (!edge.getTargetVertexId().toString().equals(message.getSource().toString())) { CustomMessage msg = new CustomMessage(vertex.getId(), message.getMessage()); // LOG.info("SEND MESSAGE " + msg.getMessage() + " FROM " + msg.getSource() + " TO " + edge.getTargetVertexId()); sendMessage(edge.getTargetVertexId(), msg); } } // CustomMessage msg = new CustomMessage(vertex.getId(), message.getMessage()); // System.out.println("Propagazione msg\t" + message); } } } else if (getSuperstep() == k) { LOG.info(this.printGeneratedHashSet(vertex)); // LOG.info(this.printSeenHashSet(vertex)); Double T = 0.0; for (CustomMessage message : messages) { LOG.info(vertex.getId() + "\tReceive\t" + message); // System.out.println(vertex.getSource()+"\t"+message); if (vertex.getValue().getGeneratedHash().contains(message.getMessage())) { T++; } } T = T / (2 * k); vertex.setValue(new TextAndHashes(new Text(T.toString()))); vertex.voteToHalt(); aggregate(SOMMA, new DoubleWritable(T)); } }
From source file:massbank.Record.java
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("ACCESSION: " + ACCESSION() + "\n"); sb.append("RECORD_TITLE: " + RECORD_TITLE() + "\n"); sb.append("DATE: " + DATE() + "\n"); sb.append("AUTHORS: " + AUTHORS() + "\n"); sb.append("LICENSE: " + LICENSE() + "\n"); if (COPYRIGHT() != null) sb.append("COPYRIGHT: " + COPYRIGHT() + "\n"); if (PUBLICATION() != null) sb.append("PUBLICATION: " + PUBLICATION() + "\n"); if (COMMENT() != null) { for (String comment : COMMENT()) sb.append("COMMENT: " + comment + "\n"); }/* w w w. java 2 s. c o m*/ if (CH_NAME() != null) { for (String ch_name : CH_NAME()) sb.append("CH$NAME: " + ch_name + "\n"); } sb.append("CH$COMPOUND_CLASS: " + CH_COMPOUND_CLASS() + "\n"); sb.append("CH$FORMULA: " + CH_FORMULA() + "\n"); sb.append("CH$EXACT_MASS: " + CH_EXACT_MASS() + "\n"); try { sb.append("CH$SMILES: " + CH_SMILES() + "\n"); } catch (CDKException e) { System.err.println(e.getMessage()); sb.append("CH$SMILES: null\n"); } try { sb.append("CH$IUPAC: " + CH_IUPAC() + "\n"); } catch (CDKException e) { System.err.println(e.getMessage()); sb.append("CH$IUPAC: null\n"); } if (CH_LINK() != null) { for (Pair<String, String> link : CH_LINK()) sb.append("CH$LINK: " + link.getKey() + " " + link.getValue() + "\n"); } if (SP_SCIENTIFIC_NAME() != null) sb.append("SP$SCIENTIFIC_NAME: " + SP_SCIENTIFIC_NAME() + "\n"); if (SP_LINEAGE() != null) sb.append("SP$LINEAGE: " + SP_LINEAGE() + "\n"); if (SP_LINK() != null) { for (Pair<String, String> link : SP_LINK()) sb.append("SP$LINK: " + link.getKey() + " " + link.getValue() + "\n"); } if (SP_SAMPLE() != null) { for (String sample : SP_SAMPLE()) sb.append("SP$SAMPLE: " + sample + "\n"); } sb.append("AC$INSTRUMENT: " + AC_INSTRUMENT() + "\n"); sb.append("AC$INSTRUMENT_TYPE: " + AC_INSTRUMENT_TYPE().toString() + "\n"); sb.append("AC$MASS_SPECTROMETRY: MS_TYPE: " + AC_MASS_SPECTROMETRY_MS_TYPE() + "\n"); sb.append("AC$MASS_SPECTROMETRY: ION_MODE: " + AC_MASS_SPECTROMETRY_ION_MODE() + "\n"); if (AC_MASS_SPECTROMETRY() != null) { for (Pair<String, String> ac_mass_spectrometry : AC_MASS_SPECTROMETRY()) sb.append("AC$MASS_SPECTROMETRY: " + ac_mass_spectrometry.getKey() + " " + ac_mass_spectrometry.getValue() + "\n"); } if (AC_CHROMATOGRAPHY() != null) { for (Pair<String, String> ac_chromatography : AC_CHROMATOGRAPHY()) sb.append("AC$CHROMATOGRAPHY: " + ac_chromatography.getKey() + " " + ac_chromatography.getValue() + "\n"); } if (MS_FOCUSED_ION() != null) { for (Pair<String, String> ms_focued_ion : MS_FOCUSED_ION()) sb.append("MS$FOCUSED_ION: " + ms_focued_ion.getKey() + " " + ms_focued_ion.getValue() + "\n"); } if (MS_DATA_PROCESSING() != null) { for (Pair<String, String> ms_data_processing : MS_DATA_PROCESSING()) sb.append("MS$DATA_PROCESSING: " + ms_data_processing.getKey() + " " + ms_data_processing.getValue() + "\n"); } sb.append("PK$SPLASH: " + PK_SPLASH() + "\n"); if (PK_ANNOTATION_HEADER() != null) { sb.append("PK$ANNOTATION:"); for (String annotation_header_item : PK_ANNOTATION_HEADER()) sb.append(" " + annotation_header_item); sb.append("\n"); for (List<String> annotation_line : PK_ANNOTATION()) { sb.append(" "); for (String annotation_item : annotation_line) sb.append(" " + annotation_item); sb.append("\n"); } } sb.append("PK$NUM_PEAK: " + PK_NUM_PEAK() + "\n"); sb.append("PK$PEAK: m/z int. rel.int.\n"); for (List<Double> peak_line : PK_PEAK()) { sb.append(" "); for (Double peak_line_item : peak_line) sb.append(" " + peak_line_item.toString()); sb.append("\n"); } /* * // PK$ANNOTATION: m/z tentative_formula formula_count mass error(ppm) // * 57.0701 C4H9+ 1 57.0699 4.61 // 67.0542 C5H7+ 1 67.0542 0.35 // 69.0336 * C4H5O+ 1 69.0335 1.14 sb.append("PK$NUM_PEAK: " + this.PK$PEAK_MZ.length + * "\n"); sb.append("PK$PEAK: m/z int. rel.int." + "\n"); for(int idx = 0; idx < * this.PK$PEAK_MZ.length; idx++) sb.append(" " + this.PK$PEAK_MZ[idx] + " " + * this.PK$PEAK_INT[idx] + " " + this.PK$PEAK_REL[idx] + "\n"); */ sb.append("//"); return sb.toString(); }
From source file:edu.isistan.carcha.lsa.LSARunnerTest.java
/** * Test calculate metrics.//from w w w . ja v a2 s . c o m * * @param ccc * the crosscuttings concerns * @param ddd * the design decisions * @param golden * the golden * @param output * the output * @throws FileNotFoundException * the file not found exception * @throws IOException * Signals that an I/O exception has occurred. * @throws ClassNotFoundException * the class not found exception */ private void testGenerateTraceabilityResults(List<Entity> ccc, List<Entity> ddd, String golden, String output) throws FileNotFoundException, IOException, ClassNotFoundException { TraceabilityDocument goldenTra = Utils.readTraceabilityFromFile(golden); LSARunner runner; TraceabilityDocument result; logger.info("ccc: " + ccc.size()); logger.info("ddd: " + ddd.size()); for (Double th : threshold) { for (Integer dim : dimensions) { runner = new LSARunner(ccc, ddd, dim, th); result = runner.getTraceability(); logger.info("-----------------"); logger.info("threshold: " + th); logger.info("dimension: " + dim); calculateMetrics(result, goldenTra); Utils.writeTraceabilityToFile(result, output + "_" + dim + "_" + th.toString() + TRA); // Utils.writeTraceabilityToGephi(result, // output+"_"+dim+"_"+th.toString()+GEPHI); // Utils.writeMatrix(result, // output+"_"+dim+"_"+th.toString()+MX); // Utils.writeTraceabilityToFile(result, // output+"_"+dim+"_"+th.toString()+"-all"+TRA); } } }
From source file:net.groupbuy.controller.admin.ProductController.java
/** * // www. j a v a 2 s . c o m * * @param price * */ private BigDecimal calculateDefaultMarketPrice(BigDecimal price) { Setting setting = SettingUtils.get(); Double defaultMarketPriceScale = setting.getDefaultMarketPriceScale(); return setting.setScale(price.multiply(new BigDecimal(defaultMarketPriceScale.toString()))); }
From source file:org.alfresco.test.util.ContentAspectsTests.java
@Test public void addGeographicAspect() { Double longitude = 46.803138; Double latitude = 26.614806;//from ww w .jav a 2s . com contentAspect.addGeographicAspect(userName, password, siteName, plainDoc, longitude, latitude); List<Property<?>> properties = contentAspect.getProperties(userName, password, siteName, plainDoc); Assert.assertEquals(contentAspect.getPropertyValue(properties, "cm:longitude"), longitude.toString()); Assert.assertEquals(contentAspect.getPropertyValue(properties, "cm:latitude"), latitude.toString()); }
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
private void importDataToWorkbook(HSSFWorkbook xlsBook, Workbook workbook) { if (workbook.getObservations() != null) { HSSFSheet observationSheet = xlsBook.getSheetAt(1); int xlsRowIndex = 1; //row 0 is the header row for (MeasurementRow wRow : workbook.getObservations()) { HSSFRow xlsRow = observationSheet.getRow(xlsRowIndex); for (MeasurementData wData : wRow.getDataList()) { String label = wData.getLabel(); int xlsColIndex = findColumn(observationSheet, label); Cell cell = xlsRow.getCell(xlsColIndex); String xlsValue = ""; if (cell != null) { if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { Double doubleVal = Double.valueOf(cell.getNumericCellValue()); Integer intVal = Integer.valueOf(doubleVal.intValue()); if (Double.parseDouble(intVal.toString()) == doubleVal.doubleValue()) { xlsValue = intVal.toString(); } else { xlsValue = doubleVal.toString(); }// w ww.j ava 2 s . c o m } else xlsValue = cell.getStringCellValue(); } wData.setValue(xlsValue); } xlsRowIndex++; } } }