Example usage for java.math BigDecimal intValue

List of usage examples for java.math BigDecimal intValue

Introduction

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

Prototype

@Override
public int intValue() 

Source Link

Document

Converts this BigDecimal to an int .

Usage

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

/**
 * ?sql???map??/*from   ww w.j  a v a 2  s.co  m*/
 * @param sql
 * @param params
 * @return
 */
public Integer findBySqlCount(String sql, Map<String, ?> params) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0)
        queryObject.setProperties(params);
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.intValue();
    }
    return 0;
}

From source file:com.siapa.managedbean.RegistroMortalidadManagedBean.java

public Boolean updateStoc() {
    Boolean isOk;/*  w ww  .j a  v a 2  s  .  c o m*/
    Integer existencia = 0;
    Integer existenciaActual = jaula.getVentaJaula();
    BigDecimal cantActual = new BigDecimal(existenciaActual);
    BigDecimal reduccion = registroMortalidad.getCantidadRegistroMortalidad();
    int reducc = reduccion.intValue();
    if (cantActual.compareTo(reduccion) == -1) {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("No contiene existencias del producto"));
        isOk = false;
    } else {
        Jaula newJaula = getJaula();
        Jaula idJaula = registroMortalidad.getIdJaula();
        Jaula cactual = jaulaService.findById(idJaula.getIdJaula());
        existencia = cactual.getVentaJaula() - reducc;
        newJaula.setVentaJaula(existencia);
        jaulaService.merge(newJaula);
        isOk = true;
    }

    return isOk;
}

From source file:com.ghy.common.orm.hibernate.HibernateDao.java

/**
 * ?sql???map?map??//from ww w .  j a  v a 2  s. co m
 * @param sql
 * @param params
 * @return
 */
public Integer findBySqlCount(String sql, Map<String, ?> params, Map<String, ?> params2) {
    SQLQuery queryObject = getSession().createSQLQuery(sql);
    if (params != null && params.size() > 0) {
        queryObject.setProperties(params);
    }
    if (params2 != null && params2.size() > 0) {
        queryObject.setProperties(params2);
    }
    List<BigDecimal> qlist = queryObject.list();
    if (qlist != null && qlist.size() > 0) {
        BigDecimal obj = qlist.get(0);
        return obj.intValue();
    }
    return 0;
}

From source file:com.qcadoo.mes.cmmsMachineParts.states.MaintenanceEventStateValidationService.java

private Integer calculatePossibleDeviation(Integer progressTime, BigDecimal possibleDeviationPercent) {
    BigDecimal percent = possibleDeviationPercent.divide(new BigDecimal(100), numberService.getMathContext());
    BigDecimal possibleDeviation = percent.multiply(new BigDecimal(progressTime));
    return possibleDeviation.intValue();
}

From source file:siddur.solidtrust.autoscoutde.AutoscoutDeService.java

public int averageTimeOnSale(String brand, String model, String build) {
    String baseJpql = "select avg(datediff(m.dateRemoved, m.dateScraped)) from AutoscoutDe m where m.dateRemoved != '0000-00-00'";
    if (!StringUtils.isEmpty(brand)) {
        baseJpql += " and m.brand = '" + brand + "'";
    }//from  ww  w  .  j  a  v  a  2  s .  com
    if (!StringUtils.isEmpty(model)) {
        baseJpql += " and m.model = '" + model + "'";
    }
    if (!StringUtils.isEmpty(build)) {
        baseJpql += " and m.build = '" + build + "'";
    }

    BigDecimal avg = (BigDecimal) em.createNativeQuery(baseJpql).getSingleResult();
    return avg.intValue();
}

From source file:org.moqui.impl.entity.EntityJavaUtil.java

