Example usage for java.lang Double doubleValue

List of usage examples for java.lang Double doubleValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public double doubleValue() 

Source Link

Document

Returns the double value of this Double object.

Usage

From source file:org.boris.xlloop.util.XLoperObjectConverter.java

/**
 * Convert an array into the desired object.
 * /*from w  w  w  .  j a va 2 s.  c o  m*/
 * @param arr.
 * @param hint.
 * 
 * @return Object.
 */
private Object convertArray(XLArray arr, Class hint, SessionContext sessionContext) {
    Object val = null;
    if (arr.columns == 1) {
        return convertVector(arr, hint, sessionContext);
    }

    if (Integer.class.equals(hint) || int.class.equals(hint)) {
        val = arr.getInteger(0);
    } else if (Double.class.equals(hint) || double.class.equals(hint)) {
        val = arr.getDouble(0);
    } else if (String.class.equals(hint)) {
        val = arr.getString(0);
    } else if (double[].class.equals(hint)) {
        double[] darr = new double[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            Double d = arr.getDouble(i);
            if (d != null)
                darr[i] = d.doubleValue();
        }

        val = darr;
    } else if (double[][].class.equals(hint)) {
        double[][] darr = new double[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                Double d = arr.getDouble(i, j);
                if (d != null)
                    darr[i][j] = d.doubleValue();
            }
        }

        val = darr;
    } else if (Double[].class.equals(hint)) {
        Double[] darr = new Double[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = arr.getDouble(i);
        }

        val = darr;
    } else if (Double[][].class.equals(hint)) {
        Double[][] darr = new Double[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                darr[i][j] = arr.getDouble(i, j);
            }
        }

        val = darr;
    } else if (int[].class.equals(hint)) {
        int[] darr = new int[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            Integer it = arr.getInteger(i);
            if (it != null)
                darr[i] = it.intValue();
        }

        val = darr;
    } else if (int[][].class.equals(hint)) {
        int[][] darr = new int[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                Integer it = arr.getInteger(i, j);
                if (it != null)
                    darr[i][j] = it.intValue();
            }
        }

        val = darr;
    } else if (Integer[].class.equals(hint)) {
        Integer[] darr = new Integer[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = arr.getInteger(i);
        }

        val = darr;
    } else if (Integer[][].class.equals(hint)) {
        Integer[][] darr = new Integer[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                darr[i][j] = arr.getInteger(i, j);
            }
        }

        val = darr;
    } else if (boolean[].class.equals(hint)) {
        boolean[] darr = new boolean[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            Boolean b = arr.getBoolean(i);
            if (b != null)
                darr[i] = b.booleanValue();
        }

        val = darr;
    } else if (boolean[][].class.equals(hint)) {
        boolean[][] darr = new boolean[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                Boolean b = arr.getBoolean(i, j);
                if (b != null)
                    darr[i][j] = b.booleanValue();
            }
        }

        val = darr;
    } else if (Boolean[].class.equals(hint)) {
        Boolean[] darr = new Boolean[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = arr.getBoolean(i);
        }

        val = darr;
    } else if (Boolean[][].class.equals(hint)) {
        Boolean[][] darr = new Boolean[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                darr[i][j] = arr.getBoolean(i, j);
            }
        }

        val = darr;
    } else if (String[].class.equals(hint)) {
        String[] darr = new String[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = arr.getString(i);
        }

        val = darr;
    } else if (String[][].class.equals(hint)) {
        String[][] darr = new String[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                darr[i][j] = arr.getString(i, j);
            }
        }

        val = darr;
    } else if (Object[].class.equals(hint)) {
        Object[] darr = new Object[arr.rows * arr.columns];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = createFrom(arr.get(i), Object.class, sessionContext);
        }

        val = darr;
    } else if (Object[][].class.equals(hint)) {
        Object[][] darr = new Object[arr.rows][arr.columns];

        for (int i = 0; i < arr.rows; i++) {
            for (int j = 0; j < arr.columns; j++) {
                darr[i][j] = createFrom(arr.get(i, j), Object.class, sessionContext);
            }
        }

        val = darr;
    } else if (XLArray.class.equals(hint)) {
        val = arr;
    } else {
        String str = arr.getString(0);
        val = registry.get(str, sessionContext);
        if (val == null)
            val = str;
    }

    return val;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java

