Example usage for java.math BigDecimal ZERO

List of usage examples for java.math BigDecimal ZERO

Introduction

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

Prototype

BigDecimal ZERO

To view the source code for java.math BigDecimal ZERO.

Click Source Link

Document

The value 0, with a scale of 0.

Usage

From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSF424V1_2Generator.java

private BigDecimal getTotalProjectIncome(BudgetContract budget) {
    BigDecimal totalProjectIncome = BigDecimal.ZERO;
    for (BudgetProjectIncomeContract budgetProjectIncome : budget.getBudgetProjectIncomes()) {
        totalProjectIncome = totalProjectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
    }/*from  w  w  w.  j a v a2 s . c o m*/
    return totalProjectIncome;
}

From source file:uk.dsxt.voting.client.web.MockVotingApiResource.java

License:asdf

@POST
@Path("/getAllClientVotes")
@Produces("application/json")
public RequestResult getAllClientVotes(@FormParam("cookie") String cookie,
        @FormParam("votingId") String votingId) {
    final VoteResultWeb[] results = new VoteResultWeb[10];

    results[0] = new VoteResultWeb(votingId, "Voting Name 2016", "client_1", "Dr. Watson", BigDecimal.TEN,
            VoteResultStatus.OK, "message_1");
    results[1] = new VoteResultWeb(votingId, "Voting Name 2016", "client_2", "Mr. Drow", BigDecimal.ONE,
            VoteResultStatus.OK, "message_2");
    results[2] = new VoteResultWeb(votingId, "Voting Name 2016", "client_3", "Mrs. Smith", BigDecimal.ZERO,
            VoteResultStatus.SignatureFailed, "message_3");
    results[3] = new VoteResultWeb(votingId, "Voting Name 2016", "client_4", "Mr. Zuba", BigDecimal.ZERO,
            VoteResultStatus.OK, "message_4");
    results[4] = new VoteResultWeb(votingId, "Voting Name 2016", "client_5", "Mr. Lenin",
            new BigDecimal(24324234), VoteResultStatus.SignatureFailed, "message_5");
    results[5] = new VoteResultWeb(votingId, "Voting Name 2016", "client_6", "Mr. Kak", BigDecimal.ONE,
            VoteResultStatus.OK, "message_6");
    results[6] = new VoteResultWeb(votingId, "Voting Name 2016", "client_7", "Mrs. Drow", BigDecimal.ZERO,
            VoteResultStatus.SignatureFailed, "message_7");
    results[7] = new VoteResultWeb(votingId, "Voting Name 2016", "client_8", "Mr. Smith", BigDecimal.ZERO,
            VoteResultStatus.OK, "message_8");
    results[8] = new VoteResultWeb(votingId, "Voting Name 2016", "client_9", "Mr. Stalin",
            new BigDecimal(6435674), VoteResultStatus.SignatureFailed, "message_9");
    results[9] = new VoteResultWeb(votingId, "Voting Name 2016", "client_10", "Mr. Kalinin",
            new BigDecimal(5632626), VoteResultStatus.OK, "message_10");

    return new RequestResult<>(results, null);
}

From source file:com.teamj.distribuidas.web.ExcursionUserBean.java

public void unselectDisabledRow(UnselectEvent e) {
    //        this.subtotal = new BigDecimal(BigInteger.ZERO);
    ExcursionArticulo ea = (ExcursionArticulo) e.getObject();
    if (ea.getArticulo().getDescripcion() != null
            && ea.getArticulo().getDescripcion().equals(String.valueOf(excursionSelected.getId()))) {
        this.derechoExcursionSeleccionada = BigDecimal.ZERO;
    } else {/*from  w w w .  j  a  v  a 2s .c  o  m*/
        this.subtotal = this.subtotal
                .add(ea.getArticulo().getPrecio().multiply(new BigDecimal(ea.getCantidad())).negate());
    }
}

From source file:com.axelor.studio.service.builder.ModelBuilderService.java

/**
 * Method to process decimal type of field for default,min,max attributes
 * and append it to field xml./*from   w w w  .  j  av  a 2 s  .c om*/
 * 
 * @param field
 *            MetaField to process
 */
