Example usage for java.math BigDecimal doubleValue

List of usage examples for java.math BigDecimal doubleValue

Introduction

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

Prototype

@Override
public double doubleValue() 

Source Link

Document

Converts this BigDecimal to a double .

Usage

From source file:ch.algotrader.dao.security.OptionDaoImpl.java

@Override
public List<Option> findByMinExpirationAndStrikeLimitWithTicks(int limit, long underlyingId,
        Date targetExpirationDate, BigDecimal underlyingSpot, OptionType optionType, Date date) {

    Validate.notNull(targetExpirationDate, "targetExpirationDate is null");
    Validate.notNull(underlyingSpot, "underlyingSpot is null");
    Validate.notNull(optionType, "optionType is null");
    Validate.notNull(date, "Date is null");

    return findCaching("Option.findByMinExpirationAndStrikeLimitWithTicks", limit, QueryType.BY_NAME,
            new NamedParam("underlyingId", underlyingId),
            new NamedParam("targetExpirationDate", targetExpirationDate),
            new NamedParam("underlyingSpot", underlyingSpot.doubleValue()),
            new NamedParam("optionType", optionType), new NamedParam("date", date));
}

From source file:org.openhie.openempi.dao.hibernate.PersonDaoHibernate.java

public double getFieldAverageLength(final String tableName, final String field) {
    if (field == null || field.length() == 0) {
        return 0.0;
    }/*from   w ww.  j a v a2s . co  m*/
    //ValidationUtil.sanityCheckFieldName(field);
    return (Double) getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            String fieldLowerCase = field.toLowerCase();
            StringBuilder sqlSelect = new StringBuilder("SELECT AVG(CHARACTER_LENGTH(");
            sqlSelect.append(COLUMN_NAME_PREFIX + fieldLowerCase);
            sqlSelect.append(")) FROM public." + getTableFullName(tableName));
            sqlSelect.append(" WHERE ");
            sqlSelect.append(COLUMN_NAME_PREFIX + fieldLowerCase);
            sqlSelect.append(" IS NOT NULL;");
            Object avgLenObj = session.createSQLQuery(sqlSelect.toString()).uniqueResult();
            if (avgLenObj == null)
                return 0.0;
            java.math.BigDecimal avgLen = (java.math.BigDecimal) avgLenObj;
            double avgLength = avgLen.doubleValue();
            log.trace("Found the following: " + avgLength);
            double presentRatio = getFieldMissingRatioInHibernate(session, tableName, fieldLowerCase, false);
            return avgLength * presentRatio; // Correct the ratio because of the NULL cells
        }
    });
}

From source file:ch.algotrader.service.TransactionServiceImpl.java

/**
 * {@inheritDoc}//from ww w  .j a va  2 s  .  c o  m
 */
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Override
public void createTransaction(final ExternalFill fill) {

    long startTime = System.nanoTime();
    LOGGER.debug("createTransaction start");

    Security security = fill.getSecurity();
    SecurityFamily securityFamily = security != null ? security.getSecurityFamily() : null;
    Currency currency = securityFamily != null ? securityFamily.getCurrency() : fill.getCurrency();
    Account account = fill.getAccount();
    TransactionType transactionType = Side.BUY.equals(fill.getSide()) ? TransactionType.BUY
            : TransactionType.SELL;
    long quantity = Side.BUY.equals(fill.getSide()) ? fill.getQuantity() : -fill.getQuantity();

    Transaction transaction = Transaction.Factory.newInstance();
    transaction.setUuid(UUID.randomUUID().toString());
    transaction.setDateTime(fill.getExtDateTime());
    transaction.setExtId(fill.getExtId());
    transaction.setIntOrderId(null);
    transaction.setExtOrderId(fill.getExtOrderId());
    transaction.setQuantity(quantity);
    transaction.setPrice(fill.getPrice());
    transaction.setType(transactionType);
    transaction.setSecurity(security);
    transaction.setStrategy(fill.getStrategy());
    transaction.setCurrency(currency);
    transaction.setAccount(account);

    String broker = account != null ? account.getBroker() : null;
    if (fill.getExecutionCommission() != null) {
        transaction.setExecutionCommission(fill.getExecutionCommission());
    } else if (securityFamily != null) {
        BigDecimal executionCommission = securityFamily.getExecutionCommission(broker);
        if (executionCommission != null) {
            transaction.setExecutionCommission(
                    RoundUtil.getBigDecimal(Math.abs(quantity * executionCommission.doubleValue())));
        }
    }

    if (fill.getClearingCommission() != null) {
        transaction.setClearingCommission(fill.getClearingCommission());
    } else if (securityFamily != null) {
        BigDecimal clearingCommission = securityFamily.getClearingCommission(broker);
        if (clearingCommission != null) {
            transaction.setClearingCommission(
                    RoundUtil.getBigDecimal(Math.abs(quantity * clearingCommission.doubleValue())));
        }
    }

    if (fill.getFee() != null) {
        transaction.setFee(fill.getFee());
    } else if (securityFamily != null) {
        final BigDecimal fee = securityFamily.getFee(broker);
        if (fee != null) {
            transaction.setFee(RoundUtil.getBigDecimal(Math.abs(quantity * fee.doubleValue())));
        }
    }

    processTransaction(transaction);

    LOGGER.debug("createTransaction end");
    MetricsUtil.accountEnd("CreateTransactionSubscriber", startTime);
}

