Example usage for java.math BigDecimal longValue

List of usage examples for java.math BigDecimal longValue

Introduction

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

Prototype

@Override
public long longValue() 

Source Link

Document

Converts this BigDecimal to a long .

Usage

From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java

protected long countSqlResult(final String hql, final Map<String, ?> values) {
    String countHql = prepareCountHql(hql);

    try {/*w  w  w . ja va 2  s.c o m*/
        BigDecimal count = (BigDecimal) createSQLQuery(countHql, values).uniqueResult();
        return count.longValue();
    } catch (Exception e) {
        throw new RuntimeException("Sql can't be auto count, hql is:" + countHql, e);
    }
}

From source file:com.norconex.collector.http.db.impl.derby.DerbyCrawlURLDatabase.java

private CrawlURL toCrawlURL(ResultSet rs) throws SQLException {
    if (rs == null) {
        return null;
    }/*from   ww  w .j a  v a  2s . co  m*/
    int colCount = rs.getMetaData().getColumnCount();
    CrawlURL crawlURL = new CrawlURL(rs.getString("url"), rs.getInt("depth"));
    if (colCount > COLCOUNT_SITEMAP) {
        crawlURL.setSitemapChangeFreq(rs.getString("smChangeFreq"));
        BigDecimal bigP = rs.getBigDecimal("smPriority");
        if (bigP != null) {
            crawlURL.setSitemapPriority(bigP.floatValue());
        }
        BigDecimal bigLM = rs.getBigDecimal("smLastMod");
        if (bigLM != null) {
            crawlURL.setSitemapLastMod(bigLM.longValue());
        }
        if (colCount > COLCOUNT_ALL) {
            crawlURL.setDocChecksum(rs.getString("docchecksum"));
            crawlURL.setHeadChecksum(rs.getString("headchecksum"));
            crawlURL.setStatus(CrawlStatus.valueOf(rs.getString("status")));
        }
    }
    return crawlURL;
}

From source file:org.pentaho.reporting.engine.classic.core.function.ItemAvgFunction.java

/**
 * Returns the function value, in this case the average of all values of a specific column in the report's TableModel.
 *
 * @return The function value.//w w w .  j a  va2 s.c  o  m
 */
public Object getValue() {
    final BigDecimal count = itemCount.get(lastGroupSequenceNumber);
    if (count == null) {
        return null;
    }
    final BigDecimal sum = this.sum.get(lastGroupSequenceNumber);
    if (sum == null) {
        return null;
    }
    if (count.longValue() == 0) {
        return null;
    }

    return sum.divide(count, scale, roundingMode);
}

From source file:com.abiquo.server.core.enterprise.EnterpriseDAO.java

public DefaultEntityCurrentUsed getEnterpriseResourceUsage(final int enterpriseId) {
    Object[] vmResources = (Object[]) getSession().createSQLQuery(SUM_VM_RESOURCES)
            .setParameter("enterpriseId", enterpriseId).uniqueResult();

    Long cpu = vmResources[0] == null ? 0 : ((BigDecimal) vmResources[0]).longValue();
    Long ram = vmResources[1] == null ? 0 : ((BigDecimal) vmResources[1]).longValue();
    Long hd = vmResources[2] == null ? 0 : ((BigDecimal) vmResources[2]).longValue();

    BigDecimal extraHd = (BigDecimal) getSession().createSQLQuery(SUM_EXTRA_HD_RESOURCES)
            .setParameter("enterpriseId", enterpriseId).uniqueResult();
    Long hdTot = extraHd == null ? hd : hd + extraHd.longValue() * 1024 * 1024;

    Long storage = getStorageUsage(enterpriseId) * 1024 * 1024; // Storage usage is stored in MB
    Long publiIp = getPublicIPUsage(enterpriseId);
    Long vlanCount = getVLANUsage(enterpriseId);

    // TODO repository

    // XXX checking null resource utilization (if any resource allocated)
    DefaultEntityCurrentUsed used = new DefaultEntityCurrentUsed(cpu.intValue(), ram, hdTot);

    used.setStorage(storage);//ww w  .j  a va2s . co  m
    used.setPublicIp(publiIp);
    used.setVlanCount(vlanCount);

    return used;
}

From source file:org.broadleafcommerce.core.pricing.service.workflow.FulfillmentItemPricingActivity.java

public long applyDifferenceToAmount(FulfillmentGroupItem fgItem, long numApplicationsNeeded, Money unitAmount) {
    BigDecimal numTimesToApply = new BigDecimal(Math.min(numApplicationsNeeded, fgItem.getQuantity()));

    Money oldAmount = fgItem.getTotalItemAmount();
    Money changeToAmount = unitAmount.multiply(numTimesToApply);

    fgItem.setTotalItemAmount(oldAmount.add(changeToAmount));
    return numTimesToApply.longValue();
}

From source file:org.broadleafcommerce.core.pricing.service.workflow.FulfillmentItemPricingActivity.java

