Example usage for java.math BigDecimal valueOf

List of usage examples for java.math BigDecimal valueOf

Introduction

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

Prototype

public static BigDecimal valueOf(double val) 

Source Link

Document

Translates a double into a BigDecimal , using the double 's canonical string representation provided by the Double#toString(double) method.

Usage

From source file:com.excilys.ebi.bank.web.tld.Functions.java

public static String amount(BigDecimal amount) {

    StringBuilder buf = new StringBuilder();
    buf.append("<span class=\"figure ").append(amount.compareTo(BigDecimal.valueOf(0.0)) >= 0 ? "green" : "red")
            .append("\">").append(amount).append("</span>");
    return buf.toString();
}

From source file:net.eusashead.hateoas.hal.response.impl.OrderRepository.java

public Order getOrder(Integer id) {
    return new Order(id, BigDecimal.valueOf(12.34d), new Date(123456789l));
}

From source file:com.qcadoo.model.api.BigDecimalUtils.java

/**
 * Converts value, if null returns zero// w  ww  .j  a va  2  s .c  o  m
 * 
 * @param value
 *            value
 * 
 * @return value or zero
 */
public static BigDecimal convertNullToZero(final Object value) {
    if (value == null) {
        return BigDecimal.ZERO;
    }
    if (value instanceof BigDecimal) {
        return (BigDecimal) value;
    }
    return BigDecimal.valueOf(Double.valueOf(value.toString()));
}

From source file:net.ceos.project.poi.annotated.bean.BasicObjectBuilder.java

/**
 * Create a BasicObject for tests.//from w w w.  jav a  2  s.c o m
 * 
 * @return the {@link BasicObject}
 */
public static BasicObject buildBasicObject(int multiplier) {
    BasicObject toValidate = new BasicObject();

    toValidate.setDateAttribute(new Date());
    toValidate.setStringAttribute("some string");
    toValidate.setDoubleAttribute(Double.valueOf("25.3") * multiplier);
    toValidate.setLongAttribute(Long.valueOf("1234567890") * multiplier);
    toValidate.setBooleanPrimitiveAttribute(true);
    toValidate.setFloatPrimitiveAttribute(11.1125f * multiplier);
    toValidate.setUnitFamily(UnitFamily.COMPONENTS);
    toValidate.setBigDecimalAttribute(BigDecimal.valueOf(24.777).multiply(BigDecimal.valueOf(multiplier)));
    // TODO add new fields below

    return toValidate;
}

From source file:com.yahoo.parsec.clients.ParsecClientProfilingLogUtil.java

/**
 * log remote profiling log./* w w  w .j  a v a  2 s.  c o m*/
 *
 * @param request ning http request
 * @param response ning http response
 * @param requestStatus request status
 * @param progress parsec async progress do
 * @param msgMap additional log msg in key=String, value=String format
 */
