Example usage for java.lang Double toString

List of usage examples for java.lang Double toString

Introduction

In this page you can find the example usage for java.lang Double toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this Double object.

Usage

From source file:de.bund.bfr.pmfml.sbml.UncertaintiesImpl.java

/**
 * Creates a UncertaintiesImpl instance.
 * /*from w ww . j  a  va  2 s  . c  o m*/
 * @param id: Ignored if null.
 * @param comment: Ignored if null or empty string.
 * @param r2: Ignored if null.
 * @param rms: Ignored if null.
 * @param sse: Ignored if null.
 * @param aic: Ignored if null.
 * @param bic: Ignored if null.
 * @param dof: Ignored if null.
 */
public UncertaintiesImpl(final Integer id, final String modelName, final String comment, final Double r2,
        final Double rms, final Double sse, final Double aic, final Double bic, final Integer dof) {
    props = new HashMap<>(9);
    if (id != null)
        props.put(ID, id.toString());
    if (StringUtils.isNotEmpty(modelName))
        props.put(MODEL_NAME, modelName);
    if (StringUtils.isNotEmpty(comment))
        props.put(COMMENT, comment);
    if (r2 != null)
        props.put(R2, r2.toString());
    if (rms != null)
        props.put(RMS, rms.toString());
    if (sse != null)
        props.put(SSE, sse.toString());
    if (aic != null)
        props.put(AIC, aic.toString());
    if (bic != null)
        props.put(BIC, bic.toString());
    if (dof != null)
        props.put(DOF, dof.toString());
}

From source file:com.sesnu.orion.web.service.ReportService.java

