Example usage for java.math BigDecimal ONE

List of usage examples for java.math BigDecimal ONE

Introduction

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

Prototype

BigDecimal ONE

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

Click Source Link

Document

The value 1, with a scale of 0.

Usage

From source file:io.curly.advisor.AdvisorApplication.java

@Bean
CommandLineRunner commandLineRunner(MongoTemplate mongoTemplate) {
    return args -> {
        String s = ObjectId.get().toHexString();
        System.out.println("--------------------------------->" + s);
        Review review = new Review("foo", "55b241c6608d54d2de26b891", String.valueOf(new Random(10).nextLong()),
                "foo", new UserInfo("foo", "url"), BigDecimal.ONE);
        try {//from w  ww . ja  v a  2  s  .c o  m
            mongoTemplate.save(review);
        } catch (DuplicateKeyException e) {
            System.out.println(e);
        }
    };
}

From source file:pe.gob.mef.gescon.hibernate.impl.UserDaoImpl.java

@Override
public List<Mtuser> getMtusersInternal() throws Exception {
    DetachedCriteria criteria = DetachedCriteria.forClass(Mtuser.class);
    criteria.add(Restrictions.eq("nuserinterno", BigDecimal.ONE));
    return (List<Mtuser>) getHibernateTemplate().findByCriteria(criteria);
}

From source file:org.fede.calculator.IndexTest.java

public void youIndexARS() {

    MoneyAmountSeries dollar = Util.readSeries("ahorros-dolar.json");
    MoneyAmountSeries gold = Util.readSeries("ahorros-oro.json");
    MoneyAmountSeries peso = Util.readSeries("ahorros-peso.json");

    final String target = "USD";

    MoneyAmountSeries proportionInUSD = new SortedMapMoneyAmountSeries("USD");

    YearMonth start = dollar.getFrom().min(gold.getFrom());

    final YearMonth end = dollar.getTo().max(gold.getTo());

    final MoneyAmount oneUSD = new MoneyAmount(BigDecimal.ONE, "USD");
    final MoneyAmount oneARS = getForeignExchange(oneUSD.getCurrency(), "ARS").exchange(oneUSD, "ARS",
            start.getYear(), start.getMonth());
    final MoneyAmount oneXAU = getForeignExchange(oneUSD.getCurrency(), "XAU").exchange(oneUSD, "XAU",
            start.getYear(), start.getMonth());

    while (start.compareTo(end) <= 0) {
        MoneyAmount usdSavings = dollar.getAmountOrElseZero(start);
        MoneyAmount arsSavings = peso.getAmountOrElseZero(start);
        MoneyAmount xauSavings = gold.getAmountOrElseZero(start);

        usdSavings = getForeignExchange(usdSavings.getCurrency(), target).exchange(usdSavings, target,
                start.getYear(), start.getMonth());
        xauSavings = getForeignExchange(xauSavings.getCurrency(), target).exchange(xauSavings, target,
                start.getYear(), start.getMonth());
        arsSavings = getForeignExchange(arsSavings.getCurrency(), target).exchange(arsSavings, target,
                start.getYear(), start.getMonth());

        final MoneyAmount totalSavings = usdSavings.add(xauSavings).add(arsSavings);

        if (totalSavings.getAmount().signum() > 0) {

            BigDecimal usdSavingsPercent = usdSavings.getAmount().divide(totalSavings.getAmount(),
                    MathContext.DECIMAL128);
            BigDecimal arsSavingsPercent = arsSavings.getAmount().divide(totalSavings.getAmount(),
                    MathContext.DECIMAL128);
            BigDecimal xauSavingsPercent = xauSavings.getAmount().divide(totalSavings.getAmount(),
                    MathContext.DECIMAL128);

            System.out.print(MessageFormat.format("{0}{1}\t{2}\t{3}\t{4}\t", String.valueOf(start.getYear()),
                    start.getMonth(), usdSavingsPercent, arsSavingsPercent, xauSavingsPercent));

            BigDecimal usdPrice = getForeignExchange(oneUSD.getCurrency(), target)
                    .exchange(oneUSD, target, start.getYear(), start.getMonth()).getAmount();
            BigDecimal arsPrice = getForeignExchange(oneARS.getCurrency(), target)
                    .exchange(oneARS, target, start.getYear(), start.getMonth()).getAmount();
            BigDecimal xauPrice = getForeignExchange(oneXAU.getCurrency(), target)
                    .exchange(oneXAU, target, start.getYear(), start.getMonth()).getAmount();

            System.out.print(MessageFormat.format("{0}\t{1}\t{2}\t", usdPrice, arsPrice, xauPrice));

            BigDecimal youIndex = usdPrice.multiply(usdSavingsPercent).add(arsPrice.multiply(arsSavingsPercent))
                    .add(xauPrice.multiply(xauSavingsPercent));

            // final MoneyAmount index = new MoneyAmount(youIndex, target);

            //BigDecimal adjustedYouIndex = USD_INFLATION.adjust(index, start.getYear(), start.getMonth(),
            //        USD_INFLATION.getTo().getYear(), USD_INFLATION.getTo().getMonth()).getAmount();

            // System.out.println(MessageFormat.format("{0}\t{1}", youIndex, adjustedYouIndex));

            proportionInUSD.putAmount(start, new MoneyAmount(youIndex, target));
        }/*from  w w w  .j a  va 2s .c  o  m*/
        start = start.next();
    }
    //proportionInUSD.forEach(new MoneyAmountProcessor() {
    //   @Override
    //  public void process(int year, int month, MoneyAmount amount) throws NoSeriesDataFoundException {
    //System.out.println(MessageFormat.format("{0}{1}\t{2}", String.valueOf(year), month, amount.getAmount()));
    //}
    //});
}