public static void logRemoteRequest(final Request request, final Response response, final String requestStatus,
        final ParsecAsyncProgress progress, final Map<String, String> msgMap) {
    if (!PROF_LOGGER.isTraceEnabled()) {
        return;
    }

    //
    // prepare log data
    //
    long now = System.currentTimeMillis();
    BigDecimal timeInSecond = new BigDecimal(now).divide(BigDecimal.valueOf(DateUtils.MILLIS_PER_SECOND));
    String contentLength = "";
    String origin = "";
    int respCode = -1;

    String reqUrl = request.getUri().toUrl();
    String reqMethod = request.getMethod();
    String reqHostHeader = request.getHeaders().getFirstValue(ParsecClientDefine.HEADER_HOST);

    if (response != null) {
        contentLength = response.getHeader(ParsecClientDefine.HEADER_CONTENT_LENGTH);
        respCode = response.getStatusCode();
    }

    try {
        String executeInfo = OBJECT_MAPPER.writeValueAsString(progress);

        //
        // FIXME: should implement a servlet filter to set $_SERVER['REQUEST_URI']
        //
        String srcUrl = "";

        StringBuilder stringBuilder = new StringBuilder().append("time=").append(timeInSecond).append(", ")
                .append("req_url=").append(reqUrl).append(", ").append("req_host_header=").append(reqHostHeader)
                .append(", ").append("req_method=").append(reqMethod).append(", ").append("exec_info=")
                .append(executeInfo).append(", ").append("resp_code=").append(respCode).append(", ")
                .append("src_url=").append(srcUrl).append(", ").append("req_status=").append(requestStatus)
                .append(", ").append("content_length=").append(contentLength).append(", ").append("origin=")
                .append(origin).append(", ");

        if (msgMap != null) {
            for (Map.Entry<String, String> entry : msgMap.entrySet()) {
                stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append(", ");
            }
        }

        String logMsg = stringBuilder.toString();

        //logging
        PROF_LOGGER.trace(logMsg);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}

From source file:net.ceos.project.poi.annotated.bean.AutoResizeObjectBuilder.java

/**
 * Create a AutoResizeObject for tests./*from  w w  w  .  ja  v  a 2  s .  co m*/
 * 
 * @return the {@link AutoResizeObject}
 */
public static AutoResizeObject buildAutoResizeObject(int multiplier) {
    AutoResizeObject toValidate = new AutoResizeObject();

    toValidate.setDateAttribute(new Date());
    toValidate.setStringAttribute("some string");
    toValidate.setDoubleAttribute(Double.valueOf("25.3") * multiplier);
    toValidate.setLongAttribute(Long.valueOf("1234567890") * multiplier);
    toValidate.setBooleanPrimitiveAttribute(true);
    toValidate.setFloatPrimitiveAttribute(11.1125f * multiplier);
    toValidate.setUnitFamily(UnitFamily.COMPONENTS);
    toValidate.setBigDecimalAttribute(BigDecimal.valueOf(24.777).multiply(BigDecimal.valueOf(multiplier)));
    // TODO add new fields below

    return toValidate;
}

From source file:com.livhuwani.rambuda.policyquotationapp.services.Impl.ChildMaintenanceCrudServiceImpl.java

@Override
public ChildMaintenance createChildMaintenance() {
    ChildMaintenance newChildMaintenance = new ChildMaintenance();
    newChildMaintenance.setId(Long.MAX_VALUE + 1);
    newChildMaintenance.setAnnualIncreasePercentage(50);
    newChildMaintenance.setCashValue(BigDecimal.valueOf(2500));
    newChildMaintenance.setTerm(60);/*from ww w  .  java 2  s.  c  o  m*/

    ChildMaintenance savedChildMaintenance = childMaintenanceRepository.save(newChildMaintenance);
    return savedChildMaintenance;
}

From source file:com.livhuwani.rambuda.policyquotation_app.service.Impl.ChildMaintenanceCrudServiceImpl.java

@Override
public ChildMaintenance createChildMaintenance() {
    ChildMaintenance newChildMaintenance = new ChildMaintenance();
    newChildMaintenance.setId(Long.MAX_VALUE + 1);
    newChildMaintenance.setAnnualIncreasePercentage(50);
    newChildMaintenance.setCashValue(BigDecimal.valueOf(2500));
    newChildMaintenance.setTerm(60);/*from   w w w .j  a  v  a2  s  .  c om*/

    ChildMaintenance savedChildMaintenance = childMaintenanceRepository.saveAndFlush(newChildMaintenance);
    return savedChildMaintenance;
}

From source file:com.trenako.web.controllers.form.WishListForm.java

/**
 * Creates a new form for {@code WishList} creation.
 *
 * @param messageSource the message source
 * @return a new {@code WishListForm}./*from   w w w. j  a  va2s .  com*/
 */
public static WishListForm newForm(MessageSource messageSource) {
    return new WishListForm(new WishList(), BigDecimal.valueOf(0), initVisibilities(messageSource));
}

From source file:net.ceos.project.poi.annotated.bean.UniqueDecoratorObjectBuilder.java

/**
 * Create a UniqueDecoratorObject for tests.
 * //from   w ww . j  ava  2 s. co  m
 * @return the {@link UniqueDecoratorObject}
 */
public static UniqueDecoratorObject buildUniqueDecoratorObject(int multiplier) {
    UniqueDecoratorObject toValidate = new UniqueDecoratorObject();

    toValidate.setDateAttribute(new Date());
    toValidate.setStringAttribute("some string");
    toValidate.setIntegerAttribute(46 * multiplier);
    toValidate.setBooleanAttribute(Boolean.FALSE);
    toValidate.setDoublePrimitiveAttribute(44.6 * multiplier);
    toValidate.setLongPrimitiveAttribute(987654321L * multiplier);
    toValidate.setFloatAttribute(14.765f * multiplier);
    toValidate.setUnitFamily(UnitFamily.COMPONENTS);
    toValidate.setBigDecimalAttribute(BigDecimal.valueOf(24.777).multiply(BigDecimal.valueOf(multiplier)));

    return toValidate;
}