public String generateOrderAuthReport(Approval appr, String state) throws DocumentException, IOException {
    Bid bid = bidDao.get(appr.getForId());
    OrderView order = orderDao.get(bid.getOrderRef());
    Item item = itemDao.get(order.getItemId());
    List<BidView> bids = bidDao.list(order.getId());

    String orginalHtml = conf.getFile("orderAuth.html");
    Estimate est = estService.totalEstimate(order, null, bid, item);

    String editedHtml = orginalHtml.replace("ORDER_DATE", Util.parseDate(order.getCreatedOn()));
    editedHtml = setPaths(editedHtml, state);
    editedHtml = editedHtml.replace("PRODUCT_NAME", item.getName());
    editedHtml = editedHtml.replace("ORDERED_BY", order.getOrderedBy());
    editedHtml = editedHtml.replace("BRAND_NAME", item.getBrand());
    editedHtml = editedHtml.replace("DEPARTMENT", "Import"); // whose department ?
    editedHtml = editedHtml.replace("PACKAGING",
            order.getBaseSize().toString() + order.getBaseUnit() + "X" + order.getQtyPerPack() + "pcs");
    editedHtml = editedHtml.replace("BUDGET_REF", order.getBudgetRef());
    editedHtml = editedHtml.replace("QTY_PER_CONT", order.getPckPerCont().toString());
    editedHtml = editedHtml.replace("DESTINATION", order.getDestinationPort());
    editedHtml = editedHtml.replace("QUANTITY", order.getContQnt() + "X" + order.getContSize() + "'");
    editedHtml = editedHtml.replace("LATEST_ETA", Util.parseDate(order.getLatestETA()));

    editedHtml = editedHtml.replace("IN_TRANSIT", shipDao.InTransitCount(item.getId()).toString());
    editedHtml = editedHtml.replace("IN_PORT", shipDao.InPortCount(item.getId()).toString());
    editedHtml = editedHtml.replace("IN_TERMINAL", shipDao.InTerminalCount(item.getId()).toString());
    BigInteger newItemOrders = orderDao.newOrdersCount(item.getId()).subtract(new BigInteger("1"));
    editedHtml = editedHtml.replace("NEW_ORDERS", newItemOrders.toString());
    editedHtml = editedHtml.replace("ORDER_DATE", bid.getUpdatedOn());

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bids.size(); i++) {
        BidView abid = bids.get(i);/*from  w  w w. j a  v a2s.  co m*/
        sb.append("<tr>");
        sb.append("<td>");
        sb.append(i + 1);
        sb.append("</td>");
        sb.append("<td>");
        sb.append(abid.getSupplier());
        sb.append("</td>");
        sb.append("<td>");
        sb.append(abid.getCifCnf());
        sb.append("</td>");
        sb.append("<td>");
        sb.append(abid.getFob());
        sb.append("</td>");
        sb.append("<td>");
        sb.append(abid.getCurrency());
        sb.append("</td>");
        sb.append("<td>");
        sb.append(abid.getPaymentMethod() == null ? "" : abid.getPaymentMethod());
        sb.append("</td>");
        sb.append("<td>");
        sb.append(abid.isSelected() ? "Yes" : "No");
        sb.append("</td>");
        sb.append("<td>");
        sb.append(abid.getRemark() == null ? "" : abid.getRemark());
        sb.append("</td>");
        sb.append("</tr>");
    }

    editedHtml = editedHtml.replace("BID_DATA_TABLE", sb.toString());
    editedHtml = editedHtml.replace("EST_TRANSIT_DAYS", bid.getEstTransitDays().toString());
    Calendar c = Calendar.getInstance();
    c.setTime(order.getLatestETA());
    c.add(Calendar.DATE, bid.getEstTransitDays());
    editedHtml = editedHtml.replace("LATEST_DATE_OF_SHIP", Util.parseDate(c.getTime()));
    editedHtml = editedHtml.replace("IMPORTER", order.getImporter());

    Exchange cur = exchangeDao.get("Other", "Other", "USD", "AOA");
    if (cur == null) {
        return null;
    }

    editedHtml = editedHtml.replace("TOTAL_CNF_USD", Util.parseCurrency(bid.getTotalBid()));
    Double pricePerPack = (bid.getTotalBid() * cur.getRate() + est.getValue()) / order.getContQnt()
            / order.getPckPerCont();
    pricePerPack = pricePerPack / cur.getRate();
    pricePerPack = (double) (Math.round(pricePerPack * 100.0) / 100);
    editedHtml = editedHtml.replace("LANDED_COST_TO_WH", pricePerPack.toString());
    Double totalEstPrice = pricePerPack * 1.12;
    editedHtml = editedHtml.replace("COST_PLUS_MRG", totalEstPrice.toString());
    String emailTo = appr.getRequestedBy() + " [" + (userDao.getUserName(appr.getRequestedBy())).getEmail()
            + "]";
    String emailCC = appr.getApprover() + " [" + (userDao.getUserName(appr.getApprover())).getEmail() + "]";
    editedHtml = editedHtml.replace("EMAIL_TO", emailTo);
    editedHtml = editedHtml.replace("EMAIL_CC", emailCC);

    if (!state.equals("preview")) {
        editedHtml = editedHtml.replace("SIGNATURE", appr.getApprover());
        editedHtml = editedHtml.replace("APPROVED_ON", new Date().toGMTString());
        String pdfFilePath = util.convertToPdf(editedHtml); // convert to pdf
        Path path = Paths.get(pdfFilePath);

        byte[] data = Files.readAllBytes(path); // convert to byte array
        String[] frag = pdfFilePath.split("/");
        String fileName = frag[frag.length - 1]; // get file name
        util.writeToS3(data, fileName); // write to s3
        sendApprovalEmail(appr, pdfFilePath, order);
        Files.deleteIfExists(path);

        Document doc = new Document(order.getId(), fileName, "Order Authorization", Util.parseDate(new Date()),
                "");
        docDao.saveOrUpdate(doc);
    } else {
        editedHtml = editedHtml.replace("APPROVED_ON", "");
    }
    return editedHtml;
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.xlsx.XLSXFileReader.java

/**
 * Reads an XLSX file, converts it into a dataverse DataTable.
 *
 * @param stream a <code>BufferedInputStream</code>.
 * @param ignored/*from  w  w  w . j a va 2 s. co m*/
 * @return an <code>TabularDataIngest</code> object
 * @throws java.io.IOException if a reading error occurs.
 */