public long applyTaxDifference(FulfillmentGroupItem fgItem, long numApplicationsNeeded, Money unitAmount) {
    BigDecimal numTimesToApply = new BigDecimal(Math.min(numApplicationsNeeded, fgItem.getQuantity()));

    Money oldAmount = fgItem.getTotalItemTaxableAmount();
    Money changeToAmount = unitAmount.multiply(numTimesToApply);

    fgItem.setTotalItemTaxableAmount(oldAmount.add(changeToAmount));
    return numTimesToApply.longValue();
}

From source file:org.broadleafcommerce.core.pricing.service.workflow.FulfillmentItemPricingActivity.java

public long applyDifferenceToProratedAdj(FulfillmentGroupItem fgItem, long numApplicationsNeeded,
        Money unitAmount) {// w  w  w. j av  a  2  s.  com
    BigDecimal numTimesToApply = new BigDecimal(Math.min(numApplicationsNeeded, fgItem.getQuantity()));

    Money oldAmount = fgItem.getProratedOrderAdjustmentAmount();
    Money changeToAmount = unitAmount.multiply(numTimesToApply);

    fgItem.setProratedOrderAdjustmentAmount(oldAmount.add(changeToAmount));
    return numTimesToApply.longValue();
}

From source file:org.eclipse.smarthome.config.core.Configuration.java

public <T> T as(Class<T> configurationClass) {
    synchronized (this) {

        T configuration = null;/*from w  w w  . ja v a 2s  .  c o  m*/

        try {
            configuration = configurationClass.newInstance();
        } catch (InstantiationException | IllegalAccessException ex) {
            logger.error("Could not create configuration instance: " + ex.getMessage(), ex);
            return null;
        }

        List<Field> fields = getAllFields(configurationClass);
        for (Field field : fields) {
            String fieldName = field.getName();
            String typeName = field.getType().getSimpleName();
            Object value = properties.get(fieldName);

            if (value == null && field.getType().isPrimitive()) {
                logger.debug("Skipping field '{}', because it's primitive data type and value is not set",
                        fieldName);
                continue;
            }

            try {
                if (value != null && value instanceof BigDecimal && !typeName.equals("BigDecimal")) {
                    BigDecimal bdValue = (BigDecimal) value;
                    if (typeName.equalsIgnoreCase("Float")) {
                        value = bdValue.floatValue();
                    } else if (typeName.equalsIgnoreCase("Double")) {
                        value = bdValue.doubleValue();
                    } else if (typeName.equalsIgnoreCase("Long")) {
                        value = bdValue.longValue();
                    } else if (typeName.equalsIgnoreCase("Integer") || typeName.equalsIgnoreCase("int")) {
                        value = bdValue.intValue();
                    }
                }

                if (value != null) {
                    logger.debug("Setting value ({}) {} to field '{}' in configuration class {}", typeName,
                            value, fieldName, configurationClass.getName());
                    FieldUtils.writeField(configuration, fieldName, value, true);
                }
            } catch (Exception ex) {
                logger.warn("Could not set field value for field '" + fieldName + "': " + ex.getMessage(), ex);
            }
        }

        return configuration;
    }
}

From source file:org.kalypso.model.wspm.tuhh.core.wprof.BCEShapeWPRofContentProvider.java

private <T> T toNumber(final BigDecimal in, final Class<T> outType) {
    if (Byte.class == outType)
        return outType.cast(in.byteValue());
    if (Short.class == outType)
        return outType.cast(in.shortValue());
    if (Integer.class == outType)
        return outType.cast(in.intValue());
    if (Long.class == outType)
        return outType.cast(in.longValue());
    if (Float.class == outType)
        return outType.cast(in.floatValue());
    if (Double.class == outType)
        return outType.cast(in.doubleValue());

    if (BigInteger.class == outType)
        return outType.cast(in.toBigInteger());

    return outType.cast(in);
}

From source file:egovframework.rte.fdl.idgnr.impl.AbstractIdGnrService.java

/**
 *    ? Long ? ? ID/*from   w  w  w.j av a  2  s . c  o m*/
 * @param maxId
 *        
 * @return long value to be less than the specified
 *         maxId
 * @throws FdlException
 *         ? ID ? MaxId ?
 */
protected final long getNextLongIdChecked(long maxId) throws FdlException {
    long nextId;
    if (useBigDecimals) {
        // Use BigDecimal data type
        BigDecimal bd;
        synchronized (mSemaphore) {
            bd = getNextBigDecimalIdInner();
        }

        if (bd.compareTo(BIG_DECIMAL_MAX_LONG) > 0) {
            getLogger().error(messageSource.getMessage("error.idgnr.greater.maxid", new String[] { "Long" },
                    Locale.getDefault()));
            throw new FdlException(messageSource, "error.idgnr.greater.maxid");
        }
        nextId = bd.longValue();
    } else {
        // Use long data type
        synchronized (mSemaphore) {
            nextId = getNextLongIdInner();
        }
    }

    // Make sure that the id is valid for the
    // requested data type.
    if (nextId > maxId) {
        getLogger().error(messageSource.getMessage("error.idgnr.greater.maxid", new String[] { "Long" },
                Locale.getDefault()));
        throw new FdlException(messageSource, "error.idgnr.greater.maxid");
    }

    return nextId;
}