Example usage for java.math BigDecimal signum

List of usage examples for java.math BigDecimal signum

Introduction

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

Prototype

public int signum() 

Source Link

Document

Returns the signum function of this BigDecimal .

Usage

From source file:org.egov.wtms.web.controller.application.GenericBillGeneratorController.java

@GetMapping(value = "/collecttax-view")
public ModelAndView collectTaxView(@ModelAttribute WaterConnectionDetails waterConnectionDetails,
        HttpServletRequest request, Model model) {
    String consumerNumber = request.getParameter("applicationCode");
    if (isNotBlank(consumerNumber))
        waterConnectionDetails = waterConnectionDetailsService
                .findByApplicationNumberOrConsumerCodeAndStatus(consumerNumber, ACTIVE);
    if (waterConnectionDetails == null)
        waterConnectionDetails = waterConnectionDetailsService
                .findByApplicationNumberOrConsumerCode(consumerNumber);
    model.addAttribute("connectionType", waterConnectionDetailsService.getConnectionTypesMap()
            .get(waterConnectionDetails.getConnectionType().name()));
    model.addAttribute("mode", "waterTaxCollection");
    model.addAttribute("checkOperator", waterTaxUtils.checkCollectionOperatorRole());
    model.addAttribute("feeDetails", connectionDemandService.getSplitFee(waterConnectionDetails));
    BigDecimal waterTaxDueAmount = waterConnectionDetailsService.getWaterTaxDueAmount(waterConnectionDetails);
    model.addAttribute("waterTaxDueforParent", waterTaxDueAmount.signum() >= 0 ? waterTaxDueAmount : ZERO);
    return new ModelAndView("application/collecttax-view", "waterConnectionDetails", waterConnectionDetails);
}

From source file:org.finra.datagenerator.engine.scxml.tags.RangeExtension.java

/**
 * Performs variable assignments from a set of values
 *
 * @param action            a RangeTag Action
 * @param possibleStateList a current list of possible states produced so far from expanding a model state
 * @return the cartesian product of every current possible state and the set of values specified by action
 *//*from   w  w  w. ja v a 2 s  .  c om*/
public List<Map<String, String>> pipelinePossibleStates(RangeTag action,
        List<Map<String, String>> possibleStateList) {
    String variable = action.getName();
    BigDecimal from = new BigDecimal(action.getFrom());
    BigDecimal to = new BigDecimal(action.getTo());
    BigDecimal step;
    if (action.getStep() != null) {
        step = new BigDecimal(action.getStep());
    } else {
        step = BigDecimal.ONE;
    }

    List<BigDecimal> rangeValues = new ArrayList<>();
    if (step.signum() == 1) {
        for (BigDecimal current = from; current.compareTo(to) <= 0; current = current.add(step)) {
            rangeValues.add(current);
        }
    } else if (step.signum() == -1) {
        for (BigDecimal current = from; current.compareTo(to) >= 0; current = current.add(step)) {
            rangeValues.add(current);
        }
    } else {
        rangeValues.add(from);
    }

    //take the product
    List<Map<String, String>> productTemp = new LinkedList<>();
    for (Map<String, String> p : possibleStateList) {
        for (BigDecimal value : rangeValues) {
            HashMap<String, String> n = new HashMap<>(p);
            n.put(variable, value.toString());
            productTemp.add(n);
        }
    }

    return productTemp;
}

From source file:org.finra.herd.core.helper.ConfigurationHelper.java

/**
 * Gets a property value as {@link BigDecimal}. Additionally it ensures that the property value is not negative.
 *
 * @param configurationValue the {@link BigDecimal} configuration value
 * @param environment the environment containing the property
 *
 * @return the non-negative {@link BigDecimal} property value
 *///from   w  w  w. j  ava 2 s .  c  o m