@Override
public TabularDataIngest read(BufferedInputStream stream, File dataFile) throws IOException {
    init();

    TabularDataIngest ingesteddata = new TabularDataIngest();
    DataTable dataTable = new DataTable();

    File firstPassTempFile = File.createTempFile("firstpass-", ".tab");
    PrintWriter firstPassWriter = new PrintWriter(firstPassTempFile.getAbsolutePath());
    try {
        processSheet(stream, dataTable, firstPassWriter);
    } catch (Exception ex) {
        throw new IOException("Could not parse Excel/XLSX spreadsheet. " + ex.getMessage());
    }

    if (dataTable.getCaseQuantity() == null || dataTable.getCaseQuantity().intValue() < 1) {
        String errorMessage;
        if (dataTable.getVarQuantity() == null || dataTable.getVarQuantity().intValue() < 1) {
            errorMessage = "No rows of data found in the Excel (XLSX) file.";
        } else {
            errorMessage = "Only one row of data (column name header?) detected in the Excel (XLSX) file.";
        }
        throw new IOException(errorMessage);
    }

    // 2nd pass:

    File tabFileDestination = File.createTempFile("data-", ".tab");
    PrintWriter finalWriter = new PrintWriter(tabFileDestination.getAbsolutePath());

    BufferedReader secondPassReader = new BufferedReader(new FileReader(firstPassTempFile));

    int varQnty = dataTable.getVarQuantity().intValue();
    int lineCounter = 0;
    String line = null;
    String[] caseRow = new String[varQnty];
    String[] valueTokens;

    while ((line = secondPassReader.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) + " during the second pass.");
        }

        if (valueTokens.length != varQnty) {
            throw new IOException("Reading mismatch, line " + (lineCounter + 1) + " during the second pass: "
                    + varQnty + " delimited values expected, " + valueTokens.length + " found.");
        }

        for (int i = 0; i < varQnty; i++) {
            if (dataTable.getDataVariables().get(i).isTypeNumeric()) {
                if (valueTokens[i] == null || valueTokens[i].equals(".") || valueTokens[i].equals("")
                        || valueTokens[i].equalsIgnoreCase("NA")) {
                    // Missing value - represented as an empty string in 
                    // the final tab file
                    caseRow[i] = "";
                } else if (valueTokens[i].equalsIgnoreCase("NaN")) {
                    // "Not a Number" special value: 
                    caseRow[i] = "NaN";
                } else if (valueTokens[i].equalsIgnoreCase("Inf") || valueTokens[i].equalsIgnoreCase("+Inf")) {
                    // Positive infinity:
                    caseRow[i] = "Inf";
                } else if (valueTokens[i].equalsIgnoreCase("-Inf")) {
                    // Negative infinity: 
                    caseRow[i] = "-Inf";
                } else if (valueTokens[i].equalsIgnoreCase("null")) {
                    // By request from Gus - "NULL" is recognized as a 
                    // numeric zero: 
                    caseRow[i] = "0";
                } else {
                    try {
                        Double testDoubleValue = new Double(valueTokens[i]);
                        caseRow[i] = testDoubleValue.toString();
                    } catch (Exception ex) {
                        throw new IOException(
                                "Failed to parse a value recognized as numeric in the first pass! column: " + i
                                        + ", value: " + valueTokens[i]);
                    }
                }
            } else {
                // Treat as a String:
                // Strings are stored in tab files quoted;                                                                                   
                // Missing values are stored as tab-delimited nothing - 
                // i.e., an empty string between two tabs (or one tab and 
                // the new line);                                                                       
                // Empty strings stored as "" (quoted empty string).

                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:
                    charToken = "\"" + charToken + "\"";
                    caseRow[i] = charToken;
                } else {
                    caseRow[i] = "";
                }
            }
        }

        finalWriter.println(StringUtils.join(caseRow, "\t"));
        lineCounter++;

    }

    secondPassReader.close();
    finalWriter.close();

    if (dataTable.getCaseQuantity().intValue() != lineCounter) {
        throw new IOException("Mismatch between line counts in first and final passes!");
    }

    dataTable.setUnf("UNF:6:NOTCALCULATED");

    ingesteddata.setTabDelimitedFile(tabFileDestination);
    ingesteddata.setDataTable(dataTable);

    dbglog.fine("Produced temporary file " + ingesteddata.getTabDelimitedFile().getAbsolutePath());
    dbglog.fine("Found " + dataTable.getVarQuantity() + " variables, " + dataTable.getCaseQuantity()
            + " observations.");
    String varNames = null;
    for (int i = 0; i < dataTable.getVarQuantity().intValue(); i++) {
        if (varNames == null) {
            varNames = dataTable.getDataVariables().get(i).getName();
        } else {
            varNames = varNames + ", " + dataTable.getDataVariables().get(i).getName();
        }
    }
    dbglog.fine("Variable names: " + varNames);

    return ingesteddata;

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.scientificCouncil.credits.ViewTeacherCreditsReportDispatchAction.java

