Example usage for java.math BigDecimal toPlainString

List of usage examples for java.math BigDecimal toPlainString

Introduction

In this page you can find the example usage for java.math BigDecimal toPlainString.

Prototype

public String toPlainString() 

Source Link

Document

Returns a string representation of this BigDecimal without an exponent field.

Usage

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

public static String convertToString(BigDecimal o) {
    return o.toPlainString();
}

From source file:uk.ac.leeds.ccg.andyt.projects.fluvialglacial.SlopeAreaScatterPlot.java

public SlopeAreaScatterPlot(int degree, Object[] data, ExecutorService executorService, File file,
        String format, String title, int dataWidth, int dataHeight, String xAxisLabel, String yAxisLabel,
        boolean drawOriginLinesOnPlot, int decimalPlacePrecisionForCalculations,
        int decimalPlacePrecisionForDisplay, RoundingMode aRoundingMode) {
    init(executorService, file, format, title, dataWidth, dataHeight, xAxisLabel, yAxisLabel,
            drawOriginLinesOnPlot, decimalPlacePrecisionForCalculations, decimalPlacePrecisionForDisplay,
            aRoundingMode);//from   w  w  w.j ava  2  s. co m
    setStartAgeOfEndYearInterval(0);
    setData(data);
    PolynomialCurveFitter pcf;
    pcf = PolynomialCurveFitter.create(degree);
    final WeightedObservedPoints obs = new WeightedObservedPoints();
    ArrayList<Generic_XYNumericalData> theGeneric_XYNumericalData;
    theGeneric_XYNumericalData = (ArrayList<Generic_XYNumericalData>) data[0];
    Iterator<Generic_XYNumericalData> ite;
    ite = theGeneric_XYNumericalData.iterator();
    Generic_XYNumericalData generic_XYNumericalData;
    while (ite.hasNext()) {
        generic_XYNumericalData = ite.next();
        obs.add(generic_XYNumericalData.x.doubleValue(), generic_XYNumericalData.y.doubleValue());
    }
    double[] coeffs = pcf.fit(obs.toList());
    title += ", y = ";
    BigDecimal coeffBD;
    String coeffS;

    double a = 0.0d;
    double b = 0.0d;
    double c = 0.0d;
    for (int i = coeffs.length - 1; i > -1; i--) {
        System.out.println(coeffs[i]);
        coeffBD = Generic_BigDecimal.roundToAndSetDecimalPlaces(BigDecimal.valueOf(coeffs[i]),
                decimalPlacePrecisionForDisplay, aRoundingMode);
        coeffS = coeffBD.toPlainString();
        String s;
        s = getCoeff(coeffBD, coeffS);
        if (i > 1) {
            if (!s.isEmpty()) {
                title += "(" + s + "*x^" + i + ")+";
            }

            if (i == 2) {
                a = Double.valueOf(s);
            }

        } else if (i == 1) {
            if (!s.isEmpty()) {
                title += "(" + s + "*x)";
                b = Double.valueOf(s);
            } else {
                b = 0.0d;
            }
        } else if (!s.isEmpty()) {
            title += s;
            c = Double.valueOf(s);
        } else {
            c = 0.0d;
        }
        //title += "" + coeffs[i] + ",";
    }
    //title = title.substring(0, (title.length() - 3));
    //title += ")";

    PolynomialFunction pf;
    pf = new PolynomialFunction(coeffs);
    double minx = getMinX().doubleValue();
    double maxx = getMaxX().doubleValue();
    double range = maxx - minx;
    int intervals = 100;
    double interval = range / (double) intervals;

    maxy = Double.NEGATIVE_INFINITY;

    double x;
    double y;
    bestfit = new ArrayList<Generic_XYNumericalData>();
    for (int i = 0; i < 100; i++) {
        x = minx + interval * i;
        y = pf.value(x);
        if (y > maxy) {
            maxy = y;
            xAtMaxy = x;
        }
        generic_XYNumericalData = new Generic_XYNumericalData(BigDecimal.valueOf(x), BigDecimal.valueOf(y));
        bestfit.add(generic_XYNumericalData);
    }

    maxy2 = Double.NEGATIVE_INFINITY;
    if (a < 0) {
        maxy2 = c - ((b * b) / (4.0d * a));
        xAtMaxy2 = (-1.0d * b) / (2.0d * a);
        isHump = true;
    } else {
        isHump = false;
    }

    double SRMSE = 0.0d;
    double deltay;
    ite = theGeneric_XYNumericalData.iterator();
    while (ite.hasNext()) {
        generic_XYNumericalData = ite.next();
        x = generic_XYNumericalData.x.doubleValue();
        y = generic_XYNumericalData.y.doubleValue();
        deltay = Math.sqrt(Math.pow(y - pf.value(x), 2));
        SRMSE += deltay;
    }
    double MRMSE = SRMSE / (double) theGeneric_XYNumericalData.size();
    title += ", MRMSE = " + (Generic_BigDecimal.roundToAndSetDecimalPlaces(BigDecimal.valueOf(MRMSE),
            decimalPlacePrecisionForDisplay, aRoundingMode)).toPlainString();
    setTitle(title);
}