private void addDecimal(StringBuilder fieldXml, MetaField field) {

    BigDecimal max = field.getDecimalMax();
    if (max != null && max.compareTo(BigDecimal.ZERO) != 0) {
        fieldXml.append("max=\"" + max + "\" ");
    }

    BigDecimal min = field.getDecimalMin();
    if (min != null && min.compareTo(BigDecimal.ZERO) != 0) {
        fieldXml.append("min=\"" + min + "\" ");
    }

    BigDecimal defaultDecimal = field.getDefaultDecimal();
    if (defaultDecimal != null && defaultDecimal.compareTo(BigDecimal.ZERO) != 0) {
        fieldXml.append("default=\"" + defaultDecimal + "\" ");
    }

}

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

public BigDecimal getPriorInvTotalUnPaidAmount() {
    BigDecimal amount = BigDecimal.ZERO;
    if (!ArrayUtils.isEmpty(priorInvs)) {
        for (int i = 0; i < priorInvs.length; i++) {
            if ("N".equals(priorInvs[i].getPaidIndicator())) {
                amount = amount.add(priorInvs[i].getAmount());
            }/* w w w  .j  ava  2 s  .c  om*/
        }
    }
    return amount;
}

From source file:org.openvpms.archetype.rules.finance.till.TillRulesTestCase.java

/**
 * Tests the {@link TillRules#startClearTill} method folli, with a zero cash float.
 * This should not create an <em>act.tillBalanceAdjustment</e>.
 *///from  w  w  w  .  j a v  a  2 s .c  o m
@Test
public void testStartClearTillWithNoAdjustment() {
    final BigDecimal cashFloat = BigDecimal.ZERO;
    checkStartClearTill(cashFloat, cashFloat);
}

From source file:com.osafe.services.OsafePayPalServices.java