public void setLabelRotationDeg(final Double value) {
    if (value == null) {
        labelRotation = null;/*from w  w w .  j a va2  s.  c  om*/
    } else {
        labelRotation = new Double(StrictMath.toRadians(value.doubleValue()));
    }
}

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);// w ww  . j  a  va2s  .  com

    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:org.apache.ctakes.ytex.kernel.metric.ConceptSimilarityServiceImpl.java

public Object[] getBestLCS(Set<String> lcses, Map<String, Double> icMap) {
    double ic = -1;
    String bestLCS = null;//from   www.  j  a va  2 s .  c  o  m
    for (String lcs : lcses) {
        Double ictmp = icMap.get(lcs);
        if (ictmp != null && ic < ictmp.doubleValue()) {
            ic = ictmp;
            bestLCS = lcs;
        }
    }
    if (ic < 0)
        ic = 0d;
    return new Object[] { bestLCS, ic };
}

From source file:org.richfaces.tests.metamer.ftest.AbstractWebDriverTest.java

public static <T extends Number & Comparable<T>> Number countMedian(List<T> values) {
    assertTrue(values.size() > 0);//from   w w  w.  j a  v  a  2  s.  c  o m
    if (values.size() == 1) {
        return values.get(0);
    }

    final List<T> copy = Lists.newArrayList(values);
    Collections.sort(copy);

    int middleIndex = (copy.size() - 1) / 2;

    double result = copy.get(middleIndex).doubleValue();
    if (copy.size() % 2 == 0) {
        result = (result + copy.get(middleIndex + 1).doubleValue()) / 2.0;
    }
    final Double median = Double.valueOf(result);
    return new Number() {
        private static final long serialVersionUID = 1L;

        @Override
        public int intValue() {
            return median.intValue();
        }

        @Override
        public long longValue() {
            return median.longValue();
        }

        @Override
        public float floatValue() {
            return median.floatValue();

        }

        @Override
        public double doubleValue() {
            return median.doubleValue();

        }

        @Override
        public String toString() {
            return median.doubleValue() + " from values(sorted) " + copy.toString() + '.';
        }
    };
}

From source file:org.squale.squalecommon.daolayer.result.MarkDAOImpl.java

/**
 * Retrouve les notes qui ont pour type pTreClass, pour id d'audit pauditId et pour valeur pValue
 * // w  ww  . ja  v  a  2s  . c  o m
 * @param pSession session Hibernate
 * @param pAuditId identifiant de l'audit
 * @param pProjectId id du projet
 * @param pTreId classe du TRE
 * @param pValueMin valeur min de l'intervalle
 * @param pValueMax valeur max de l'intervalle
 * @param pMax Nombre maximum de composants retourn
 * @return les notes associes
 * @throws JrafDaoException exception DAO
 */
public Collection findWhereInterval(ISession pSession, Long pAuditId, Long pProjectId, Long pTreId,
        Double pValueMin, Double pValueMax, Integer pMax) throws JrafDaoException {
    String whereClause = "where ";
    whereClause += getAlias() + ".practice.rule.id = " + pTreId;
    whereClause += " and ";
    whereClause += getAlias() + ".practice.audit.id = '" + pAuditId + "'";
    whereClause += " and ";
    whereClause += getAlias() + ".practice.project.id = " + pProjectId;
    whereClause += " and ";
    whereClause += whereValueClause(pValueMin.doubleValue(), pValueMax.doubleValue());
    Collection ret = (Collection) findWhereScrollable(pSession, whereClause, pMax.intValue(), 0, false);
    return ret;
}

From source file:com.aurel.track.fieldType.runtime.matchers.run.DoubleMatcherRT.java

/**
 * Whether the value matches or not//from w w  w.  ja va 2  s.co m
 * 
 * @param attributeValue
 * @return
 */
