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:ddf.catalog.validation.impl.validator.RangeValidator.java

/**
 * Creates a {@code RangeValidator} with an <strong>inclusive</strong> range and the provided
 * epsilon./*from   w w w  . j  a  v  a 2  s  .c  om*/
 * <p>
 * Uses the provided epsilon on both sides of the range to account for floating point
 * representation inaccuracies, so the range is really [min - epsilon, max + epsilon].
 *
 * @param min     the minimum allowable value (inclusive), cannot be null
 * @param max     the maximum allowable value (inclusive), cannot be null and must be greater
 *                than {@code min}
 * @param epsilon the epsilon value, cannot be null and must be positive
 * @throws IllegalArgumentException if {@code max} is not greater than {@code min},
 *                                  {@code epsilon} is not positive, or if any argument is null
 */
public RangeValidator(final BigDecimal min, final BigDecimal max, final BigDecimal epsilon) {
    Preconditions.checkArgument(min != null, "The minimum cannot be null.");
    Preconditions.checkArgument(max != null, "The maximum cannot be null.");
    Preconditions.checkArgument(epsilon != null, "The epsilon cannot be null.");
    Preconditions.checkArgument(min.compareTo(max) == -1, "The maximum must be greater than the minimum.");
    Preconditions.checkArgument(epsilon.compareTo(BigDecimal.ZERO) == 1, "The epsilon must be greater than 0.");

    this.min = min.subtract(epsilon);
    this.max = max.add(epsilon);
}

From source file:com.opensourcestrategies.financials.accounts.GLAccountInTree.java

/**
 * Gets the debit of this GL account children GL accounts.
 * @return a <code>BigDecimal</code> value
 *//*  w  ww.j  a  va 2  s.  com*/
public BigDecimal getDebitOfChildren() {
    BigDecimal debitOfChildren = BigDecimal.ZERO;
    for (GLAccountInTree childAccount : childAccounts) {
        debitOfChildren = debitOfChildren.add(getDebitOfChildrenRec(childAccount));
    }
    return debitOfChildren.setScale(AccountsHelper.decimals, AccountsHelper.rounding);
}

From source file:py.una.pol.karaku.test.test.math.QuantityTest.java

@Test
public void testConstructor() {

    assertQuantity(new Quantity(100000), bd("100000"));
    assertQuantity(new Quantity(10000000L), bd("10000000"));
    assertQuantity(new Quantity(new BigDecimal("100000000000000")), bd("100000000000000"));
    assertQuantity(new Quantity("0.00004"), bd("0.0000"));
    assertQuantity(new Quantity("0.00005"), bd("0.0001"));
    assertQuantity(new Quantity("0.00094"), bd("0.0009"));
    assertQuantity(new Quantity("0.00095"), bd("0.0010"));
    assertQuantity(new Quantity("100000"), bd("100000"));
    assertQuantity(new Quantity("200000"), bd("200000"));
    assertQuantity(new Quantity("100000.0004"), bd("100000.0004"));

    assertQuantity(new Quantity("3.53456"), bd("3.5346"));

    assertFalse(new Quantity().equals(BigDecimal.ZERO));
}

From source file:com.teamj.distribuidas.servicios.UsuarioServicio.java

public boolean guardarMochilaFactura(Integer user_id) throws ValidationException {
    Factura f = new Factura();
    f.setDocEmisor("0604133546001");
    f.setTipoDocEmisor("04");
    f.setClaveAcceso("xx");
    f.setFechaEmision(new Date());
    f.setDireccionEmisor("Quito, Sangolqui");
    f.setTipoDocReceptor("04");
    f.setTotal(BigDecimal.ZERO);
    f.setSubtotal(BigDecimal.ZERO);
    f.setDocReceptor(user_id.toString());
    f.setRazonSocial("Excursiones S.A");
    f.setSecuencial("000000000000000");
    try {//from   ww w  .j  av a  2 s .c  o  m
        this.facturaDAO.insert(f);
        return true;
    } catch (Exception ex) {
        throw new ValidationException(ex, "Error al crear la factura mochila");

    }
}

From source file:net.sf.reportengine.core.calc.TestCalculators.java

@Test
public void testUniversalAvgCalculator() {
    AvgGroupCalculator calculator = new AvgGroupCalculator();
    assertTrue(calculator.init() instanceof AvgCalcIntermResult);
    assertTrue(calculator.init().getResult() instanceof BigDecimal);
    assertEquals(calculator.init().getResult(), BigDecimal.ZERO);
    assertEquals(calculator.init().getCount(), 0);

    AvgCalcIntermResult<BigDecimal> testIntermResult = new AvgCalcIntermResult<BigDecimal>(BigDecimal.ZERO, 0);
    AvgCalcIntermResult<BigDecimal> newResult = calculator.compute(testIntermResult, "1");

    assertNotNull(newResult);//w w  w  . jav  a  2 s.c  o  m
    assertNotNull(newResult.getResult());
    assertEquals(newResult.getResult(), new BigDecimal(1));
    assertEquals(newResult.getCount(), 1);

    testIntermResult = newResult; //ie. result=1, count=1
    newResult = calculator.compute(testIntermResult, Integer.valueOf(7));

    assertNotNull(newResult);
    assertNotNull(newResult.getResult());
    assertEquals(newResult.getResult(), new BigDecimal(4));
    assertEquals(newResult.getCount(), 2);

    //reset
    testIntermResult = new AvgCalcIntermResult<BigDecimal>(BigDecimal.ZERO, 0);
    newResult = calculator.compute(testIntermResult, "1.1890");

    assertNotNull(newResult);
    assertNotNull(newResult.getResult());
    assertTrue(newResult.getResult().doubleValue() == 1.1890);

    testIntermResult = newResult;
    newResult = calculator.compute(testIntermResult, new Double(2.3));

    assertNotNull(newResult);
    assertNotNull(newResult.getResult());
    assertEquals(newResult.getResult().doubleValue(), 1.7445D, 0/*delta*/);
    assertEquals(newResult.getCount(), 2);

    testIntermResult = newResult;
    newResult = calculator.compute(testIntermResult, new Double(2.511));

    assertNotNull(newResult);
    assertNotNull(newResult.getResult());
    assertEquals(newResult.getResult().doubleValue(), 2.0, 0/*delta*/);
}

