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:net.sourceforge.fenixedu.domain.vigilancy.VigilantWrapper.java

public double getPoints() {
    double points = this.getStartPoints().doubleValue();
    BigDecimal weight = this.getPointsWeight();

    Collection<Vigilancy> vigilancies = getVigilanciesSet();

    for (Vigilancy vigilancy : vigilancies) {
        points += weight.doubleValue() * vigilancy.getPoints();
    }//from  w w w.j a  v a 2  s  .  co m

    return points;
}

From source file:co.com.soinsoftware.altablero.request.AbstractRequestHandler.java

protected BigDecimal getMaxEvaluation(final UserBO user) {
    final Set<SchoolBO> schoolSet = (user != null) ? user.getSchoolSet() : null;
    BigDecimal maxEvaluation = null;
    if (schoolSet != null) {
        for (final SchoolBO school : schoolSet) {
            for (final NoteValueConfigurationBO noteValue : school.getNote().getNoteValueSet()) {
                if (maxEvaluation == null
                        || maxEvaluation.doubleValue() < noteValue.getRangeEnd().doubleValue()) {
                    maxEvaluation = noteValue.getRangeEnd();
                }/*from  w  ww  .  j  a  v  a2 s  .  co  m*/
            }
        }
    }
    return maxEvaluation;
}

From source file:fsm.series.Series_CF.java

@Override
public 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:com.epam.cme.facades.converters.populator.DeviceBundleTabsPopulator.java

/**
 * Hook to call additional populators for different purposes. For Devices we are populating the
 * standard price of the according plan. Afterwards we are finding possible price rules for the
 * device product as well as for the plan product and storing the cheapest ones in the plan DTO
 * as <code>otherBundleProductPrice</code> for the cheapest device price and as
 * <code>thisBundleProductPrice</code> for the cheapest plan price.
 * //  w w w .  j a va2s . c  o m
 * @param sourceComponent
 *            in this case e.g. the "Smartphone-Handset" component
 * @param targetComponent
 *            in this case e.g. the "Smartphone-Plan" component
 * @param productModel
 *            in this case the Model of the device product
 * @param productData
 *            in this case the DTO of the device product
 * @param subscriptionProductModel
 *            in this case the Model of the plan product
 * @param subscriptionProductData
 *            in this case the DTO of the plan product
 */
@Override
protected void callPopulators(final SOURCETEMPLATE sourceComponent, final SOURCETEMPLATE targetComponent,
        final SOURCEPRODUCT productModel, final TARGETPRODUCT productData,
        final SubscriptionProductModel subscriptionProductModel, final ProductData subscriptionProductData) {
    getProductPricePopulator().populate(subscriptionProductModel, subscriptionProductData);
    getSubscriptionProductPricePopulator().populate(subscriptionProductModel, subscriptionProductData);
    getProductDescriptionPopulator().populate(subscriptionProductModel, subscriptionProductData);
    getProductClassificationPopulator().populate(subscriptionProductModel, subscriptionProductData);

    final CurrencyModel currency = getCommonI18NService().getCurrentCurrency();

    final ChangeProductPriceBundleRuleModel devicePriceRule = getBundleRuleService()
            .getChangePriceBundleRule(sourceComponent, productModel, subscriptionProductModel, currency);
    subscriptionProductData.setOtherBundleProductPrice(devicePriceRule == null ? productData.getPrice()
            : getPriceDataFactory().create(PriceDataType.BUY, devicePriceRule.getPrice(),
                    currency.getIsocode()));

    final ChangeProductPriceBundleRuleModel planPriceRule = getBundleRuleService()
            .getChangePriceBundleRule(targetComponent, subscriptionProductModel, productModel, currency);
    final BigDecimal planPriceRulePrice = planPriceRule == null ? null : planPriceRule.getPrice();

    final SubscriptionPricePlanData pricePlan = (SubscriptionPricePlanData) subscriptionProductData.getPrice();
    BigDecimal pricePlanLowestPrice = BigDecimal.ZERO;
    BigDecimal discountPrice = BigDecimal.ZERO;

    if (pricePlan != null && CollectionUtils.isNotEmpty(pricePlan.getRecurringChargeEntries())) {
        final RecurringChargeEntryData lowestPriceChargeEntry = pricePlan.getRecurringChargeEntries().iterator()
                .next();
        pricePlanLowestPrice = lowestPriceChargeEntry.getPrice().getValue();
    }

    if (planPriceRulePrice == null || pricePlanLowestPrice.doubleValue() < planPriceRulePrice.doubleValue()) {
        discountPrice = pricePlanLowestPrice;
    } else {
        discountPrice = BigDecimal.valueOf(planPriceRulePrice.doubleValue());
    }

    subscriptionProductData.setThisBundleProductPrice(
            getPriceDataFactory().create(PriceDataType.BUY, discountPrice, currency.getIsocode()));
}

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

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

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

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