From source file:pe.gob.mef.gescon.hibernate.impl.MaestroDetalleDaoImpl.java

@Override
public List<Tmaestrodetalle> getDetallesActivosByMaestro(Mtmaestro mtmaestro) throws Exception {
    DetachedCriteria criteria = DetachedCriteria.forClass(Tmaestrodetalle.class);
    criteria.add(Restrictions.eq("nmaestroid", mtmaestro.getNmaestroid()));
    criteria.add(Restrictions.eq("nactivo", BigDecimal.ONE));
    criteria.addOrder(Order.asc("ndetalleid"));
    return (List<Tmaestrodetalle>) getHibernateTemplate().findByCriteria(criteria);
}

From source file:client.Pi.java

/**
 * Compute the value, in radians, of the arctangent of 
 * the inverse of the supplied integer to the specified
 * number of digits after the decimal point.  The value
 * is computed using the power series expansion for the
 * arc tangent:/*from   ww w . j  av a2s  .c o  m*/
 *
 * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + 
 *     (x^9)/9 ...
 */
public static BigDecimal arctan(int inverseX, int scale) {
    BigDecimal result, numer, term;
    BigDecimal invX = BigDecimal.valueOf(inverseX);
    BigDecimal invX2 = BigDecimal.valueOf(inverseX * inverseX);

    numer = BigDecimal.ONE.divide(invX, scale, roundingMode);

    result = numer;
    int i = 1;
    do {
        numer = numer.divide(invX2, scale, roundingMode);
        int denom = 2 * i + 1;
        term = numer.divide(BigDecimal.valueOf(denom), scale, roundingMode);
        if ((i % 2) != 0) {
            result = result.subtract(term);
        } else {
            result = result.add(term);
        }
        i++;
    } while (term.compareTo(BigDecimal.ZERO) != 0);
    return result;
}

From source file:com.coinblesk.server.service.UserAccountServiceTest.java

@Before
public void before() throws IOException, UnreadableWalletException, BlockStoreException, InterruptedException {
    System.setProperty("coinblesk.config.dir", "/tmp/lib/coinblesk" + (counter++));
    if (counter > 0) {
        walletService.init();//from  w ww.j  a v  a  2s . c om
    }

    UserAccount userAccount = new UserAccount();
    userAccount.setBalance(BigDecimal.ONE).setCreationDate(new Date(1)).setDeleted(false)
            .setEmail("test@test.test").setEmailToken(null).setPassword(passwordEncoder.encode("test"))
            .setUsername("blib");
    userAccountService.save(userAccount);

    Keys keys = keyService.storeKeysAndAddress(ecKeyClient.getPubKey(), ecKeyServer.getPubKey(),
            ecKeyServer.getPrivKeyBytes()).element1();

    TimeLockedAddress address = new TimeLockedAddress(ecKeyClient.getPubKey(), ecKeyServer.getPubKey(), 123456);

    keyService.storeTimeLockedAddress(keys, address);
}

From source file:org.openvpms.esci.adapter.AbstractESCITest.java

/**
 * Helper to create a POSTED order with a single item.
 *
 * @param supplier the supplier/*from w ww  .  ja va 2  s .  c om*/
 * @return a new order
 */
protected FinancialAct createOrder(Party supplier) {
    FinancialAct orderItem = createOrderItem(BigDecimal.ONE, 1, BigDecimal.ONE);
    ActBean itemBean = new ActBean(orderItem);
    itemBean.setValue("reorderCode", "AREORDERCODE");
    itemBean.setValue("reorderDescription", "A reorder description");
    FinancialAct order = createOrder(supplier, orderItem);
    order.setStatus(ActStatus.POSTED);
    save(order, orderItem);
    return order;
}

From source file:cz.muni.fi.pa165.legomanager.services.LegoSetServiceImplTest.java

public static LegoSetTO getValidSet() {

    LegoSetTO set = new LegoSetTO();
    set.setId(-1L);/*from  w ww .ja  va  2 s  .c o m*/
    set.setCategories(new HashSet());
    set.setLegoKits(new ArrayList());
    set.setName("Star Wars");
    set.setPrice(BigDecimal.ONE);
    return set;
}

From source file:pe.gob.mef.gescon.hibernate.impl.CategoriaDaoImpl.java

@Override
public List<Mtcategoria> getMtcategoriasPrimerNivel() throws Exception {
    DetachedCriteria criteria = DetachedCriteria.forClass(Mtcategoria.class);
    criteria.add(Restrictions.eq("nnivel", BigDecimal.ONE));
    criteria.add(Restrictions.eq("nestado", BigDecimal.ONE));
    criteria.addOrder(Order.asc("ncategoriaid"));
    return (List<Mtcategoria>) getHibernateTemplate().findByCriteria(criteria);
}

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

/**
 * Function to round up when the decimal part is more than a half, and down when its less than, if it is a half keep it
 *
 * @return fixed rate//from  w w  w  .  j a v  a 2s  .c  o  m
 */
public BigDecimal fixPrecision() {
    if (rate == null)
        return null;
    BigDecimal decimal = rate.remainder(BigDecimal.ONE);
    BigInteger integer = rate.toBigInteger();
    if (decimal.compareTo(new BigDecimal(0.5)) > 0) {
        rate = new BigDecimal(integer.add(new BigInteger("1")));
    } else if (decimal.compareTo(new BigDecimal(0.5)) < 0) {
        rate = new BigDecimal(integer);
    }
    return rate;
}