public BigDecimal getNonNegativeBigDecimalRequiredProperty(ConfigurationValue configurationValue,
        Environment environment) {
    final BigDecimal nonNegativeBigDecimalPropertyValue = getBigDecimalRequiredProperty(configurationValue,
            environment);
    if (nonNegativeBigDecimalPropertyValue.signum() == -1) {
        throw new IllegalStateException(
                String.format("Configuration \"%s\" has an invalid non-negative BigDecimal value: \"%s\".",
                        configurationValue.getKey(), nonNegativeBigDecimalPropertyValue));
    }

    return nonNegativeBigDecimalPropertyValue;
}

From source file:org.totschnig.myexpenses.activity.AccountEdit.java

/**
 * populates the input field either from the database or with default value for currency (from Locale)
 *//*w  w  w  .  ja  v  a 2  s .  com*/
private void populateFields() {

    BigDecimal amount = mAccount.openingBalance.getAmountMajor();
    if (amount.signum() == -1) {
        amount = amount.abs();
    } else {
        mType = INCOME;
        configureType();
    }
    mAmountText.setAmount(amount);
    mCurrencySpinner.setSelection(
            currencyAdapter.getPosition(CurrencyEnum.valueOf(mAccount.currency.getCurrencyCode())));
    mAccountTypeSpinner.setSelection(mAccount.type.ordinal());
    int selected = mColors.indexOf(mAccount.color);
    mColorSpinner.setSelection(selected);
}

From source file:org.openconcerto.erp.graph.GraphFamilleArticlePanel.java

protected BigDecimal updateDataset(List<String> labels, List<Number> values) {

    final SQLTable tableVFElement = Configuration.getInstance().getDirectory()
            .getElement("SAISIE_VENTE_FACTURE_ELEMENT").getTable();
    final SQLTable tableVF = tableVFElement.getTable("SAISIE_VENTE_FACTURE");
    final SQLTable tableArticle = tableVFElement.getTable("ARTICLE");

    final SQLSelect sel = new SQLSelect();
    final String field = "ID_FAMILLE_ARTICLE";

    sel.addSelect(tableArticle.getField(field));

    sel.addSelect(tableVFElement.getField("T_PA_HT"), "SUM");
    sel.addSelect(tableVFElement.getField("T_PV_HT"), "SUM");
    sel.addSelect(tableVFElement.getField("QTE"), "SUM");

    Where w = new Where(tableVF.getKey(), "=", tableVFElement.getField("ID_SAISIE_VENTE_FACTURE"));
    w = w.and(new Where(tableVF.getField("DATE"), this.d1, this.d2));
    w = w.and(new Where(tableArticle.getKey(), "=", tableVFElement.getField("ID_ARTICLE")));
    sel.setWhere(w);/*from   w  w  w  . j  ava2s  .  com*/

    final List<Object[]> rowsArticle = (List<Object[]>) Configuration.getInstance().getBase().getDataSource()
            .execute(sel.asString() + " GROUP BY \"ARTICLE\".\"" + field + "\"", new ArrayListHandler());

    Collections.sort(rowsArticle, new Comparator<Object[]>() {
        @Override
        public int compare(Object[] o1, Object[] o2) {

            BigDecimal pa1 = (BigDecimal) o1[1];
            BigDecimal pv1 = (BigDecimal) o1[2];
            BigDecimal qte1 = new BigDecimal(o1[3].toString());

            BigDecimal pa2 = (BigDecimal) o2[1];
            BigDecimal pv2 = (BigDecimal) o2[2];
            BigDecimal qte2 = new BigDecimal(o2[3].toString());

            BigDecimal marge1 = pv1.subtract(pa1).multiply(qte1, DecimalUtils.HIGH_PRECISION);
            BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, DecimalUtils.HIGH_PRECISION);
            return pv1.compareTo(pv2);
        }
    });

    SQLTable tableFamille = tableVFElement.getTable("FAMILLE_ARTICLE");

    BigDecimal total = BigDecimal.ZERO;
    for (int i = 0; i < rowsArticle.size(); i++) {
        Object[] o = rowsArticle.get(i);

        BigDecimal pv2 = (BigDecimal) o[2];
        total = total.add(pv2);
    }
    if (total.signum() > 0) {

        for (int i = 0; i < 12 && i < rowsArticle.size(); i++) {
            Object[] o = rowsArticle.get(i);
            BigDecimal pa2 = (BigDecimal) o[1];
            BigDecimal pv2 = (BigDecimal) o[2];
            BigDecimal qte2 = new BigDecimal(o[3].toString());
            BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, DecimalUtils.HIGH_PRECISION);

            String s = "Indfini";
            if (o[0] != null) {
                int id = ((Number) o[0]).intValue();
                s = tableFamille.getRow(id).getString("NOM");
            }
            values.add(pv2);
            labels.add(s + "(" + decFormat.format(pv2.setScale(2, RoundingMode.HALF_UP).doubleValue())
                    + " soit " + pv2.divide(total, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2,
                            RoundingMode.HALF_UP)
                    + "%)");
        }
    }
    return total;
}