From source file:eionet.gdem.conversion.spreadsheet.SourceReaderLogger.java

/**
 * End reading spreadsheet./*from   w w w. ja v a2  s .c  o m*/
 * @param fileSize File size
 */
public void logEndWorkbook(long fileSize) {
    BigDecimal totalTime = new BigDecimal(System.currentTimeMillis() - startTimestamp)
            .divide(new BigDecimal("1000.0"));
    String fileSizeMessage = "";
    if (fileSize > 0) {
        fileSizeMessage = FileUtils.byteCountToDisplaySize(fileSize);
    }
    String message = Properties.getMessage(BusinessConstants.CONVERSION_LOG_END_SPREADSHEET,
            new String[] { fileSizeMessage, totalTime.toPlainString() });
    conversionResult.addConversionLog(ConversionLogType.INFO, message, ConversionLogDto.CATEGORY_WORKBOOK);
    LOGGER.info(message);
}

From source file:net.jmhertlein.alphonseirc.AlphonseBot.java

private void handleBillyCommand(String target) {
    sendMessage(target, "Measuring Billium levels...");
    int total = previousSenders.size(), billy = 0;
    for (String previousSender : previousSenders) {
        if (previousSender.equals("brodes")) {
            billy++;// w w w  . j a  va  2  s  . c  o  m
        }
    }
    if (total > 0) {
        BigDecimal conc = new BigDecimal(((float) billy) / total * 100);
        sendMessage(target, "Current Billium concentration: " + conc.toPlainString() + "%");
        String status;
        if (conc.compareTo(new BigDecimal(80)) > 0) {
            status = "!!DANGER!! OVERDOSE IMMENENT";
        } else if (conc.compareTo(new BigDecimal(50)) > 0) {
            status = "WARNING - DANGEROUS LEVELS";
        } else if (conc.compareTo(new BigDecimal(30)) > 0) {
            status = "Caution - Levels rising, but stable";
        } else {
            status = "Billium levels negligible.";
        }
        sendMessage(target, "Current status: " + status);
    } else {
        sendMessage(target, "Billium levels negligible.");
    }
}

From source file:net.samuelbjohnson.javadev.crosstopix.Joiner.java

public boolean join(Statement imslpStatement, Statement cpdlStatement, boolean fullOutput)
        throws NoSuchAlgorithmException, RepositoryException {
    BigDecimal distance = computeDistance(imslpStatement.getObject().stringValue(),
            cpdlStatement.getObject().stringValue());

    if (!fullOutput) {
        outputWriter.print(imslpStatement.getObject().stringValue().length() + ",");
        outputWriter.print(cpdlStatement.getObject().stringValue().length() + ",");
        outputWriter.println(distance);//  w w w  .  j  a  va  2 s.  c  o  m
        return true;
    }

    MessageDigest md5 = MessageDigest.getInstance("MD5");
    md5.update((imslpStatement.getObject().stringValue() + cpdlStatement.getObject().stringValue()
            + distance.toPlainString()).getBytes());
    BigInteger hashInt = new BigInteger(1, md5.digest());
    String md5Sum = hashInt.toString(16);

    Resource subject = valueFactory.createURI(subjectNamespace, md5Sum);
    URI predicateImslp = valueFactory.createURI(predicateNamespace, "comparable_1");
    URI predicateCpdl = valueFactory.createURI(predicateNamespace, "comparable_2");
    URI predicateDiff = valueFactory.createURI(predicateNamespace, "similarity");

    outputRepCon.add(subject, predicateImslp, imslpStatement.getSubject());
    outputRepCon.add(subject, predicateCpdl, cpdlStatement.getSubject());
    outputRepCon.add(subject, predicateDiff, valueFactory.createLiteral(distance.doubleValue()));

    outputRepCon.commit();

    return true;
}

