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:net.shopxx.service.impl.ShippingMethodServiceImpl.java

@Transactional(readOnly = true)
public BigDecimal calculateFreight(ShippingMethod shippingMethod, Area area, Integer weight) {
    Assert.notNull(shippingMethod);/*  w w w  .  ja  v  a2s .  c om*/

    Setting setting = SystemUtils.getSetting();
    BigDecimal firstPrice = shippingMethod.getDefaultFirstPrice();
    BigDecimal continuePrice = shippingMethod.getDefaultContinuePrice();
    if (area != null && CollectionUtils.isNotEmpty(shippingMethod.getFreightConfigs())) {
        List<Area> areas = new ArrayList<Area>();
        areas.addAll(area.getParents());
        areas.add(area);
        for (int i = areas.size() - 1; i >= 0; i--) {
            FreightConfig freightConfig = shippingMethod.getFreightConfig(areas.get(i));
            if (freightConfig != null) {
                firstPrice = freightConfig.getFirstPrice();
                continuePrice = freightConfig.getContinuePrice();
                break;
            }
        }
    }
    if (weight == null || weight <= shippingMethod.getFirstWeight()
            || continuePrice.compareTo(BigDecimal.ZERO) == 0) {
        return setting.setScale(firstPrice);
    } else {
        double contiuneWeightCount = Math
                .ceil((weight - shippingMethod.getFirstWeight()) / (double) shippingMethod.getContinueWeight());
        return setting.setScale(
                firstPrice.add(continuePrice.multiply(new BigDecimal(String.valueOf(contiuneWeightCount)))));
    }
}

From source file:io.curly.advisor.model.Review.java

private BigDecimal fixPrecision(BigDecimal rate) {
    if (rate == null)
        return BigDecimal.ZERO;
    BigDecimal decimal = rate.remainder(BigDecimal.ONE);
    BigInteger integer = rate.toBigInteger();
    if (decimal.compareTo(new BigDecimal(0.5)) > 0) {
        return new BigDecimal(integer.add(new BigInteger("1")));
    } else if (decimal.compareTo(new BigDecimal(0.5)) < 0) {
        return new BigDecimal(integer);
    }/*from www. ja  v  a  2 s.  co  m*/
    return rate;
}

From source file:cz.muni.fi.dndtroops.test.HeroDaoImplTest.java

@Test
public void testFindAllHeroes() throws ConnectionException {

    Hero heroF = new Hero();
    heroF.setName("Hero");
    heroF.setLevel(1);/*www.  j a  v  a 2  s . co m*/
    heroF.setRole(RoleName.BARD);
    Troop troopF = new Troop();
    troopF.setName("Angels");
    troopF.setMoney(BigDecimal.ZERO);
    troopF.setMission("mise A");
    heroF.setTroop(troopF);

    troopDao.createTroop(troopF);
    heroDao.createHero(heroF);
    List<Hero> list = heroDao.findAll();

    Assert.assertEquals(list.size(), 1);

    Assert.assertTrue(list.contains(heroF));
}

From source file:lu.lippmann.cdb.graph.renderer.CadralEdgeColorTransformer.java

/**
 * /*www.  j av a 2s. c  om*/
 * @param color1
 * @param color2
 * @param nb
 * @return
 */
private List<Color> getColorList() {

    final List<Color> res = new ArrayList<Color>();

    for (int i = 0; i < nbColors; i++) {
        res.add(rangeColor(color1, color2, BigDecimal.valueOf(i), BigDecimal.ZERO,
                BigDecimal.valueOf(nbColors)));
    }
    return res;
}

From source file:com.oreilly.springdata.gemfire.core.Product.java

/**
 * Creates a new {@link Product} from the given name and description.
 * @param id a unique Id//from  w w w . j  a v  a2 s  .  co m
 * @param name must not be {@literal null} or empty.
 * @param price must not be {@literal null} or less than or equal to zero.
 * @param description
 */
@PersistenceConstructor
public Product(Long id, String name, BigDecimal price, String description) {
    super(id);
    Assert.hasText(name, "Name must not be null or empty!");
    Assert.isTrue(BigDecimal.ZERO.compareTo(price) < 0, "Price must be greater than zero!");

    this.name = name;
    this.price = price;
    this.description = description;
}

From source file:com.haulmont.cuba.gui.components.validators.DoubleValidator.java

private boolean checkBigDecimalOnPositive(BigDecimal value) {
    return !ObjectUtils.equals("true", onlyPositive) || value.compareTo(BigDecimal.ZERO) >= 0;
}

From source file:org.openvpms.archetype.tools.account.AccountBalanceToolTestCase.java

/**
 * Tests generation given a customer id.
 *//*from   w  w  w.j  av a  2 s  .  com*/
@Test
public void testGenerateForCustomerId() {
    Party customer = getCustomer();
    long id = customer.getId();
    Money amount = new Money(100);
    FinancialAct debit = createInitialBalance(amount);
    save(debit);

    checkEquals(BigDecimal.ZERO, rules.getBalance(customer));
    assertFalse(tool.check(id));

    tool.generate(id);
    checkEquals(amount, rules.getBalance(customer));
    FinancialAct credit = createBadDebt(amount);
    save(credit);
    tool.generate(id);
    checkEquals(BigDecimal.ZERO, rules.getBalance(customer));
    assertTrue(tool.check(id));
}

From source file:org.springsource.restbucks.training.core.MonetaryAmount.java

/**
 * No-arg constructor to satisfy persistence mechanism.
 */
protected MonetaryAmount() {
    this(EURO, BigDecimal.ZERO);
}

From source file:de.olivergierke.whoops.app.JavaConfigTest.java

@Test
public void vmWareEquitiesIsFree() {

    Deal deal = new Deal(new Equity("VMware"));
    Result result = processor.process(deal);

    assertThat(result.getFee(), is(BigDecimal.ZERO));
}

From source file:ch.cyberduck.cli.TerminalStreamListener.java

private void increment() {
    final TransferProgress progress = meter.getStatus();
    if (System.currentTimeMillis() - timestamp.get() < 100L) {
        if (!progress.isComplete()) {
            return;
        }/*from   w  w  w .  j av  a 2 s  .  c  om*/
    }
    try {
        lock.acquire();
        final BigDecimal fraction;
        if (progress.getTransferred() == 0L) {
            fraction = BigDecimal.ZERO;
        } else {
            fraction = new BigDecimal(progress.getTransferred()).divide(new BigDecimal(progress.getSize()), 1,
                    RoundingMode.DOWN);
        }
        console.printf("\r%s[",
                Ansi.ansi().saveCursorPosition().eraseLine(Ansi.Erase.ALL).restoreCursorPosition());
        int i = 0;
        for (; i <= (int) (fraction.doubleValue() * width); i++) {
            console.printf("\u25AE");
        }
        for (; i < width; i++) {
            console.printf(StringUtils.SPACE);
        }
        console.printf("] %s%s", progress.getProgress(), Ansi.ansi().reset());
        timestamp.set(System.currentTimeMillis());
    } catch (InterruptedException e) {
        //
    } finally {
        lock.release();
    }
}