public static Object convertFromString(String value, FieldInfo fi, L10nFacade l10n) {
    Object outValue;//w w  w  .  j  a v a 2 s .  c o  m
    boolean isEmpty = value.length() == 0;

    try {
        switch (fi.typeValue) {
        case 1:
            outValue = value;
            break;
        case 2: // outValue = java.sql.Timestamp.valueOf(value);
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = l10n.parseTimestamp(value, null);
            if (outValue == null)
                throw new BaseException("The value [" + value + "] is not a valid date/time for field "
                        + fi.entityName + "." + fi.name);
            break;
        case 3: // outValue = java.sql.Time.valueOf(value);
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = l10n.parseTime(value, null);
            if (outValue == null)
                throw new BaseException("The value [" + value + "] is not a valid time for field "
                        + fi.entityName + "." + fi.name);
            break;
        case 4: // outValue = java.sql.Date.valueOf(value);
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = l10n.parseDate(value, null);
            if (outValue == null)
                throw new BaseException("The value [" + value + "] is not a valid date for field "
                        + fi.entityName + "." + fi.name);
            break;
        case 5: // outValue = Integer.valueOf(value); break
        case 6: // outValue = Long.valueOf(value); break
        case 7: // outValue = Float.valueOf(value); break
        case 8: // outValue = Double.valueOf(value); break
        case 9: // outValue = new BigDecimal(value); break
            if (isEmpty) {
                outValue = null;
                break;
            }
            BigDecimal bdVal = l10n.parseNumber(value, null);
            if (bdVal == null) {
                throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType
                        + "] for field " + fi.entityName + "." + fi.name);
            } else {
                bdVal = bdVal.stripTrailingZeros();
                switch (fi.typeValue) {
                case 5:
                    outValue = bdVal.intValue();
                    break;
                case 6:
                    outValue = bdVal.longValue();
                    break;
                case 7:
                    outValue = bdVal.floatValue();
                    break;
                case 8:
                    outValue = bdVal.doubleValue();
                    break;
                default:
                    outValue = bdVal;
                    break;
                }
            }
            break;
        case 10:
            if (isEmpty) {
                outValue = null;
                break;
            }
            outValue = Boolean.valueOf(value);
            break;
        case 11:
            outValue = value;
            break;
        case 12:
            try {
                outValue = new SerialBlob(value.getBytes());
            } catch (SQLException e) {
                throw new BaseException("Error creating SerialBlob for value [" + value + "] for field "
                        + fi.entityName + "." + fi.name);
            }
            break;
        case 13:
            outValue = value;
            break;
        case 14:
            if (isEmpty) {
                outValue = null;
                break;
            }
            Timestamp ts = l10n.parseTimestamp(value, null);
            outValue = new java.util.Date(ts.getTime());
            break;
        // better way for Collection (15)? maybe parse comma separated, but probably doesn't make sense in the first place
        case 15:
            outValue = value;
            break;
        default:
            outValue = value;
            break;
        }
    } catch (IllegalArgumentException e) {
        throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType
                + "] for field " + fi.entityName + "." + fi.name, e);
    }

    return outValue;
}

From source file:com.siapa.managedbean.IngresoProductoManagedBean.java

public Boolean updateStoc() {
    Boolean isOk;/*from ww  w . j  ava  2s .c om*/
    Integer existencia = 0;
    Integer existenciaActual = jaula.getVentaJaula();
    BigDecimal cantActual = new BigDecimal(existenciaActual);
    BigDecimal aumento = ingresoProducto.getCantidadIngresoProducto();
    int suma = aumento.intValue();
    //if (cantActual.compareTo(reduccion) == -1) {
    //    FacesContext context = FacesContext.getCurrentInstance();
    //    context.addMessage(null, new FacesMessage("La cantidad es mayor a la almacenada"));
    // isOk = false;
    //} else {
    Jaula newJaula = getJaula();
    Jaula idJaula = ingresoProducto.getIdJaula();
    Jaula cactual = jaulaService.findById(idJaula.getIdJaula());
    existencia = cactual.getVentaJaula() + suma;
    newJaula.setVentaJaula(existencia);
    jaulaService.merge(newJaula);
    isOk = true;
    //}

    return isOk;
}

From source file:org.libreplan.business.planner.entities.SigmoidFunction.java

private BigDecimal intPart(BigDecimal bd) {
    return BigDecimal.valueOf(bd.intValue());
}

From source file:com.codecrate.shard.level.ConstantRateLevelCalculator.java

public int calculateValue(int level) {
    BigDecimal value = rate.multiply(new BigDecimal(level - 1));
    value = value.add(new BigDecimal(initialValue));
    value = value.setScale(0, BigDecimal.ROUND_HALF_UP);
    LOG.debug("Computed value for level " + level + " is: " + value);

    return value.intValue();
}

From source file:com.envision.envservice.service.RankingListService.java

private List<SpiritSortBo> sortuserPraiseNumSort(Map<String, Integer> lowerUserPraiseNum,
        final SortType sortType) {
    List<SpiritSortBo> sbos = new ArrayList<SpiritSortBo>();

    for (Entry<String, Integer> entry : lowerUserPraiseNum.entrySet()) {
        if (!TOTAL.equals(entry.getKey())) {
            SpiritSortBo sbo = new SpiritSortBo();
            sbo.setUserId(entry.getKey());
            BigDecimal fz = new BigDecimal(entry.getValue());
            BigDecimal fm = new BigDecimal(lowerUserPraiseNum.get(TOTAL));
            if (fm.intValue() == 0) {
                sbo.setPercent("0");
            } else {
                DecimalFormat df = new DecimalFormat("0.00");
                String pe = df.format(fz.multiply(new BigDecimal(100)).divide(fm, 2, RoundingMode.HALF_UP));
                sbo.setPercent(pe);/*from  w  w  w  .  j  a  va  2  s .  c om*/
            }
            sbos.add(sbo);
        }
    }
    // ?
    // Collections.sort(sbos, new SpiritSortBoComparator(sortType));
    Collections.sort(sbos, new Comparator<SpiritSortBo>() {

        public int compare(SpiritSortBo o1, SpiritSortBo o2) {
            BigDecimal o1Percent = new BigDecimal(o1.getPercent());
            BigDecimal o2Percent = new BigDecimal(o2.getPercent());

            int multiplier = -1;
            if (sortType.equals(SortType.ASC)) {
                multiplier = 1;
            }
            return o1Percent.compareTo(o2Percent) * multiplier;
        }

    });
    return sbos;
}