From source file:jduagui.Controller.java

private String twoDecimals(BigDecimal d, String suffix) {
    String decimal = d.toPlainString();
    int pos = decimal.indexOf('.') + 3;
    if (pos > decimal.length())
        pos = decimal.length();/*  www.  j a va2s  . com*/
    return decimal.substring(0, pos) + suffix;
}

From source file:org.diretto.web.richwebclient.view.sections.UploadSection.java

/**
 * Uploads the currently processed file.
 * /*from   w  ww.j a  va 2s.  c  o m*/
 * @param uploadSettings The {@code UploadSettings} of the file
 * @param filesWithSameSettings A {@code List} with the names of the files
 *        which should get the given {@code UploadSettings} as presetting
 */
public void upload(final UploadSettings uploadSettings, List<String> filesWithSameSettings) {
    final FileInfo fileInfo = currentFile;

    settings.put(fileInfo.getName(), uploadSettings);

    for (String fileName : filesWithSameSettings) {
        preSettings.put(fileName, uploadSettings);
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            ProgressIndicator progressIndicator = multipleUpload.upload(fileInfo);

            synchronized (application) {
                VerticalLayout uploadBoxLayout = new VerticalLayout();
                mainLayout.addComponent(uploadBoxLayout);

                HorizontalLayout fileInfoLayout = new HorizontalLayout();
                uploadBoxLayout.addComponent(fileInfoLayout);

                Label nameLabel = StyleUtils.getLabelBold(fileInfo.getName());
                fileInfoLayout.addComponent(nameLabel);
                fileInfoLayout.addComponent(StyleUtils.getLabelSmallHTML("&nbsp;&nbsp;&nbsp;"));
                fileInfoLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_LEFT);

                BigDecimal fileSize = new BigDecimal((((double) fileInfo.getSize()) / 1000000.0d));
                fileSize = fileSize.setScale(2, BigDecimal.ROUND_HALF_UP);

                Label typeSizeLabel = StyleUtils.getLabelSmallHTML(
                        fileInfo.getType() + "&nbsp;&nbsp;--&nbsp;&nbsp;" + fileSize.toPlainString() + " MB");
                fileInfoLayout.addComponent(typeSizeLabel);
                fileInfoLayout.setComponentAlignment(typeSizeLabel, Alignment.MIDDLE_LEFT);

                uploadBoxLayout.addComponent(StyleUtils.getVerticalSpace("100%", "8px"));

                uploadBoxLayout.addComponent(progressIndicator);

                uploadBoxLayout.addComponent(StyleUtils.getVerticalSpace("100%", "8px"));

                HorizontalLayout resultLayout = new HorizontalLayout();
                uploadBoxLayout.addComponent(resultLayout);

                Label uploadedLabel = StyleUtils.getLabelSmallHTML("Uploaded:&nbsp;");
                resultLayout.addComponent(uploadedLabel);
                resultLayout.setComponentAlignment(uploadedLabel, Alignment.MIDDLE_LEFT);

                Embedded uploadedEmbedded = new Embedded(null, ResourceUtils.RUNO_ICON_32_GLOBE_RESOURCE);
                uploadedEmbedded.addStyleName("image-opacity-65");
                uploadedEmbedded.setType(Embedded.TYPE_IMAGE);
                uploadedEmbedded.setImmediate(true);
                uploadedEmbedded.setWidth("22px");
                uploadedEmbedded.setHeight("22px");
                resultLayout.addComponent(uploadedEmbedded);

                uploadedEmbeddeds.put(fileInfo, uploadedEmbedded);

                resultLayout.addComponent(StyleUtils.getLabelSmallHTML("&nbsp;&nbsp;&nbsp;"));

                Label publishedLabel = StyleUtils.getLabelSmallHTML("Published:&nbsp;");
                resultLayout.addComponent(publishedLabel);
                resultLayout.setComponentAlignment(publishedLabel, Alignment.MIDDLE_LEFT);

                Embedded publishedEmbedded = new Embedded(null, ResourceUtils.RUNO_ICON_32_GLOBE_RESOURCE);
                publishedEmbedded.addStyleName("image-opacity-65");
                publishedEmbedded.setType(Embedded.TYPE_IMAGE);
                publishedEmbedded.setImmediate(true);
                publishedEmbedded.setWidth("22px");
                publishedEmbedded.setHeight("22px");
                resultLayout.addComponent(publishedEmbedded);

                publishedEmbeddeds.put(fileInfo, publishedEmbedded);

                mainLayout.addComponent(StyleUtils.getVerticalSpace("100%", "5px"));

                requestRepaint();
            }
        }
    }).start();

    handleNextFile();
}