From source file:fsm.series.Series_CC.java

@Override
public strictfp double getFunctionValue(double y, int m) {

    double um = getMu_m(m);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double km = um / a;

    BigDecimal Ym;

    BigDecimal cosh = new BigDecimal(-alphaM * -cosh(km * y));
    BigDecimal sinh = new BigDecimal(-sinh(km * y));
    BigDecimal sin = new BigDecimal(sin(km * y));
    BigDecimal cos = new BigDecimal(-alphaM * cos(km * y));

    Ym = (cos.add(sin).add(sinh).add(cosh));

    return Ym.doubleValue();
}

From source file:fsm.series.Series_CC.java

@Override
public double getFirstDerivativeValue(double y, int m) {
    //        dY = alphaM*(km*sin(km*y) + km*sinh(km*y)) + km*cos(km*y) - km*cosh(km*y)

    double um = getMu_m(m);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double km = um / a;

    BigDecimal dYm;

    BigDecimal cosh = new BigDecimal(-km * cosh(km * y));
    BigDecimal sinh = new BigDecimal(alphaM * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(alphaM * km * sin(km * y));
    BigDecimal cos = new BigDecimal(km * cos(km * y));

    dYm = (cos.add(sin).add(sinh).add(cosh));

    return dYm.doubleValue();

}

From source file:com.salesmanager.core.util.CheckoutUtil.java

/**
 * OrderProductAttribute is configured from javascript This code needs to
 * invoke catalog objects require getProductOptionValueId
 * //from   w  ww  .jav  a 2 s  .c o m
 * @param attributes
 * @param lineId
 * @param currency
 * @param request
 * @return
 * @throws Exception
 */
public static OrderProduct addAttributesFromRawObjects(List<OrderProductAttribute> attributes, OrderProduct scp,
        String currency, HttpServletRequest request) throws Exception {

    Locale loc = request.getLocale();
    String lang = loc.getLanguage();

    CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);

    BigDecimal sumPrice = null;

    Locale locale = (Locale) request.getSession().getAttribute("WW_TRANS_I18N_LOCALE");
    if (locale == null)
        locale = request.getLocale();

    // get attributes for this product
    Collection productAttributes = cservice.getProductAttributes(scp.getProductId(), locale.getLanguage());
    Map mapAttributes = new HashMap();
    if (productAttributes != null) {

        Iterator i = productAttributes.iterator();
        while (i.hasNext()) {
            ProductAttribute p = (ProductAttribute) i.next();
            mapAttributes.put(p.getOptionValueId(), p);
        }

    }

    if (scp != null) {

        StringBuffer attributesLine = null;

        if (attributes != null) {
            attributesLine = new StringBuffer();
            int count = 0;
            Iterator i = attributes.iterator();
            while (i.hasNext()) {
                OrderProductAttribute opa = (OrderProductAttribute) i.next();
                String attrPriceText = opa.getPrice();
                BigDecimal attrPrice = null;
                if (attrPriceText != null) {
                    attrPrice = CurrencyUtil.validateCurrency(attrPriceText, currency);
                } else {
                    attrPrice = opa.getOptionValuePrice();
                }
                // get all information from the attribute
                ProductAttribute pa = (ProductAttribute) mapAttributes.get(opa.getProductOptionValueId());
                if (pa != null) {
                    if (attrPrice == null) {
                        attrPrice = pa.getOptionValuePrice();
                    }
                }
                if (attrPrice != null) {
                    opa.setOptionValuePrice(attrPrice);
                    opa.setPrice(CurrencyUtil.displayFormatedAmountNoCurrency(attrPrice, currency));
                    if (sumPrice == null) {
                        sumPrice = new BigDecimal(attrPrice.doubleValue()).setScale(2);
                    } else {

                        BigDecimal currentPrice = sumPrice;
                        sumPrice = currentPrice.add(attrPrice);
                    }
                }
                // opa.setOrderId(Long.parseLong(orderId));
                opa.setOrderProductId(scp.getProductId());
                opa.setProductAttributeIsFree(pa.isProductAttributeIsFree());

                opa.setProductOption("");
                if (StringUtils.isBlank(opa.getProductOptionValue())) {
                    opa.setProductOptionValue("");
                }

                ProductOption po = pa.getProductOption();
                Set poDescriptions = po.getDescriptions();
                if (poDescriptions != null) {
                    Iterator pi = poDescriptions.iterator();
                    while (pi.hasNext()) {
                        ProductOptionDescription pod = (ProductOptionDescription) pi.next();
                        if (pod.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                            opa.setProductOption(pod.getProductOptionName());
                            break;
                        }
                    }
                }

                if (StringUtils.isBlank(opa.getProductOptionValue())) {
                    ProductOptionValue pov = pa.getProductOptionValue();
                    if (pov != null) {
                        Set povDescriptions = pov.getDescriptions();
                        if (povDescriptions != null) {
                            Iterator povi = povDescriptions.iterator();
                            while (povi.hasNext()) {
                                ProductOptionValueDescription povd = (ProductOptionValueDescription) povi
                                        .next();
                                if (povd.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                                    opa.setProductOptionValue(povd.getProductOptionValueName());
                                    break;
                                }
                            }
                        }
                    }
                }
                opa.setProductAttributeWeight(pa.getProductAttributeWeight());
                if (count == 0) {
                    attributesLine.append("[ ");
                }
                attributesLine.append(opa.getProductOption()).append(" -> ")
                        .append(opa.getProductOptionValue());
                if (count + 1 == attributes.size()) {
                    attributesLine.append("]");
                } else {
                    attributesLine.append(", ");
                }
                count++;
            }
        }

        // add attribute price to productprice
        if (sumPrice != null) {
            // sumPrice = sumPrice.multiply(new
            // BigDecimal(scp.getProductQuantity()));

            // get product price
            BigDecimal productPrice = scp.getProductPrice();
            productPrice = productPrice.add(sumPrice);

            // added
            scp.setProductPrice(productPrice);

            // BigDecimal finalPrice = scp.getFinalPrice();
            BigDecimal finalPrice = productPrice.multiply(new BigDecimal(scp.getProductQuantity()));
            // finalPrice = finalPrice.add(sumPrice);
            // BigDecimal cost = scp.get

            scp.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(productPrice, currency));
            scp.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency));
        }

        if (attributesLine != null) {
            scp.setAttributesLine(attributesLine.toString());
        }

        Set attributesSet = new HashSet(attributes);

        scp.setOrderattributes(attributesSet);

    }

    return scp;
}

