Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

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

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:it.govpay.core.utils.RtUtils.java

private static void validaSemantica(CtDatiVersamentoRPT rpt, CtDatiVersamentoRT rt, EsitoValidazione esito) {

    valida(rpt.getCodiceContestoPagamento(), rt.getCodiceContestoPagamento(), esito,
            "CodiceContestoPagamento non corrisponde", true);
    valida(rpt.getIdentificativoUnivocoVersamento(), rt.getIdentificativoUnivocoVersamento(), esito,
            "IdentificativoUnivocoVersamento non corrisponde", true);

    Rpt.EsitoPagamento esitoPagamento = validaSemanticaCodiceEsitoPagamento(rt.getCodiceEsitoPagamento(),
            esito);//from  ww  w .  ja v  a2s . c  om

    // Se siamo in pagamento eseguito, parzialmente eseguito o parzialmente decorso, devono esserci tanti versamenti quanti pagamenti.
    if (esitoPagamento != null) {
        switch (esitoPagamento) {
        case DECORRENZA_TERMINI_PARZIALE:
        case PAGAMENTO_ESEGUITO:
        case PAGAMENTO_PARZIALMENTE_ESEGUITO:
            if (rt.getDatiSingoloPagamento().size() != rpt.getDatiSingoloVersamento().size()) {
                esito.addErrore("Numero di pagamenti diverso dal numero di versamenti per una ricevuta di tipo "
                        + esitoPagamento.name(), true);
                return;
            }
        case DECORRENZA_TERMINI:
        case PAGAMENTO_NON_ESEGUITO:
            if (rt.getDatiSingoloPagamento().size() != 0
                    && rt.getDatiSingoloPagamento().size() != rpt.getDatiSingoloVersamento().size()) {
                esito.addErrore("Numero di pagamenti diverso dal numero di versamenti per una ricevuta di tipo "
                        + esitoPagamento.name(), true);
                return;
            }
        }
    }

    BigDecimal importoTotaleCalcolato = BigDecimal.ZERO;

    for (int i = 0; i < rpt.getDatiSingoloVersamento().size(); i++) {

        CtDatiSingoloVersamentoRPT singoloVersamento = rpt.getDatiSingoloVersamento().get(i);
        CtDatiSingoloPagamentoRT singoloPagamento = null;
        if (rt.getDatiSingoloPagamento().size() != 0) {
            singoloPagamento = rt.getDatiSingoloPagamento().get(i);
            validaSemanticaSingoloVersamento(singoloVersamento, singoloPagamento, esito);
            importoTotaleCalcolato = importoTotaleCalcolato.add(singoloPagamento.getSingoloImportoPagato());
        }
    }

    if (importoTotaleCalcolato.compareTo(rt.getImportoTotalePagato()) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] non corrisponde alla somma dei SingoliImportiPagati ["
                + importoTotaleCalcolato.doubleValue() + "]", true);
    if (esitoPagamento == Rpt.EsitoPagamento.PAGAMENTO_NON_ESEGUITO
            && rt.getImportoTotalePagato().compareTo(BigDecimal.ZERO) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da 0 per un pagamento con esito 'Non Eseguito'.", true);
    if (esitoPagamento == Rpt.EsitoPagamento.DECORRENZA_TERMINI
            && rt.getImportoTotalePagato().compareTo(BigDecimal.ZERO) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da 0 per un pagamento con esito 'Decorrenza temini'.", true);
    if (esitoPagamento == Rpt.EsitoPagamento.PAGAMENTO_ESEGUITO
            && rt.getImportoTotalePagato().compareTo(rpt.getImportoTotaleDaVersare()) != 0)
        esito.addErrore("Importo totale del pagamento [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da quanto richiesto [" + rpt.getImportoTotaleDaVersare().doubleValue() + "]",
                false);
}

From source file:ymanv.forex.provider.AProvider.java

protected BigDecimal avg(BigDecimal first, BigDecimal second) {
    return first.add(second).divide(TWO);
}

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:ch.ralscha.extdirectspring.provider.FormInfoController.java

@ExtDirectMethod(value = ExtDirectMethodType.FORM_POST, group = "group3")
public ExtDirectFormPostResult updateInfoDirect(FormInfo formInfo, BindingResult result) {
    ExtDirectFormPostResult e = new ExtDirectFormPostResult(result);
    e.addResultProperty("name", formInfo.getName().toUpperCase());
    e.addResultProperty("age", formInfo.getAge() + 10);
    e.addResultProperty("admin", !formInfo.isAdmin());
    BigDecimal bd = new BigDecimal("1000");
    bd = bd.add(formInfo.getSalary());
    e.addResultProperty("salary", bd);
    e.addResultProperty("result", formInfo.getResult() + "RESULT");
    return e;//from w  ww . j  a  va  2  s. c o  m
}

From source file:com.aoindustries.website.signup.SignupCustomizeManagementActionHelper.java

/**
 * Gets the total monthly rate for the server, basic server + hardware options + management options
 *///from   w w  w  .j av  a 2 s .  c o  m
public static BigDecimal getTotalMonthlyRate(AOServConnector rootConn,
        SignupCustomizeServerForm signupCustomizeServerForm,
        SignupCustomizeManagementForm signupCustomizeManagementForm, PackageDefinition packageDefinition)
        throws SQLException, IOException {
    BigDecimal monthlyRate = SignupCustomizeServerActionHelper.getHardwareMonthlyRate(rootConn,
            signupCustomizeServerForm, packageDefinition);

    int totalDiskSpace = SignupCustomizeServerActionHelper.getTotalHardwareDiskSpace(rootConn,
            signupCustomizeServerForm);

    // Add the backup onsite option
    int backupOnsiteOption = signupCustomizeManagementForm.getBackupOnsiteOption();
    if (backupOnsiteOption != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits().get(backupOnsiteOption);
        BigDecimal rate = pdl.getAdditionalRate();
        if (rate != null)
            monthlyRate = monthlyRate.add(rate.multiply(BigDecimal.valueOf(totalDiskSpace)));
    }

    // Add the backup offsite option
    int backupOffsiteOption = signupCustomizeManagementForm.getBackupOffsiteOption();
    if (backupOffsiteOption != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits().get(backupOffsiteOption);
        BigDecimal rate = pdl.getAdditionalRate();
        if (rate != null)
            monthlyRate = monthlyRate.add(rate.multiply(BigDecimal.valueOf(totalDiskSpace)));
    }

    // Add the distributionScanOption option
    int distributionScanOption = signupCustomizeManagementForm.getDistributionScanOption();
    if (distributionScanOption != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits().get(distributionScanOption);
        BigDecimal rate = pdl.getAdditionalRate();
        if (rate != null)
            monthlyRate = monthlyRate.add(rate);
    }

    // Add the backup offsite option
    int failoverOption = signupCustomizeManagementForm.getFailoverOption();
    if (failoverOption != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits().get(failoverOption);
        String resourceName = pdl.getResource().getName();
        if (Resource.FAILOVER.equals(resourceName)) {
            // Failover mirror only
            BigDecimal rate = pdl.getAdditionalRate();
            if (rate != null)
                monthlyRate = monthlyRate.add(rate.multiply(BigDecimal.valueOf(totalDiskSpace)));
        } else if (Resource.MYSQL_REPLICATION.equals(resourceName)) {
            // Failover mirror plus MySQL replication
            Resource failoverResource = rootConn.getResources().get(Resource.FAILOVER);
            if (failoverResource == null)
                throw new SQLException("Unable to find Resource: " + Resource.FAILOVER);
            PackageDefinitionLimit failoverPDL = packageDefinition.getLimit(failoverResource);
            if (failoverPDL == null)
                throw new SQLException("Unable to find PackageDefinitionLimit: " + Resource.FAILOVER
                        + " on PackageDefinition #" + packageDefinition.getPkey());
            BigDecimal additionalRate = BigDecimal.valueOf(0, 2);
            BigDecimal failoverRate = failoverPDL.getAdditionalRate();
            if (failoverRate != null)
                additionalRate = failoverRate.multiply(BigDecimal.valueOf(totalDiskSpace));
            BigDecimal rate = pdl.getAdditionalRate();
            if (rate != null)
                additionalRate = additionalRate.add(rate);
            if (additionalRate != null)
                monthlyRate = monthlyRate.add(additionalRate);
        }
    }

    return monthlyRate;
}

From source file:com.quinsoft.zeidon.domains.BigDecimalDomain.java

@Override
public Object addToAttribute(Task task, AttributeInstance attributeInstance, AttributeDef attributeDef,
        Object currentValue, Object operand) {
    BigDecimal num = (BigDecimal) convertExternalValue(task, attributeInstance, attributeDef, null, operand);
    BigDecimal value = (BigDecimal) currentValue;
    return value.add(num);
}

From source file:ch.ralscha.extdirectspring.provider.FormInfoController3.java

@SuppressWarnings("unused")
@ExtDirectMethod(value = ExtDirectMethodType.FORM_POST_JSON)
public ExtDirectFormPostResult updateInfoJsonDirect(Locale locale,
        @RequestParam(value = "p1", required = true) Long param1,
        @RequestParam(value = "p2", required = true) String param2, @Valid FormInfo formInfo) {

    ExtDirectFormPostResult e = new ExtDirectFormPostResult();
    e.addResultProperty("name", formInfo.getName().toUpperCase());
    e.addResultProperty("age", formInfo.getAge() + 10);
    e.addResultProperty("admin", !formInfo.isAdmin());
    BigDecimal bd = new BigDecimal("1000");
    bd = bd.add(formInfo.getSalary());
    e.addResultProperty("salary", bd);
    e.addResultProperty("result", formInfo.getResult() + "RESULT");
    return e;/*from www. ja v a  2 s  .  c o m*/
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.BigDecimalCalculator.java

public Object add(Object obj1, Object obj2) {
    BigDecimal decimalData1 = (BigDecimal) obj1;
    BigDecimal decimalData2 = (BigDecimal) obj2;

    return (Object) (decimalData1.add(decimalData2));
}

From source file:kr.ac.kaist.se.simulator.NormalDistributor.java

public int getNextVal() {
    String _val = Double.toString(this.distGenerator.sample());
    BigDecimal dec = new BigDecimal(_val);
    BigDecimal std = new BigDecimal(Integer.toString(this.stDev));
    dec = dec.add(new BigDecimal(Integer.toString(mean)));
    std = std.multiply(new BigDecimal(_val));
    int retVal = dec.add(std).toBigInteger().intValue();
    return retVal;
}

From source file:com.axelor.web.MapRest.java

@Path("/geomap/turnover")
@GET/* w w w.j  a  v  a  2  s  .  c om*/
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getGeoMapData() {

    Map<String, BigDecimal> data = new HashMap<String, BigDecimal>();
    List<? extends SaleOrder> orders = saleOrderRepo.all().filter("self.statusSelect=?", 3).fetch();
    JsonNodeFactory factory = JsonNodeFactory.instance;
    ObjectNode mainNode = factory.objectNode();
    ArrayNode arrayNode = factory.arrayNode();

    ArrayNode labelNode = factory.arrayNode();
    labelNode.add("Country");
    labelNode.add("Turnover");
    arrayNode.add(labelNode);

    for (SaleOrder so : orders) {

        Country country = so.getMainInvoicingAddress().getAddressL7Country();
        BigDecimal value = so.getExTaxTotal();

        if (country != null) {
            String key = country.getName();

            if (data.containsKey(key)) {
                BigDecimal oldValue = data.get(key);
                oldValue = oldValue.add(value);
                data.put(key, oldValue);
            } else {
                data.put(key, value);
            }
        }
    }

    Iterator<String> keys = data.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        ArrayNode dataNode = factory.arrayNode();
        dataNode.add(key);
        dataNode.add(data.get(key));
        arrayNode.add(dataNode);
    }

    mainNode.put("status", 0);
    mainNode.put("data", arrayNode);
    return mainNode;
}