public static Map<String, Object> payPalCheckoutUpdate(DispatchContext dctx, Map<String, Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    HttpServletRequest request = (HttpServletRequest) context.get("request");
    HttpServletResponse response = (HttpServletResponse) context.get("response");

    Map<String, Object> paramMap = UtilHttp.getParameterMap(request);

    String token = (String) paramMap.get("TOKEN");
    WeakReference<ShoppingCart> weakCart = tokenCartMap.get(new TokenWrapper(token));
    ShoppingCart cart = null;/*from w ww .j a v  a  2s.  c  o  m*/
    if (weakCart != null) {
        cart = weakCart.get();
    }
    if (cart == null) {
        Debug.logError("Could locate the ShoppingCart for token " + token, module);
        return ServiceUtil.returnSuccess();
    }
    // Since most if not all of the shipping estimate codes requires a persisted contactMechId we'll create one and
    // then delete once we're done, now is not the time to worry about updating everything
    String contactMechId = null;
    Map<String, Object> inMap = FastMap.newInstance();
    inMap.put("address1", paramMap.get("SHIPTOSTREET"));
    inMap.put("address2", paramMap.get("SHIPTOSTREET2"));
    inMap.put("city", paramMap.get("SHIPTOCITY"));
    String countryGeoCode = (String) paramMap.get("SHIPTOCOUNTRY");
    String countryGeoId = OsafePayPalServices.getCountryGeoIdFromGeoCode(countryGeoCode, delegator);
    if (countryGeoId == null) {
        return ServiceUtil.returnSuccess();
    }
    inMap.put("countryGeoId", countryGeoId);
    inMap.put("stateProvinceGeoId",
            parseStateProvinceGeoId((String) paramMap.get("SHIPTOSTATE"), countryGeoId, delegator));
    inMap.put("postalCode", paramMap.get("SHIPTOZIP"));

    try {
        GenericValue userLogin = delegator.findOne("UserLogin", true, UtilMisc.toMap("userLoginId", "system"));
        inMap.put("userLogin", userLogin);
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }
    boolean beganTransaction = false;
    Transaction parentTransaction = null;
    try {
        parentTransaction = TransactionUtil.suspend();
        beganTransaction = TransactionUtil.begin();
    } catch (GenericTransactionException e1) {
        Debug.logError(e1, module);
    }
    try {
        Map<String, Object> outMap = dispatcher.runSync("createPostalAddress", inMap);
        contactMechId = (String) outMap.get("contactMechId");
    } catch (GenericServiceException e) {
        Debug.logError(e.getMessage(), module);
        return ServiceUtil.returnSuccess();
    }
    try {
        TransactionUtil.commit(beganTransaction);
        if (parentTransaction != null)
            TransactionUtil.resume(parentTransaction);
    } catch (GenericTransactionException e) {
        Debug.logError(e, module);
    }
    // clone the cart so we can modify it temporarily
    CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart);
    String oldShipAddress = cart.getShippingContactMechId();
    coh.setCheckOutShippingAddress(contactMechId);
    ShippingEstimateWrapper estWrapper = new ShippingEstimateWrapper(dispatcher, cart, 0);
    int line = 0;
    NVPEncoder encoder = new NVPEncoder();
    encoder.add("METHOD", "CallbackResponse");

    for (GenericValue shipMethod : estWrapper.getShippingMethods()) {
        BigDecimal estimate = estWrapper.getShippingEstimate(shipMethod);
        //Check that we have a valid estimate (allowing zero value estimates for now)
        if (estimate == null || estimate.compareTo(BigDecimal.ZERO) < 0) {
            continue;
        }
        cart.setShipmentMethodTypeId(shipMethod.getString("shipmentMethodTypeId"));
        cart.setCarrierPartyId(shipMethod.getString("partyId"));
        try {
            coh.calcAndAddTax();
        } catch (GeneralException e) {
            Debug.logError(e, module);
            continue;
        }
        String estimateLabel = shipMethod.getString("partyId") + " - " + shipMethod.getString("description");
        encoder.add("L_SHIPINGPOPTIONLABEL" + line, estimateLabel);
        encoder.add("L_SHIPPINGOPTIONAMOUNT" + line,
                estimate.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
        // Just make this first one default for now
        encoder.add("L_SHIPPINGOPTIONISDEFAULT" + line, line == 0 ? "true" : "false");
        encoder.add("L_TAXAMT" + line,
                cart.getTotalSalesTax().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
        line++;
    }
    String responseMsg = null;
    try {
        responseMsg = encoder.encode();
    } catch (PayPalException e) {
        Debug.logError(e, module);
    }
    if (responseMsg != null) {
        try {
            response.setContentLength(responseMsg.getBytes("UTF-8").length);
        } catch (UnsupportedEncodingException e) {
            Debug.logError(e, module);
        }

        try {
            Writer writer = response.getWriter();
            writer.write(responseMsg);
            writer.close();
        } catch (IOException e) {
            Debug.logError(e, module);
        }
    }

    // Remove the temporary ship address
    try {
        GenericValue postalAddress = delegator.findOne("PostalAddress", false,
                UtilMisc.toMap("contactMechId", contactMechId));
        postalAddress.remove();
        GenericValue contactMech = delegator.findOne("ContactMech", false,
                UtilMisc.toMap("contactMechId", contactMechId));
        contactMech.remove();
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }
    coh.setCheckOutShippingAddress(oldShipAddress);
    return ServiceUtil.returnSuccess();
}

From source file:com.hengyi.japp.print.client.controller.MdController.java

@FXML
private void handleAutoXd() {
    try {//from   www  .  j a va 2 s . c  om
        MdValidate.checkMdInput(md);
        md.xdsProperty().clear();
        md.setXds(FXCollections.observableArrayList(IntStream.range(0, md.getZcanmge()).mapToObj(i -> {
            Xd xd = new Xd();
            xd.zboxsnrProperty().set(i + 1);
            xd.sapYmmmachProperty().bind(md.sapYmmmachProperty());
            xd.zrolmgeProperty().bind(md.zrolmgeProperty());
            return xd;
        }).collect(Collectors.toList())));
        if (md.getZdzflg()) {
            zsgwghtColumn.setEditable(false);
            md.getXds().forEach(xd -> {
                xd.zsnwghtProperty().bind(md.zcnwghtProperty());
                xd.zsgwghtProperty().bind(new ObjectBinding<BigDecimal>() {
                    {
                        bind(xd.zsnwghtProperty(), xd.zrolmgeProperty(), md.sapYmmzhixProperty(),
                                md.sapYmmtonggProperty());
                    }

                    @Override
                    protected BigDecimal computeValue() {
                        return xd.getZsnwght().add(tareF.apply(md, xd));
                    }
                });
            });
        } else {
            zsgwghtColumn.setEditable(true);
            md.getXds().forEach(xd -> {
                xd.zsnwghtProperty().bind(new ObjectBinding<BigDecimal>() {
                    {
                        bind(xd.zsgwghtProperty(), xd.zrolmgeProperty(), md.sapYmmzhixProperty(),
                                md.sapYmmtonggProperty());
                    }

                    @Override
                    protected BigDecimal computeValue() {
                        return xd.getZsgwght().add(tareF.apply(md, xd).negate());
                    }
                });
            });
        }
        md.zsgwghtProperty().bind(new ObjectBinding<BigDecimal>() {
            {
                md.getXds().forEach(xd -> bind(xd.zsgwghtProperty()));
            }

            @Override
            protected BigDecimal computeValue() {
                BigDecimal result = BigDecimal.ZERO;
                for (Xd xd : md.getXds()) {
                    result = result.add(xd.getZsgwght());
                }
                return result;
            }
        });
        md.zsnwghtProperty().bind(new ObjectBinding<BigDecimal>() {
            {
                md.getXds().forEach(xd -> bind(xd.zsnwghtProperty()));
            }

            @Override
            protected BigDecimal computeValue() {
                BigDecimal result = BigDecimal.ZERO;
                for (Xd xd : md.getXds()) {
                    result = result.add(xd.getZsnwght());
                }
                return result;
            }
        });
    } catch (AppException e) {
        Util.alertDialog(e);
    }
}

From source file:com.dm.estore.core.config.impl.InitDataLoaderImpl.java

private BigDecimal parseSafeDouble(final String value) {
    if (!StringUtils.isEmpty(value)) {
        try {/*w w  w  .  ja  v a2s.c  om*/
            return BigDecimal.valueOf(Double.parseDouble(value));
        } catch (Exception e) {
            // do nothing
        }
    }

    return BigDecimal.ZERO;
}

From source file:de.micromata.genome.util.runtime.ClassUtils.java

/**
 * Set all String field to empty on current class.
 *
 * @param object the object//ww  w  . ja v a 2  s.  co  m
 * @param exceptClass the except class
 * @throws IllegalArgumentException the illegal argument exception
 * @throws IllegalAccessException the illegal access exception
 */
// CHECKSTYLE.OFF com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck Trivial code.
public static void fillDefaultEmptyFieldsIfEmpty(Object object, Class<?>... exceptClass) // NOSONAR "Methods should not be too complex" trivial
        throws IllegalArgumentException, IllegalAccessException {
    Class<?> currentClazz = object.getClass();
    List exClazzes = Arrays.asList(exceptClass);
    while (currentClazz.getSuperclass() != null) {
        if (exClazzes.contains(currentClazz) == false) {
            Field[] fields = currentClazz.getDeclaredFields();
            for (Field field : fields) {
                if (String.class.equals(field.getType())) {
                    field.setAccessible(true);
                    if (field.get(object) == null) {
                        field.set(object, "");
                    }
                }
                if (Integer.class.equals(field.getType())) {
                    field.setAccessible(true);
                    if (field.get(object) == null) {
                        field.set(object, 0);
                    }
                }
                if (BigDecimal.class.equals(field.getType())) {
                    field.setAccessible(true);
                    if (field.get(object) == null) {
                        field.set(object, BigDecimal.ZERO);
                    }
                }
                if (Date.class.equals(field.getType())) {
                    field.setAccessible(true);
                    if (field.get(object) == null) {
                        field.set(object, new Date());
                    }
                }
            }
        }
        currentClazz = currentClazz.getSuperclass();
    }
}