From source file:se.frikod.payday.DailyBudgetFragment.java

public void editBudgetItem(final View v, final int currentIndex) {

    LayoutInflater inflater = activity.getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.daily_budget_edit_budget_item, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
    builder.setTitle(getString(R.string.edit_budget_item_title));

    final BudgetItem budgetItem;
    final EditText titleView = (EditText) dialogView.findViewById(R.id.budget_item_title);
    final Spinner typeView = (Spinner) dialogView.findViewById(R.id.budget_item_type);
    final EditText amountView = (EditText) dialogView.findViewById(R.id.budget_item_amount);

    if (currentIndex == NEW_BUDGET_ITEM) {
        budgetItem = null;/*from w w w  . j ava  2s. c  o  m*/
        builder.setTitle(getString(R.string.add_budget_item_dialog_title));
        builder.setPositiveButton(R.string.add_budget_item, null);
    } else {
        builder.setTitle(getString(R.string.edit_budget_item_title));

        budgetItem = budget.budgetItems.get(currentIndex);

        String title = budgetItem.title;
        BigDecimal amount = budgetItem.amount;
        int type;
        if (amount.signum() < 0) {
            type = 0;
            amount = amount.negate();
        } else {
            type = 1;
        }

        titleView.setText(title);
        typeView.setSelection(type);
        amountView.setText(amount.toString());

        builder.setNeutralButton(getString(R.string.delete_budget_item_yes),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.vibrate(100);
                        budget.budgetItems.remove(currentIndex);
                        budget.saveBudgetItems();
                        updateBudgetItems();
                        dialog.dismiss();
                    }

                });
        builder.setPositiveButton(R.string.update_budget_item, null);
    }

    builder.setNegativeButton(getString(R.string.delete_budget_item_no), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    /* onClick listener for update needs to be setup like this to
       prevent closing dialog on error
     */

    final AlertDialog d = builder.create();
    d.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
            assert b != null;
            b.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    BigDecimal amount;
                    try {
                        amount = new BigDecimal(amountView.getText().toString());
                        if (typeView.getSelectedItemId() == 0)
                            amount = amount.negate();
                    } catch (NumberFormatException e) {

                        Toast.makeText(activity.getApplicationContext(),
                                getString(R.string.new_budget_item_no_amount_specified), Toast.LENGTH_SHORT)
                                .show();

                        return;
                    }

                    String title = titleView.getText().toString();

                    if (budgetItem != null) {
                        budgetItem.amount = amount;
                        budgetItem.title = title;
                    } else {
                        budget.budgetItems.add(new BudgetItem(title, amount));
                    }

                    budget.saveBudgetItems();
                    updateBudgetItems();
                    d.dismiss();
                }
            });
        }
    });

    d.setView(dialogView);
    d.show();
}

From source file:com.cubeia.backoffice.accounting.core.entity.Transaction.java

