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:org.eclipse.smarthome.binding.homematic.handler.HomematicThingHandler.java

@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters)
        throws ConfigValidationException {
    super.handleConfigurationUpdate(configurationParameters);

    try {//  w w w  .ja v  a 2 s. c o m
        HomematicGateway gateway = getHomematicGateway();
        HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));

        for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
            String key = configurationParameter.getKey();
            Object newValue = configurationParameter.getValue();

            if (key.startsWith("HMP_")) {
                key = StringUtils.removeStart(key, "HMP_");
                Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
                String dpName = StringUtils.substringAfter(key, "_");

                HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER,
                        channelNumber, dpName);
                HmDatapoint dp = device.getChannel(channelNumber).getDatapoint(dpInfo);

                if (dp != null) {
                    try {
                        if (newValue != null) {
                            if (newValue instanceof BigDecimal) {
                                final BigDecimal decimal = (BigDecimal) newValue;
                                if (dp.isIntegerType()) {
                                    newValue = decimal.intValue();
                                } else if (dp.isFloatType()) {
                                    newValue = decimal.doubleValue();
                                }
                            }
                            if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(),
                                    newValue)) {
                                sendDatapoint(dp, new HmDatapointConfig(), newValue);
                            }
                        }
                    } catch (IOException ex) {
                        logger.error("Error setting thing property {}: {}", dpInfo, ex.getMessage());
                    }
                } else {
                    logger.error("Can't find datapoint for thing property {}", dpInfo);
                }
            }
        }
        gateway.triggerDeviceValuesReload(device);
    } catch (HomematicClientException | GatewayNotAvailableException ex) {
        logger.error("Error setting thing properties: {}", ex.getMessage(), ex);
    }
}

From source file:module.siadap.domain.wrappers.SiadapUniverseWrapper.java

/**
 * @param totalPeople/*from  w  ww.  j ava2s  .co m*/
 *            the number of people to calculate the quota on
 * @param quota
 *            the percentage points of quota
 * @return how many people it represents, it is never 0 due to SIADAPs rules
 */
private BigDecimal calculateQuota(int totalPeople, Integer quota) {
    BigDecimal result = new BigDecimal(totalPeople).multiply(new BigDecimal(quota)).divide(new BigDecimal(100));

    int value = result.intValue();
    return value > 0 ? result : BigDecimal.ONE; //if the quota is 0 the the quota shifts to 1

}

From source file:siddur.solidtrust.marktplaats.MarktplaatsService.java

public int averageTimeOnSale(String brand, String model, String build, String fuelType) {
    String baseJpql = "select avg(datediff(m.dateRegisted, m.adDate)) from SortedMarktplaats s, NewMarktplaats m where s.id = m.id and m.dateRegisted is not null and m.repetition is null";
    if (!StringUtils.isEmpty(brand)) {
        baseJpql += " and s.brand = '" + brand + "'";
    }//  w w w .  j a  v a  2s  .c  o m
    if (!StringUtils.isEmpty(model)) {
        baseJpql += " and s.model = '" + model + "'";
    }
    if (!StringUtils.isEmpty(build)) {
        baseJpql += " and s.build = '" + build + "'";
    }
    if (!StringUtils.isEmpty(fuelType)) {
        baseJpql += " and s.fuelType = '" + fuelType + "'";
    }

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

From source file:org.openhab.binding.pilight.internal.PilightBinding.java

private void setDimmerValue(PercentType percent, Code code) {
    if (BigDecimal.ZERO.equals(percent.toBigDecimal())) {
        // pilight is not responding to commands that set both the dimlevel to 0 and state to off. 
        // So, we're only updating the state for now 
        code.setState(Code.STATE_OFF);/*  w w w  .ja v a 2s  . com*/
    } else {
        BigDecimal dimlevel = new BigDecimal(percent.toBigDecimal().toString()).setScale(2)
                .divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP)
                .multiply(BigDecimal.valueOf(MAX_DIM_LEVEL)).setScale(0, RoundingMode.HALF_UP);

        Values values = new Values();
        values.setDimlevel(dimlevel.intValue());
        code.setValues(values);
        code.setState(dimlevel.compareTo(BigDecimal.ZERO) == 1 ? Code.STATE_ON : Code.STATE_OFF);
    }
}

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

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

        T configuration = null;//from w  ww.j a va 2s  .c  om

        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:siddur.solidtrust.marktplaats.MarktplaatsService.java

