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:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getTotalMSPmtAdj() {
    BigDecimal result = BigDecimal.ZERO;
    if (!ArrayUtils.isEmpty(this.msPmtAdjArr)) {
        for (int i = 0; i < this.msPmtAdjArr.length; i++) {
            result = result.add(this.msPmtAdjArr[i].getPmtAdjAmount());
        }//from   w w  w. j a va  2  s .  co  m
    }
    return result;
}

From source file:hr.restart.util.chart.ChartXY.java

public CategoryDataset createDataSet() throws NullPointerException {

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    DataSet ds = getDataSet();/*from   w ww  .  j a  va2s  .  co  m*/
    SortDescriptor old = ds.getSort();
    String key = getAxisX();
    String value = jcb == null ? getAxisY() : colNamesY[jcb.getSelectedIndex()];

    ds.setSort(new SortDescriptor(new String[] { value }, true, true));

    StorageDataSet scoped = new StorageDataSet();
    scoped.setLocale(Locale.getDefault());
    scoped.setColumns(new Column[] { ds.getColumn(key).cloneColumn(), ds.getColumn(value).cloneColumn(), });
    scoped.open();

    BigDecimal ostali = new BigDecimal(0);

    int maxElements = getNumberOfElements();

    if (comboBoxQuantity != null)
        maxElements = new Integer(comboBoxQuantity.getSelectedItem().toString()).intValue();

    int i = 0;
    for (ds.first(); ds.inBounds(); ds.next()) {
        i++;
        if (i > maxElements) {
            try {

                ostali = ostali.add(ds.getBigDecimal(value));
            } catch (Exception e) {
                System.out.println("(ChartXY) : method --> dataSetToMap : " + e);
                break;
            }
        } else {
            scoped.insertRow(false);

            scoped.setString(key, ds.getString(key));
            scoped.setBigDecimal(value, ds.getBigDecimal(value));
        }
    }

    if (ostali.signum() > 0) {
        scoped.insertRow(false);

        scoped.setString(key, "OSTALI");
        scoped.setBigDecimal(value, ostali);
    }
    scoped.post();

    if (sortByValue())
        scoped.setSort(ds.getSort());
    else
        scoped.setSort(new SortDescriptor(new String[] { key }));

    ds.setSort(old);

    for (scoped.first(); scoped.inBounds(); scoped.next())
        dataset.addValue(scoped.getBigDecimal(value).doubleValue(), "", scoped.getString(key));
    return dataset;
    //return initMapTest();
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getTotalRecentPmtAdjAmt() {
    BigDecimal result = BigDecimal.ZERO;
    if (!ArrayUtils.isEmpty(this.msRecentPmtAdjArr)) {
        for (int i = 0; i < this.msRecentPmtAdjArr.length; i++) {
            result = result.add(this.msRecentPmtAdjArr[i].getPmtAdjAmount());
        }//from   w w  w .  j  a  v  a2 s .c  o m
    }
    return result;
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractHomeController.java

private void drawTenantDashboard(Tenant tenant, String serviceInstanceUUID, HttpServletRequest request,
        List<Map<String, Object>> dashboardItems, AccountStatement currentAccountStatement) {
    ServiceInstance serviceInstance = null;
    int spendIndex = 1;
    if (serviceInstanceUUID != null) {
        serviceInstance = connectorConfigurationManager.getInstanceByUUID(serviceInstanceUUID);
        List<User> activeUsers = tenant.getUsers(serviceInstanceUUID, UserHandle.State.ACTIVE);
        int activeUsersCount = activeUsers != null ? activeUsers.size() : 0;

        Map<String, Object> dashboardItem1 = new HashMap<String, Object>();
        dashboardItem1.put("itemName",
                messageSource.getMessage("label.active.users", null, getSessionLocale(request)));
        dashboardItem1.put("itemValue", activeUsersCount);
        dashboardItem1.put("itemImage", "dashboard_active_users");
        dashboardItem1.put("itemUom",
                messageSource.getMessage("label.dashboard.users", null, getSessionLocale(request)));
        dashboardItems.add(dashboardItem1);

        if (!config.getBooleanValue(Names.com_citrix_cpbm_catalog_payAsYouGoMode)) {
            spendIndex = 2;/*from w  w w.ja v  a2 s . c o  m*/
            int activeSubscriptions = subscriptionService.getCountByState(tenant, null, serviceInstance,
                    Subscription.State.ACTIVE, false);

            Set<Invoice> invoices = currentAccountStatement.getRenewalInvoices();
            BigDecimal renewalAmount = BigDecimal.ZERO;
            for (Invoice invoice : invoices) {
                if (invoice.getSubscription().getServiceInstance().getUuid().equals(serviceInstanceUUID)) {
                    renewalAmount = renewalAmount.add(invoice.getAmount());
                }
            }

            Map<String, Object> dashboardItem2 = new HashMap<String, Object>();
            dashboardItem2.put("itemName",
                    messageSource.getMessage("label.active.subscriptions", null, getSessionLocale(request)));
            dashboardItem2.put("itemValue", activeSubscriptions);
            dashboardItem2.put("itemValue2", renewalAmount);
            dashboardItem2.put("itemValue2Type", "currency");
            dashboardItem2.put("itemValue2Prefix",
                    messageSource.getMessage("label.dashboard.renewal.value", null, getSessionLocale(request)));
            dashboardItem2.put("itemImage", "dashboard_active_subscriptions");
            dashboardItem2.put("itemUom",
                    messageSource.getMessage("label.dashboard.subscriptions", null, getSessionLocale(request)));
            dashboardItems.add(dashboardItem2);
        }

        Map<String, List<BigDecimal>> productInvoiceItemsMap = new HashMap<String, List<BigDecimal>>();

        List<ProductUsage> productUsages = null;
        try {
            productUsages = usageService.getAggregatedProductUsageForTenant(tenant, null, null, false, null,
                    null, serviceInstanceUUID).getProductUsages();
        } catch (UsageServiceException use) {
            // no products found most likely
            logger.error(use);
        }

        if (productUsages != null) {
            for (ProductUsage productUsage : productUsages) {
                List<BigDecimal> productUsageAmountAndQuantity = new ArrayList<BigDecimal>();
                productUsageAmountAndQuantity.add(productUsage.getRawUsage());
                productUsageAmountAndQuantity.add(productUsage.getRatedUsage());
                productInvoiceItemsMap.put(productUsage.getProductCode(), productUsageAmountAndQuantity);
            }
        }

        List<Product> products = productService.listProductsByServiceInstance(serviceInstance, 0, 60);
        // adding perPage as 60 for now so that dashboard UI pagination doesn't break
        int productImageCount = 0;

        BigDecimal totalSpendByTenantByInstance = BigDecimal.ZERO;
        for (Product product : products) {
            Map<String, Object> productValues = new HashMap<String, Object>();
            if (productInvoiceItemsMap.containsKey(product.getCode())) {
                float quantityTotal = Math.round(
                        productInvoiceItemsMap.get(product.getCode()).get(0).floatValue() * 100.0f) / 100.0f;
                BigDecimal amount = productInvoiceItemsMap.get(product.getCode()).get(1);
                totalSpendByTenantByInstance = totalSpendByTenantByInstance.add(amount);
                if (product.getDiscrete()) {
                    // quantity
                    productValues.put("itemValue", new Float(quantityTotal).intValue());
                } else {
                    // quantity
                    productValues.put("itemValue", quantityTotal);
                }
                // amount
                productValues.put("itemValue2", amount);
                productValues.put("itemValue2Type", "currency");

                String customImagePath = product.getImagePath();
                if (customImagePath != null) {
                    productValues.put("itemCustomImage", "/portal/portal/logo/product/" + product.getId());
                    productValues.put("itemId", product.getId());
                } else {
                    if (productImageCount == 3) {
                        productImageCount = 0;
                    }
                    productImageCount = productImageCount + 1;
                    productValues.put("itemImage", "dashboard_product" + productImageCount);
                }
                productValues.put("itemName", product.getName());
                productValues.put("itemValueType", "product");
                productValues.put("itemUom", product.getUom());
                dashboardItems.add(productValues);
            }
        }
        Map<String, Object> dashboardItem3 = new HashMap<String, Object>();
        dashboardItem3.put("itemName",
                messageSource.getMessage("label.total.spend", null, getSessionLocale(request)));
        dashboardItem3.put("itemValue", totalSpendByTenantByInstance);
        dashboardItem3.put("itemValueType", "currency");
        dashboardItem3.put("itemImage", "dashboard_total_spend");
        dashboardItems.add(spendIndex, dashboardItem3);
    }
}

From source file:com.xumpy.thuisadmin.services.implementations.BedragenSrvImpl.java

@Override
public OverzichtGroepBedragenTotal filterOverzichtGroepBedragenTotalGroep(
        OverzichtGroepBedragenTotal overzichtGroepBedragenTotal, Groepen groep) {
    List<OverzichtGroepBedragen> overzichtGroepBedragen = new ArrayList<OverzichtGroepBedragen>();
    BigDecimal newSomBedrag = new BigDecimal(0);

    OverzichtGroepBedragenTotal newOverzichtGroepBedragenTotal = new OverzichtGroepBedragenTotal();

    for (OverzichtGroepBedragen overzichtGroepBedrag : overzichtGroepBedragenTotal
            .getOverzichtGroepBedragen()) {
        if (overzichtGroepBedrag.getType_naam().equals(groep.getNaam())) {
            overzichtGroepBedragen.add(overzichtGroepBedrag);
            newSomBedrag = newSomBedrag.add(overzichtGroepBedrag.getBedrag());
        }//from w  w w  .j a v  a2s . c  o  m
    }
    newOverzichtGroepBedragenTotal.setSomBedrag(newSomBedrag);
    newOverzichtGroepBedragenTotal.setOverzichtGroepBedragen(overzichtGroepBedragen);

    return newOverzichtGroepBedragenTotal;
}

From source file:me.j360.idgen.impl.test.TableIdGenServiceJdbcTest.java

/**
 * [Flow #-10] Positive, Negative Case : try to get next bigdecimal id
 * /* ww w  .  j a  va2s  .co  m*/
 * @throws Exception
 *             fail to test
 */
@Test
public void testGetBigDecimalfromNonBigDecimal() throws Exception {
    if (isBigDecimalImplemented()) {
        IdGenService idGenerator = (IdGenService) applicationContext.getBean("Ids-TestSimpleRequestIdsSize100");
        int testCount = 100;
        BigDecimal initial = new BigDecimal("0");

        // 1. Initialize the counter in the
        // database.
        initializeNextBigDecimalId("test", initial);

        // 2. get next bigdecimal id
        for (int i = 0; i < testCount; i++) {
            BigDecimal id = idGenerator.getNextBigDecimalId();
            assertEquals("The returned id was not what was expected.",
                    initial.add(new BigDecimal(new Integer(i).doubleValue())), id);
        }

        // 3. get next integer id using query
        // directly.
        assertEquals("The next_id column in the database did not have the expected value.",
                initial.add(new BigDecimal(new Integer(testCount).doubleValue())),
                peekNextBigDecimalId("test"));
    } else
        fail("Test failed because BigDecimals are not implemented in current driver.");

}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getAuthorizedInvoiceAmount() {
    BigDecimal total = new BigDecimal(0.0);
    if (!ArrayUtils.isEmpty(invoices)) {
        for (int i = 0; i < invoices.length; i++) {
            if (invoices[i].isAuthorized()) {
                total = total.add(invoices[i].getTollAmount());
            }// w w w.j  a v a  2s .c om
        }
    }
    return total;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getAuthorizedInvoiceFeeAmount() {
    BigDecimal total = new BigDecimal(0.0);
    if (!ArrayUtils.isEmpty(invoices)) {
        for (int i = 0; i < invoices.length; i++) {
            if (invoices[i].isAuthorized()) {
                total = total.add(BigDecimalUtil.nullSafe(invoices[i].getFeeAmount()));
            }//from  ww  w.jav a2s  .  co  m
        }
    }
    return total;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getAuthorizedInvoiceAdminFeeAmount() {
    BigDecimal total = new BigDecimal(0.0);
    if (!ArrayUtils.isEmpty(invoices)) {
        for (int i = 0; i < invoices.length; i++) {
            if (invoices[i].isAuthorized()) {
                total = total.add(BigDecimalUtil.nullSafe(invoices[i].getInvoiceAdminFee()));
            }//ww w  .  j  av  a2 s. com
        }
    }
    return total;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getAuthorizedInvSecondNoticeAdminFee() {
    BigDecimal total = new BigDecimal(0.0);
    if (!ArrayUtils.isEmpty(invoices)) {
        for (int i = 0; i < invoices.length; i++) {
            if (invoices[i].isAuthorized()) {
                total = total.add(BigDecimalUtil.nullSafe(invoices[i].getInvSecondNoticeAdminFee()));
            }/* w  w  w  .  j  a v a 2 s  .co  m*/
        }
    }
    return total;
}