From source file:fsm.series.Series_CC.java

@Override
public double getSecondDerivativeValue(double y, int m) {

    // d2Y =alphaM*(km^2*cos(km*y) + km^2*cosh(km*y)) - km^2*sin(km*y) - km^2*sinh(km*y)
    double um = getMu_m(m);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double km = um / a;

    BigDecimal d2Ym;

    BigDecimal cosh = new BigDecimal(km * km * alphaM * cosh(km * y));
    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(km * km * alphaM * cos(km * y));

    d2Ym = (cos.add(sin).add(sinh).add(cosh));

    return d2Ym.doubleValue();

}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.PolygonZone.java

public PolarCoordinate getCenterOfGravity() {
    BigDecimal x = new BigDecimal(0), y = new BigDecimal(0);
    BigDecimal doubleArea = new BigDecimal(0);

    for (int k = 0, l = vertices.length - 1; k < l; ++k) {
        BigDecimal ax = new BigDecimal(vertices[k].x);
        BigDecimal ay = new BigDecimal(vertices[k].y);
        BigDecimal bx = new BigDecimal(vertices[k + 1].x);
        BigDecimal by = new BigDecimal(vertices[k + 1].y);
        BigDecimal t = ax.multiply(by).subtract(bx.multiply(ay));
        x = x.add(ax.add(bx).multiply(t));
        y = y.add(ay.add(by).multiply(t));
        doubleArea = doubleArea.add(ax.multiply(by).subtract(bx.multiply(ay)));
    }/*from  w w  w  . j a  v  a2 s .  co  m*/

    double sixTimesArea = 3.0 * doubleArea.doubleValue();
    return new PolarCoordinate(x.doubleValue() / sixTimesArea, y.doubleValue() / sixTimesArea, 0);
}