From source file:com.redhat.rhtracking.core.services.DeliveryMatrixServiceHandler.java

private Map<String, Object> initMap(String status) {
    Map<String, Object> row = new HashMap<>();
    row.put("status", status);
    row.put("opportunities", 0);
    row.put("totalHours", 0);
    row.put("amount", BigDecimal.ZERO);
    return row;// www .j  a v  a2  s. com
}

From source file:uk.dsxt.voting.client.datamodel.QuestionWeb.java

public QuestionWeb(Question q, VoteResult vr, boolean includeZeroAnswers) {
    this.id = q.getId();
    this.question = q.getQuestion();
    List<AnswerWeb> answers = new ArrayList<>();
    for (Answer answer : q.getAnswers()) {
        final String key = String.format("%s-%s", q.getId(), answer.getId());
        final VotedAnswer votedAnswer = vr.getAnswerByKey(key);
        if (votedAnswer != null && (votedAnswer.getVoteAmount().compareTo(BigDecimal.ZERO) > 0
                || (includeZeroAnswers && votedAnswer.getVoteAmount().compareTo(BigDecimal.ZERO) == 0))) {
            AnswerWeb answerWeb = new AnswerWeb(answer, votedAnswer.getVoteAmount());
            answers.add(answerWeb);//from   w w w. ja  v  a  2 s  .  com
        }
    }
    this.answers = answers.toArray(new AnswerWeb[answers.size()]);
    this.canSelectMultiple = q.isCanSelectMultiple();
    this.multiplicator = q.getMultiplicator();
}

From source file:com.opensky.osis.BraintreeConnector.java

/**
 * Clone a transaction//from   w ww  . j  a  v  a 2s. c o  m
 * 
 * TODO Should amount be optional?
 *
 * {@sample.xml ../../../doc/braintree-connector.xml.sample braintree:clone-transaction}
 *
 * @param originalTxId The original transaction id
 * @param amount The new amount to auth for
 * @param settle to settle or not
 * @return The transaction
 */
@Processor
public Result cloneTransaction(String originalTxId, BigDecimal amount,
        @Optional @Default(value = "false") Boolean settle) {
    log.info("Cloning transaction {} with amount {} settle {}", new Object[] { originalTxId, amount, settle });

    Validate.notNull(originalTxId, "Original transaction id must not be null");
    Validate.notNull(amount, "amount should not be null");
    Validate.isTrue(amount.compareTo(BigDecimal.ZERO) >= 0, "amount must be >= 0");

    TransactionCloneRequest txCloneReq = getRequestFactory().transactionCloneRequest().amount(amount).options()
            .submitForSettlement(settle).done();
    try {
        return getGateway().transaction().cloneTransaction(originalTxId, txCloneReq);
    } catch (BraintreeException e) {
        return new ExceptionResult(e.getClass().getCanonicalName());
    }
}

From source file:com.siapa.managedbean.DetalleCompraAlimentoManagedBean.java

public BigDecimal calcularTotal() {
    BigDecimal total1 = BigDecimal.ZERO;
    BigDecimal imp = BigDecimal.ZERO;
    if (detalleCompraAlimento != null && detalleCompraAlimento.getCantDetalleCompraAlimento() != null) {
        if (detalleCompraAlimento.getPrecioDetalleCompraAlimento() != null) {
            if (detalleCompraAlimento.getImpuestoDetCompraAlimento() != null) {

                total1 = total1.add((detalleCompraAlimento.getCantDetalleCompraAlimento()
                        .multiply(detalleCompraAlimento.getPrecioDetalleCompraAlimento()))
                                .multiply(detalleCompraAlimento.getImpuestoDetCompraAlimento()
                                        .divide(new BigDecimal(100)).add(new BigDecimal(1)))
                                .setScale(2, BigDecimal.ROUND_HALF_UP));
            }/* w w w. ja v a2 s  . co m*/
        }
    }
    return total1;
}

From source file:BlogRocksteady2.bean.EditPerfilBean.java

public void editarPerfil(ActionEvent event) throws IOException {
    BigDecimal user = (BigDecimal) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
            .get("user");
    if (user.compareTo(BigDecimal.ZERO) >= 1) {
        usuario = usuarioFacade.findById(user);
        usuario.setEmail(email);/* w w  w  .j a  v  a 2  s .c  o  m*/
        usuario.setDescription(description);
        usuario.setWebsite(website);
        usuario.setFacebook(facebook);
        usuario.setTwitter(twitter);
        usuario.setLinkedin(linkedin);
        usuario.setInstagram(instagram);
        if (foto != null) {
            InputStream inputStream = foto.getInputStream();
            byte[] imagen = IOUtils.toByteArray(inputStream);
            usuario.setImg(imagen);
        }
        usuarioFacade.edit(usuario);
        FacesMessage message = new FacesMessage("Perfil actualizado con xito");
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

}