From source file:org.broadleafcommerce.core.search.service.solr.SolrHelperServiceImpl.java

@Override
public String getSolrRangeFunctionString(BigDecimal minValue, BigDecimal maxValue) {
    StringBuilder sb = new StringBuilder();

    sb.append("frange incl=false l=").append(minValue.toPlainString());
    if (maxValue != null) {
        sb.append(" u=").append(maxValue.toPlainString());
    }//from   ww  w  .  j a v a  2 s . c  o  m

    return sb.toString();
}

From source file:ca.uhn.fhir.jpa.dao.dstu3.SearchParamExtractorDstu3.java

@Override
public Set<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity,
        IBaseResource theResource) {//from  ww  w . jav  a  2s. com
    HashSet<ResourceIndexedSearchParamString> retVal = new HashSet<ResourceIndexedSearchParamString>();

    RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
    for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
        if (nextSpDef.getParamType() != RestSearchParameterTypeEnum.STRING) {
            continue;
        }

        String nextPath = nextSpDef.getPath();
        String resourceName = nextSpDef.getName();

        if (isBlank(nextPath)) {

            // TODO: implement phonetic, and any others that have no path

            if ("Questionnaire".equals(def.getName()) && nextSpDef.getName().equals("title")) {
                Questionnaire q = (Questionnaire) theResource;
                String title = "";// q.getGroup().getTitle();
                addSearchTerm(theEntity, retVal, resourceName, title);
            }
            continue;
        }

        for (Object nextObject : extractValues(nextPath, theResource)) {
            if (nextObject == null || ((IBase) nextObject).isEmpty()) {
                continue;
            }

            boolean multiType = false;
            if (nextPath.endsWith("[x]")) {
                multiType = true;
            }

            if (nextObject instanceof IPrimitiveType<?>) {
                IPrimitiveType<?> nextValue = (IPrimitiveType<?>) nextObject;
                String searchTerm = nextValue.getValueAsString();
                addSearchTerm(theEntity, retVal, resourceName, searchTerm);
            } else {
                if (nextObject instanceof HumanName) {
                    ArrayList<StringType> allNames = new ArrayList<StringType>();
                    HumanName nextHumanName = (HumanName) nextObject;
                    allNames.addAll(nextHumanName.getFamily());
                    allNames.addAll(nextHumanName.getGiven());
                    for (StringType nextName : allNames) {
                        addSearchTerm(theEntity, retVal, resourceName, nextName.getValue());
                    }
                } else if (nextObject instanceof Address) {
                    ArrayList<StringType> allNames = new ArrayList<StringType>();
                    Address nextAddress = (Address) nextObject;
                    allNames.addAll(nextAddress.getLine());
                    allNames.add(nextAddress.getCityElement());
                    allNames.add(nextAddress.getStateElement());
                    allNames.add(nextAddress.getCountryElement());
                    allNames.add(nextAddress.getPostalCodeElement());
                    for (StringType nextName : allNames) {
                        addSearchTerm(theEntity, retVal, resourceName, nextName.getValue());
                    }
                } else if (nextObject instanceof ContactPoint) {
                    ContactPoint nextContact = (ContactPoint) nextObject;
                    if (nextContact.getValueElement().isEmpty() == false) {
                        addSearchTerm(theEntity, retVal, resourceName, nextContact.getValue());
                    }
                } else if (nextObject instanceof Quantity) {
                    BigDecimal value = ((Quantity) nextObject).getValue();
                    if (value != null) {
                        addSearchTerm(theEntity, retVal, resourceName, value.toPlainString());
                    }
                } else if (nextObject instanceof Range) {
                    SimpleQuantity low = ((Range) nextObject).getLow();
                    if (low != null) {
                        BigDecimal value = low.getValue();
                        if (value != null) {
                            addSearchTerm(theEntity, retVal, resourceName, value.toPlainString());
                        }
                    }
                } else {
                    if (!multiType) {
                        throw new ConfigurationException("Search param " + resourceName
                                + " is of unexpected datatype: " + nextObject.getClass());
                    }
                }
            }
        }
    }

    return retVal;
}