From source file:uk.co.onehp.trickle.services.betfair.BetfairServiceImpl.java

private PlaceBets createMOCExchangeBet(Bet bet, BigDecimal liability, BigDecimal price) {
    bet.addLog(new BetLog(new LocalDateTime(), liability, price, BetType.MOC_EXCHANGE));
    this.domainService.updateBet(bet);
    PlaceBets placeBets = new PlaceBets();
    placeBets.setBetType(bet.getStrategy().getAspect() == BettingAspect.BACK ? BetTypeEnum.B : BetTypeEnum.L);
    placeBets.setBetCategoryType(BetCategoryTypeEnum.E);
    placeBets.setBetPersistenceType(BetPersistenceTypeEnum.SP);
    placeBets.setMarketId(bet.getHorse().getRaceId());
    placeBets.setSelectionId(bet.getHorse().getRunnerId());
    placeBets.setSize(bet.getStrategy().getAspect() == BettingAspect.BACK ? liability.doubleValue()
            : BettingUtil.libilityToStake(liability, price).doubleValue());
    placeBets.setPrice(price.doubleValue());
    //Workaround for known bug in betfair
    placeBets.setBspLiability(0.0);//  www. ja v a  2s . c  o m
    return placeBets;
}

From source file:com.facebook.InsightsLogger.java

/**
 * Logs a purchase event with Facebook, in the specified amount and with the specified currency.  Additional
 * detail about the purchase can be passed in through the parameters bundle.
 *
 * @param purchaseAmount  Amount of purchase, in the currency specified by the 'currency' parameter. This value
 *                        will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346).
 * @param currency        Currency used to specify the amount.
 * @param parameters      Arbitrary additional information for describing this event.  Should have no more than
 *                        10 entries, and keys should be mostly consistent from one purchase event to the next.
 *//* w  w w .jav  a  2s .com*/
public void logPurchase(BigDecimal purchaseAmount, Currency currency, Bundle parameters) {

    if (purchaseAmount == null) {
        notifyDeveloperError("purchaseAmount cannot be null");
        return;
    } else if (currency == null) {
        notifyDeveloperError("currency cannot be null");
        return;
    }

    if (parameters == null) {
        parameters = new Bundle();
    }
    parameters.putString(EVENT_PARAMETER_CURRENCY, currency.getCurrencyCode());

    logEventNow(EVENT_NAME_LOG_MOBILE_PURCHASE, purchaseAmount.doubleValue(), parameters);
}