@Override
public boolean match(Object attributeValue) {
    Boolean nullMatch = nullMatcher(attributeValue);
    if (nullMatch != null) {
        return nullMatch.booleanValue();
    }
    if (attributeValue == null || matchValue == null) {
        return false;
    }
    Double attributeValueDouble = null;
    Double matcherValueDouble = null;
    try {
        attributeValueDouble = (Double) attributeValue;
    } catch (Exception e) {
        LOGGER.error("Converting the attribute value " + attributeValue + " of type "
                + attributeValue.getClass().getName() + " to Double failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return false;
    }
    try {
        matcherValueDouble = (Double) matchValue;
    } catch (Exception e) {
        LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName()
                + " to Double failed with " + e.getMessage(), e);
        return false;
    }

    switch (relation) {
    case MatchRelations.EQUAL:
        return (Double.doubleToRawLongBits(attributeValueDouble.doubleValue())
                - Double.doubleToRawLongBits(matcherValueDouble.doubleValue()) == 0);
    case MatchRelations.NOT_EQUAL:
        return (Double.doubleToRawLongBits(attributeValueDouble.doubleValue())
                - Double.doubleToRawLongBits(matcherValueDouble.doubleValue()) != 0);
    case MatchRelations.GREATHER_THAN:
        return attributeValueDouble.doubleValue() > matcherValueDouble.doubleValue();
    case MatchRelations.GREATHER_THAN_EQUAL:
        return attributeValueDouble.doubleValue() >= matcherValueDouble.doubleValue();
    case MatchRelations.LESS_THAN:
        return attributeValueDouble.doubleValue() < matcherValueDouble.doubleValue();
    case MatchRelations.LESS_THAN_EQUAL:
        return attributeValueDouble.doubleValue() <= matcherValueDouble.doubleValue();
    default:
        return false;
    }
}

From source file:com.epam.cme.facades.bundle.impl.DefaultGuidedSellingFacade.java

protected Double getMinPriceOfRuleAndPlan(final SubscriptionPricePlanModel pricePlan,
        final ChangeProductPriceBundleRuleModel priceRule) {
    Double rulePrice = null;
    Double planPrice = null;/*w  ww .  j a  va2  s  .c  om*/

    if (pricePlan != null) {
        final RecurringChargeEntryModel chargeEntry = getCommercePriceService()
                .getFirstRecurringPriceFromPlan(pricePlan);
        planPrice = chargeEntry.getPrice();
    }

    if (priceRule != null) {
        rulePrice = Double.valueOf(priceRule.getPrice().doubleValue());
    }

    if (rulePrice == null && planPrice != null) {
        return planPrice;
    } else if (rulePrice != null && planPrice == null) {
        return rulePrice;
    } else if (rulePrice != null && planPrice != null) {
        return (Double.compare(rulePrice.doubleValue(), planPrice.doubleValue()) == -1) ? rulePrice : planPrice;
    }

    return null;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java

public void setCategoricalItemLabelRotationDeg(final Double value) {
    if (value == null) {
        categoricalItemLabelRotation = null;
    } else {/*from   w  w  w . ja  va  2  s .  co m*/
        categoricalItemLabelRotation = new Double(StrictMath.toRadians(value.doubleValue()));
    }
}

From source file:org.hawkular.alerts.engine.util.NelsonData.java

public void addData(Data data) {
    // The rulebase will try to add the same data multiple times (once for each NelsonCondition using
    // the dataId).  Just ignore subsequent attempts.
    if (violationsData.contains(data)) {
        return;//from w w w . ja  v a  2 s . c om
    }

    Double sample;
    try {
        sample = Double.valueOf(data.getValue());
    } catch (Exception e) {
        // not a valid numeric data
        return;
    }

    if (!isValid(sample)) {
        // not a valid Double
        return;
    }

    violationsData.push(data);
    while (violationsData.size() > 15) {
        violationsData.removeLast();
    }

    // System.out.printf("\nViolationsData (size=%s)", violationsData.size());
    // violationsData.stream().forEach(d -> System.out.printf(" \n%d %s", d.getTimestamp(), d.getValue()));
    // System.out.println("");

    addSample(sample.doubleValue());
}