private Double fillSpreadSheet(final List<TeacherCreditsReportDTO> allListElements,
        final Spreadsheet spreadsheet) {

    Double listTotalCredits = 0.0;
    int numberOfCells = 0;
    for (final TeacherCreditsReportDTO teacherCreditsReportDTO : allListElements) {
        final Row row = spreadsheet.addRow();
        row.setCell(teacherCreditsReportDTO.getTeacher().getPerson().getIstUsername());
        row.setCell(teacherCreditsReportDTO.getTeacher().getPerson().getName());
        Double pastCredits = NumberUtils.formatNumber(teacherCreditsReportDTO.getPastCredits(), 2);
        row.setCell(pastCredits.toString().replace('.', ','));
        Set<ExecutionSemester> executionSemesters = teacherCreditsReportDTO.getCreditsByExecutionPeriod()
                .keySet();/* w ww. j a  va 2s.c  o  m*/
        Double totalCredits = 0.0;
        totalCredits += teacherCreditsReportDTO.getPastCredits();
        numberOfCells = 2;
        for (ExecutionSemester executionSemester : executionSemesters) {
            numberOfCells += 1;
            Double credits = teacherCreditsReportDTO.getCreditsByExecutionPeriod().get(executionSemester);
            credits = NumberUtils.formatNumber(credits, 2);
            row.setCell(credits.toString().replace('.', ','));
            totalCredits += credits;
            if (executionSemester.getSemester() == 2) {
                numberOfCells += 1;
                totalCredits = NumberUtils.formatNumber(totalCredits, 2);
                row.setCell(totalCredits.toString().replace('.', ','));
            }
        }
        listTotalCredits += totalCredits;
    }
    final Row row = spreadsheet.addRow();
    row.setCell(numberOfCells - 1, "Total Unidade");
    row.setCell(numberOfCells, NumberUtils.formatNumber(listTotalCredits, 2).toString().replace('.', ','));
    return listTotalCredits;
}

From source file:com.nestof.paraweather.utils.LocationConverter.java

/**
 * Returns the Decimal Degrees that corresponds to the DMS values entered.
 * Requires values in Degrees, Minutes, Seconds, and Direction
 *
 * @return String/*from   www.  j  a va  2 s.co  m*/
 */
public String toDecimalDegrees(String location) {
    degrees = StringUtils.substringBefore(location, "").trim();
    minutes = StringUtils.substringBetween(location, "", "'").trim();
    seconds = StringUtils.substringBetween(location, "'", "\"").trim();
    direction = StringUtils.substringAfter(location, "\"").trim();

    String returnString = null;

    Double dblDegree;
    Double dblMinutes;
    Double dblSeconds;
    Double decDegrees;
    String CompassDirection;

    dblDegree = Double.parseDouble(getDegrees());
    dblMinutes = Double.parseDouble(getMinutes());
    dblSeconds = Double.parseDouble(getSeconds());

    CompassDirection = getDirection();

    decDegrees = dblDegree + (dblMinutes / 60) + (dblSeconds / 3600);

    if (CompassDirection.equalsIgnoreCase("S"))
        decDegrees = decDegrees * -1;

    if (CompassDirection.equalsIgnoreCase("W"))
        decDegrees = decDegrees * -1;

    returnString = decDegrees.toString() + direction;

    return returnString;
}

From source file:com.cheddargetter.client.service.CheddarGetterPaymentService.java