private void ensureEntrySumIsZero(Entry[] entries) throws TransactionNotBalancedException {
    //BigDecimal sum = BigDecimal.ZERO;
    Map<String, BigDecimal> sums = new HashMap<String, BigDecimal>(2);
    for (Entry e : entries) {
        //sum = sum.add(e.getAmount());
        Account a = e.getAccount();//from www.  j a  v a 2  s. co m
        String curr = a.getCurrencyCode();
        BigDecimal sum = sums.get(curr);
        if (sum == null) {
            sum = BigDecimal.ZERO;
        }
        sums.put(curr, sum.add(e.getAmount()));
    }

    for (String curr : sums.keySet()) {
        BigDecimal sum = sums.get(curr);
        if (sum.signum() != 0) {
            throw new TransactionNotBalancedException("Transaction balance is not zero for currency '" + curr
                    + "', sum = " + sum + ". Entries: " + Arrays.toString(entries));
        }
    }
}

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

private BigDecimal calculateLeftFor(BigDecimal sumOfProportions) {
    BigDecimal left = BigDecimal.ONE.subtract(sumOfProportions);
    left = left.signum() <= 0 ? BigDecimal.ZERO : left;

    return left;//  w  ww .  j  av a 2 s .c o  m
}

From source file:net.sourceforge.fenixedu.domain.mobility.outbound.OutboundMobilityCandidacyContestGroup.java

@Atomic
public void selectCandidates(final OutboundMobilityCandidacyPeriod period) {
    for (final OutboundMobilityCandidacyContest contest : getOutboundMobilityCandidacyContestSet()) {
        if (contest.getOutboundMobilityCandidacyPeriod() == period) {
            for (final OutboundMobilityCandidacy candidacy : contest.getOutboundMobilityCandidacySet()) {
                final OutboundMobilityCandidacySubmission submission = candidacy
                        .getSubmissionFromSelectedCandidacy();
                if (submission != null) {
                    candidacy.unselect();
                }//from w ww.  j  ava  2s  .c o  m
            }
        }
    }

    final SortedSet<OutboundMobilityCandidacySubmissionGrade> grades = new TreeSet<OutboundMobilityCandidacySubmissionGrade>();
    collectGradesForGroup(grades, period);

    for (final OutboundMobilityCandidacyContestGroup otherGroup : getRootDomainObject()
            .getOutboundMobilityCandidacyContestGroupSet()) {
        if (otherGroup != this && intersect(otherGroup)) {
            otherGroup.collectGradesForGroup(grades, period);
        }
    }

    for (final OutboundMobilityCandidacySubmissionGrade submissionGrade : grades) {
        logger.info("Selecting for: " + submissionGrade.getOutboundMobilityCandidacySubmission()
                .getRegistration().getPerson().getUsername());
        final BigDecimal grade = submissionGrade.getGrade();
        if (grade.signum() == 1) {
            submissionGrade.getOutboundMobilityCandidacySubmission().select();
        }
    }
}

From source file:org.openvpms.hl7.impl.RDSProcessor.java

/**
 * Adds an order item./*w  ww . ja  v a2 s . com*/
 *
 * @param group the order group
 * @param state the state
 */
private void addItem(RDS_O13_ORDER group, State state) {
    BigDecimal quantity = getQuantity(group);
    ActBean bean;
    ActBean itemBean;
    if (quantity.signum() >= 0) {
        bean = state.getOrder();
        itemBean = state.createOrderItem();
    } else {
        bean = state.getReturn();
        itemBean = state.createReturnItem();
        quantity = quantity.abs();
    }

    String fillerOrderNumber = group.getORC().getFillerOrderNumber().getEntityIdentifier().getValue();
    if (fillerOrderNumber != null) {
        itemBean.setValue("reference", fillerOrderNumber);
    }
    FinancialAct invoiceItem = addInvoiceItem(group.getORC(), bean, itemBean, state);
    addClinician(group, bean, itemBean, invoiceItem);
    Product product = addProduct(group, bean, itemBean);
    if (product != null) {
        checkSellingUnits(group, bean, product);
    }
    itemBean.setValue("quantity", quantity);
}