From source file:org.codhaus.groovy.grails.validation.ScaleConstraint.java

/**
 * {@inheritDoc}//from  ww  w . ja  v a 2s  . co m
 *
 *     Object, Object, org.springframework.validation.Errors)
 */
@Override
protected void processValidate(Object target, Object propertyValue, Errors errors) {
    BigDecimal bigDecimal;

    BeanWrapper bean = new BeanWrapperImpl(target);

    if (propertyValue instanceof Float) {
        bigDecimal = new BigDecimal(propertyValue.toString());
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal.floatValue());
    } else if (propertyValue instanceof Double) {
        bigDecimal = new BigDecimal(propertyValue.toString());
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal.doubleValue());
    } else if (propertyValue instanceof BigDecimal) {
        bigDecimal = (BigDecimal) propertyValue;
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal);
    } else {
        throw new IllegalArgumentException("Unsupported type detected in constraint [" + getName()
                + "] of property [" + constraintPropertyName + "] of class [" + constraintOwningClass + "]");
    }
}

From source file:burstcoin.jminer.JMinerCommandLine.java

private void initApplicationListeners() {
    context.addApplicationListener(new ApplicationListener<RoundFinishedEvent>() {
        @Override/*from ww w  . j  av a  2  s .co  m*/
        public void onApplicationEvent(RoundFinishedEvent event) {
            previousRemainingCapacity = 0;
            previousElapsedTime = 0;

            long s = event.getRoundTime() / 1000;
            long ms = event.getRoundTime() % 1000;

            String bestDeadline = Long.MAX_VALUE == event.getBestCommittedDeadline() ? "N/A"
                    : String.valueOf(event.getBestCommittedDeadline());
            LOG.info("FINISH block '" + event.getBlockNumber() + "', " + "best deadline '" + bestDeadline
                    + "', " + "round time '" + s + "s " + ms + "ms'");
        }
    });

    context.addApplicationListener(new ApplicationListener<RoundStoppedEvent>() {
        @Override
        public void onApplicationEvent(RoundStoppedEvent event) {
            previousRemainingCapacity = 0;
            previousElapsedTime = 0;

            long s = event.getElapsedTime() / 1000;
            long ms = event.getElapsedTime() % 1000;

            BigDecimal totalCapacity = new BigDecimal(event.getCapacity());
            BigDecimal factor = BigDecimal.ONE.divide(totalCapacity, MathContext.DECIMAL32);
            BigDecimal progress = factor
                    .multiply(new BigDecimal(event.getCapacity() - event.getRemainingCapacity()));
            int percentage = (int) Math.ceil(progress.doubleValue() * 100);
            percentage = percentage > 100 ? 100 : percentage;

            String bestDeadline = Long.MAX_VALUE == event.getBestCommittedDeadline() ? "N/A"
                    : String.valueOf(event.getBestCommittedDeadline());
            LOG.info("STOP block '" + event.getBlockNumber() + "', " + String.valueOf(percentage) + "% done, "
                    + "best deadline '" + bestDeadline + "', " + "elapsed time '" + s + "s " + ms + "ms'");
        }
    });

    context.addApplicationListener(new ApplicationListener<NetworkLastWinnerEvent>() {
        @Override
        public void onApplicationEvent(NetworkLastWinnerEvent event) {
            if (blockNumber - 1 == event.getLastBlockNumber()) {
                LOG.info(
                        "      winner block '" + event.getLastBlockNumber() + "', '" + event.getWinner() + "'");
            } else {
                LOG.error("Error: NetworkLastWinnerEvent for block: " + event.getLastBlockNumber()
                        + " is outdated!");
            }
        }
    });

    context.addApplicationListener(new ApplicationListener<NetworkStateChangeEvent>() {
        @Override
        public void onApplicationEvent(NetworkStateChangeEvent event) {
            blockNumber = event.getBlockNumber();
        }
    });

    context.addApplicationListener(new ApplicationListener<RoundStartedEvent>() {
        @Override
        public void onApplicationEvent(RoundStartedEvent event) {
            progressLogStep = NUMBER_OF_PROGRESS_LOGS_PER_ROUND;

            LOG.info("-------------------------------------------------------");
            LOG.info("START block '" + event.getBlockNumber() + "', " + "scoopNumber '" + event.getScoopNumber()
                    + "', " + "capacity '" + event.getCapacity() / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR
                    + " " + G_UNIT + "'");
            String target = event.getTargetDeadline() == Long.MAX_VALUE ? "N/A"
                    : String.valueOf(event.getTargetDeadline());
            LOG.info("      targetDeadline '" + target + "', " + "baseTarget '"
                    + String.valueOf(event.getBaseTarget()) + "'");
        }
    });

    context.addApplicationListener(new ApplicationListener<ReaderProgressChangedEvent>() {
        @Override
        public void onApplicationEvent(ReaderProgressChangedEvent event) {
            long logStepCapacity = event.getCapacity() / NUMBER_OF_PROGRESS_LOGS_PER_ROUND;

            if (event.getRemainingCapacity() < logStepCapacity * progressLogStep
                    || event.getRemainingCapacity() == 0) {
                progressLogStep--;

                // trigger garbage collection on every progress step
                System.gc();

                BigDecimal totalCapacity = new BigDecimal(event.getCapacity());
                BigDecimal factor = BigDecimal.ONE.divide(totalCapacity, MathContext.DECIMAL32);
                BigDecimal progress = factor
                        .multiply(new BigDecimal(event.getCapacity() - event.getRemainingCapacity()));
                int percentage = (int) Math.ceil(progress.doubleValue() * 100);
                percentage = percentage > 100 ? 100 : percentage;

                // calculate capacity
                long effMBPerSec = 0;
                if (previousRemainingCapacity > 0) {
                    long effDoneBytes = previousRemainingCapacity - event.getRemainingCapacity();

                    // calculate current reading speed (since last info)
                    long effBytesPerMs = (effDoneBytes / 4096) / (event.getElapsedTime() - previousElapsedTime);
                    effMBPerSec = (effBytesPerMs * 1000) / SIZE_DIVISOR / SIZE_DIVISOR;
                }

                // calculate capacity
                long doneBytes = event.getCapacity() - event.getRemainingCapacity();
                long doneTB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR;
                long doneGB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR % SIZE_DIVISOR;

                // calculate reading speed (average)
                long averageBytesPerMs = (doneBytes / 4096) / event.getElapsedTime();
                long averageMBPerSec = (averageBytesPerMs * 1000) / SIZE_DIVISOR / SIZE_DIVISOR;

                previousRemainingCapacity = event.getRemainingCapacity();
                previousElapsedTime = event.getElapsedTime();

                LOG.info(String.valueOf(percentage) + "% done (" + doneTB + T_UNIT + " " + doneGB + G_UNIT
                        + "), avg.'" + averageMBPerSec + " " + M_UNIT + "/s'"
                        + (effMBPerSec > 0 ? ", eff.'" + effMBPerSec + " " + M_UNIT + "/s'" : ""));
            }
        }
    });

    context.addApplicationListener(new ApplicationListener<RoundSingleResultEvent>() {
        @Override
        public void onApplicationEvent(RoundSingleResultEvent event) {
            LOG.info("dl '" + event.getCalculatedDeadline() + "' send ("
                    + (event.isPoolMining() ? "pool" : "solo") + ")");
        }
    });

    context.addApplicationListener(new ApplicationListener<RoundSingleResultSkippedEvent>() {
        @Override
        public void onApplicationEvent(RoundSingleResultSkippedEvent event) {
            LOG.info(
                    "dl '" + event.getCalculatedDeadline() + "' > '" + event.getTargetDeadline() + "' skipped");
        }
    });

    context.addApplicationListener(new ApplicationListener<NetworkResultConfirmedEvent>() {
        @Override
        public void onApplicationEvent(NetworkResultConfirmedEvent event) {
            LOG.info("dl '" + event.getDeadline() + "' confirmed!  [ " + getDeadlineTime(event.getDeadline())
                    + " ]");
        }
    });

    context.addApplicationListener(new ApplicationListener<NetworkDevResultConfirmedEvent>() {
        @Override
        public void onApplicationEvent(NetworkDevResultConfirmedEvent event) {
            LOG.info("devPool response '" + event.getResponse() + "', block '" + event.getBlockNumber() + "'");
            for (DevPoolResult devPoolResult : event.getDevPoolResults()) {
                LOG.info("dl '" + devPoolResult.getCalculatedDeadline() + "' successful committed!  [ "
                        + getDeadlineTime(devPoolResult.getCalculatedDeadline()) + " ]");
            }
        }
    });

    context.addApplicationListener(new ApplicationListener<NetworkResultErrorEvent>() {
        @Override
        public void onApplicationEvent(NetworkResultErrorEvent event) {
            LOG.info("strange dl result '" + event.getStrangeDeadline() + "', calculated '"
                    + event.getCalculatedDeadline() + "' " + "block '" + event.getBlockNumber() + "' nonce '"
                    + event.getNonce() + "'");
        }
    });

    context.addApplicationListener(new ApplicationListener<ReaderCorruptFileEvent>() {
        @Override
        public void onApplicationEvent(ReaderCorruptFileEvent event) {
            LOG.info("strange dl source '" + event.getFilePath() + "' (try replotting!?)");
            LOG.info("strange dl file chunks '" + event.getNumberOfChunks() + "', " + "parts per chunk '"
                    + event.getNumberOfParts() + "', " + "block '" + event.getBlockNumber() + "'");
        }
    });

    context.addApplicationListener(new ApplicationListener<ReaderDriveFinishEvent>() {
        @Override
        public void onApplicationEvent(ReaderDriveFinishEvent event) {
            if (blockNumber == event.getBlockNumber()) {
                // calculate capacity
                long doneBytes = event.getSize();
                long doneTB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR;
                long doneGB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR % SIZE_DIVISOR;

                long s = event.getTime() / 1000;
                long ms = event.getTime() % 1000;

                LOG.info("read '" + event.getDirectory() + "' (" + doneTB + T_UNIT + " " + doneGB + G_UNIT
                        + ") in '" + s + "s " + ms + "ms'");
            }
        }
    });

    context.addApplicationListener(new ApplicationListener<ReaderDriveInterruptedEvent>() {
        @Override
        public void onApplicationEvent(ReaderDriveInterruptedEvent event) {
            LOG.info("stopped '" + event.getDirectory() + "' for block '" + event.getBlockNumber() + "'.");
        }
    });

    context.addApplicationListener(new ApplicationListener<NetworkPoolInfoEvent>() {
        @Override
        public void onApplicationEvent(NetworkPoolInfoEvent event) {
            String value = event.getPoolBalanceNQT();
            String amount = value.length() > 8 ? value.substring(0, value.length() - 8) : value;
            value = event.getPoolForgedBalanceNQT();
            String totalForget = value.length() > 8 ? value.substring(0, value.length() - 8) : value;
            LOG.info("-------------------------------------------------------");
            LOG.info("POOL account '" + event.getPoolAccountRS() + "', assigned miners '"
                    + event.getPoolNumberOfMiningAccounts() + "'");
            LOG.info("     balance '" + amount + " BURST', total mined '" + totalForget + " BURST'");
        }
    });
}