public Customer addCustomCharge(String customerCode, String chargeCode, Integer quantity, Double eachAmount,
        String description, String invoicePeriod, String remoteAddress) throws PaymentException {

    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put("chargeCode", chargeCode);
    paramMap.put("quantity", quantity.toString());
    paramMap.put("eachAmount", eachAmount.toString());
    if (description != null) {
        paramMap.put("description", description);
    }// w w  w .  j  a  v  a 2  s.c om
    if (invoicePeriod != null) {
        paramMap.put("invoicePeriod", invoicePeriod);
    }
    if (remoteAddress != null) {
        paramMap.put("remoteAddress", remoteAddress);
    }

    return firstCustomer(makeServiceCall(Customers.class,
            "/customers/add-charge/productCode/" + getProductCode() + "/code/" + customerCode, paramMap));
}

From source file:de.fhg.fokus.odp.middleware.unittest.xTestCKANGateway.java

/**
 * Test the getPackageRatingsAverage method.
 *//*from   w w w. j a  va 2 s  .c o m*/
@Test
public void testGetDataSetRatingsAverage() {
    log.fine("########### GET AVERAGE RATING ###########");
    Double avRating = ckanGW.getDataSetRatingsAverage(DATASET_NAME);
    assertEquals(true, (avRating <= 5) && (avRating >= 0));
    log.fine(avRating.toString());
}

From source file:com.nestof.paraweather.utils.LocationConverter.java

/**
 * Returns a formatted DMS String using value loaded into DecimalDegrees ie.
 * DD MM' SS" E//from   ww w  . java  2 s  . c o  m
 *
 * @return String
 */
public String toDMS(String DecimalDegreesAndMinutes, String type) {
    this.type = type;

    String returnstring = null;
    Double DegreesAndMinutes;
    Integer decDegrees;
    Integer decMinutes;
    Double decSeconds;

    DegreesAndMinutes = Double.parseDouble(DecimalDegreesAndMinutes);
    decDegrees = (int) DegreesAndMinutes.doubleValue();
    decMinutes = (int) ((DegreesAndMinutes.doubleValue() - decDegrees) * 60);
    decSeconds = ((((DegreesAndMinutes.doubleValue() - decDegrees) * 60) - decMinutes) * 60);

    decDegrees = Math.abs(decDegrees);
    decMinutes = Math.abs(decMinutes);
    decSeconds = Math.abs(decSeconds);

    setDegrees(decDegrees.toString());
    setMinutes(decMinutes.toString());
    setSeconds(decSeconds.toString());

    if (getType().equalsIgnoreCase("Latitude")) {
        if (Double.parseDouble(getDegrees()) < 0) {
            setDirection("S");
        } else {
            setDirection("N");
        }
    }

    if (getType().equalsIgnoreCase("Longitude")) {
        if (Double.parseDouble(getDegrees()) < 0) {
            setDirection("W");
        } else {
            setDirection("E");
        }
    }

    returnstring = toFormattedDMSString();

    return returnstring;

}

From source file:playground.artemc.analysis.AnalysisControlerListener.java

private void addMonetaryExpensesToPlanAttributes(IterationEndsEvent event) {
    for (Person person : event.getControler().getScenario().getPopulation().getPersons().values()) {
        Double monetaryPayments = moneyHandler.getPersonId2amount().get(person.getId());
        if (monetaryPayments == null) {
            monetaryPayments = 0.0;/*www  .j  a va  2 s. c  om*/
        }
        person.getSelectedPlan().getCustomAttributes().put("toll", monetaryPayments.toString());
        event.getControler().getScenario().getPopulation().getPersonAttributes()
                .putAttribute(person.getId().toString(), "selectedPlanToll", monetaryPayments.toString());
    }
}

From source file:sandbox.sfwatergit.analysis.runtime.AnalysisControlerListener.java

private void addMonetaryExpensesToPlanAttributes(IterationEndsEvent event) {
    for (Person person : event.getServices().getScenario().getPopulation().getPersons().values()) {
        Double monetaryPayments = moneyHandler.getPersonId2amount().get(person.getId());
        if (monetaryPayments == null) {
            monetaryPayments = 0.0;/*  w  w  w .j  a  v  a  2s .c  o  m*/
        }
        person.getSelectedPlan().getCustomAttributes().put("toll", monetaryPayments.toString());
        event.getServices().getScenario().getPopulation().getPersonAttributes()
                .putAttribute(person.getId().toString(), "selectedPlanToll", monetaryPayments.toString());
    }
}