@Deprecated //replace by averageTimeOnSaleByLucene2
@Transactional(readOnly = true)//from w  w  w .ja  va2  s.c o m
public int averageTimeOnSaleByLucene(String brand, String model, String build) throws Exception {
    List<Integer> items = searchIds(brand, model, build, null);
    if (items.isEmpty()) {
        return 0;
    }
    String baseJpql = "select avg(datediff(m.dateRegisted, m.adDate)) from NewMarktplaats m where m.id in :ids and m.dateRegisted is not null";
    BigDecimal avg = (BigDecimal) em.createNativeQuery(baseJpql).setParameter("ids", items).getSingleResult();
    return avg == null ? 0 : avg.intValue();
}

From source file:gov.medicaid.process.enrollment.sync.FlatFileExporter.java

/**
 * Limits the value to a range/*from w  w w .j  a  v  a2s. c o m*/
 * 
 * @param value the value
 * @param i the range
 * @return the mod of value and i
 */
private String mod(BigDecimal value, int i) {
    if (value == null) {
        return null;
    }
    return String.valueOf(value.intValue() % i);
}

From source file:fr.univlorraine.mondossierweb.services.apogee.MultipleApogeeServiceImpl.java

@Override
public int getNbPJnonValides(String cod_ind, String cod_anu) {
    if (StringUtils.hasText(cod_ind) && StringUtils.hasText(cod_anu)) {
        @SuppressWarnings("unchecked")
        BigDecimal nbPJnonValides = (BigDecimal) entityManagerApogee
                .createNativeQuery("select count(*) from TELEM_IAA_TPJ tit, INS_ADM_ANU iaa "
                        + "where iaa.COD_ANU = " + cod_anu + " " + "and iaa.cod_ind = tit.cod_ind "
                        + "and iaa.ETA_IAA = 'E' " + "and tit.cod_anu= iaa.COD_ANU "
                        + "and tit.STATUT_PJ != 'V' " + "and tit.cod_ind = " + cod_ind)
                .getSingleResult();//from  ww w.j ava2  s .com
        return nbPJnonValides.intValue();
    }
    return 0;
}

From source file:org.kuali.ole.module.purap.document.web.struts.PurchasingAccountsPayableActionBase.java

/**
 * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#deleteSourceLine(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from  w  w  w .  java 2  s.c o m*/
@Override
public ActionForward deleteSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form;

    String[] indexes = getSelectedLineForAccounts(request);
    int itemIndex = Integer.parseInt(indexes[0]);
    int accountIndex = Integer.parseInt(indexes[1]);

    PurApItem item = (PurApItem) ((PurchasingAccountsPayableDocument) purapForm.getDocument())
            .getItem((itemIndex));
    if (itemIndex == -2) {
        item.getSourceAccountingLines().remove(accountIndex);
    } else {
        item.getSourceAccountingLines().remove(accountIndex);
        List<PurApAccountingLine> purApAccountingLineList = item.getSourceAccountingLines();
        BigDecimal initialPercent = new BigDecimal(0);
        for (PurApAccountingLine purApAccountingLine : purApAccountingLineList) {
            initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent());
        }
        initialPercent = new BigDecimal(100).subtract(initialPercent);
        if (initialPercent.intValue() > 0) {
            item.resetAccount(initialPercent);
        } else {
            item.resetAccount(new BigDecimal(0));
        }
    }
    return mapping.findForward(OLEConstants.MAPPING_BASIC);
}

From source file:org.openhab.binding.denon.internal.DenonConnector.java

private String toDenonValue(BigDecimal percent) {
    // Round to nearest number divisible by 0.5 
    percent = percent.divide(POINTFIVE).setScale(0, RoundingMode.UP).multiply(POINTFIVE)
            .min(connection.getMainVolumeMax()).max(BigDecimal.ZERO);

    String dbString = String.valueOf(percent.intValue());

    if (percent.compareTo(BigDecimal.TEN) == -1) {
        dbString = "0" + dbString;
    }//from w  w  w  .  jav a  2 s.c  o m
    if (percent.remainder(BigDecimal.ONE).equals(POINTFIVE)) {
        dbString = dbString + "5";
    }

    return dbString;
}