From source file:net.sourceforge.fenixedu.domain.vigilancy.VigilantWrapper.java

public double getEstimatedPoints() {
    double totalPoints = getStartPoints().doubleValue();
    BigDecimal weight = getPointsWeight();

    for (Vigilancy vigilancy : getActiveVigilancies()) {
        int points = vigilancy.hasPointsAttributed() ? vigilancy.getPoints() : vigilancy.getEstimatedPoints();
        totalPoints += points * weight.doubleValue();
    }//from   w  w  w  .  j a  v a2s  .  c  o m

    return totalPoints;
}

From source file:de.hybris.platform.b2bacceleratorservices.jalo.promotions.ProductPriceDiscountPromotionByPaymentType.java

@Override
public List<PromotionResult> evaluate(final SessionContext ctx, final PromotionEvaluationContext promoContext) {
    final List<PromotionResult> promotionResults = new ArrayList<PromotionResult>();
    // Find all valid products in the cart
    final PromotionsManager.RestrictionSetResult restrictionResult = this.findEligibleProductsInBasket(ctx,
            promoContext);//from   w  w w . j  a v a 2 s.c  om

    if (restrictionResult.isAllowedToContinue() && !restrictionResult.getAllowedProducts().isEmpty()) {
        final PromotionOrderView view = promoContext.createView(ctx, this,
                restrictionResult.getAllowedProducts());
        final AbstractOrder order = promoContext.getOrder();

        for (final PromotionOrderEntry entry : view.getAllEntries(ctx)) {
            // Get the next order entry
            final long quantityToDiscount = entry.getQuantity(ctx);
            if (quantityToDiscount > 0) {
                final long quantityOfOrderEntry = entry.getBaseOrderEntry().getQuantity(ctx).longValue();

                // The adjustment to the order entry
                final double originalUnitPrice = entry.getBasePrice(ctx).doubleValue();
                final double originalEntryPrice = quantityToDiscount * originalUnitPrice;

                final Currency currency = promoContext.getOrder().getCurrency(ctx);
                Double discountPriceValue;

                final EnumerationValue paymentType = B2BAcceleratorServicesManager.getInstance()
                        .getPaymentType(ctx, order);

                if (paymentType != null
                        && StringUtils.equalsIgnoreCase(paymentType.getCode(), getPaymentType().getCode())) {
                    promoContext.startLoggingConsumed(this);
                    discountPriceValue = this.getPriceForOrder(ctx, this.getProductDiscountPrice(ctx),
                            promoContext.getOrder(),
                            ProductPriceDiscountPromotionByPaymentType.PRODUCTDISCOUNTPRICE);

                    final BigDecimal adjustedEntryPrice = Helper.roundCurrencyValue(ctx, currency,
                            originalEntryPrice - (quantityToDiscount * discountPriceValue.doubleValue()));
                    // Calculate the unit price and round it
                    final BigDecimal adjustedUnitPrice = Helper.roundCurrencyValue(ctx, currency,
                            adjustedEntryPrice.equals(BigDecimal.ZERO) ? BigDecimal.ZERO
                                    : adjustedEntryPrice.divide(BigDecimal.valueOf(quantityToDiscount),
                                            RoundingMode.HALF_EVEN));

                    for (final PromotionOrderEntryConsumed poec : view.consume(ctx, quantityToDiscount)) {
                        poec.setAdjustedUnitPrice(ctx, adjustedUnitPrice.doubleValue());
                    }

                    final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx,
                            this, promoContext.getOrder(), 1.0F);
                    result.setConsumedEntries(ctx, promoContext.finishLoggingAndGetConsumed(this, true));
                    final BigDecimal adjustment = Helper.roundCurrencyValue(ctx, currency,
                            adjustedEntryPrice.subtract(BigDecimal.valueOf(originalEntryPrice)));
                    final PromotionOrderEntryAdjustAction poeac = PromotionsManager.getInstance()
                            .createPromotionOrderEntryAdjustAction(ctx, entry.getBaseOrderEntry(),
                                    quantityOfOrderEntry, adjustment.doubleValue());
                    result.addAction(ctx, poeac);
                    promotionResults.add(result);
                }
            }
        }
        final long remainingCount = view.getTotalQuantity(ctx);
        if (remainingCount > 0) {
            promoContext.startLoggingConsumed(this);
            view.consume(ctx, remainingCount);
            final PromotionResult result = PromotionsManager.getInstance().createPromotionResult(ctx, this,
                    promoContext.getOrder(), 0.5F);
            result.setConsumedEntries(ctx, promoContext.finishLoggingAndGetConsumed(this, false));
            promotionResults.add(result);
        }
    }
    return promotionResults;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java

private BigDecimal getDifference(BigDecimal lessonHours, BigDecimal summaryHours) {
    Double difference;// www  .  j a  v  a 2  s . c  o m
    difference = (1 - ((lessonHours.doubleValue() - summaryHours.doubleValue()) / lessonHours.doubleValue()))
            * 100;
    if (difference.isNaN() || difference.isInfinite()) {
        difference = 0.0;
    }
    return BigDecimal.valueOf(difference).setScale(2, RoundingMode.HALF_UP);
}