Example usage for java.math BigDecimal BigDecimal

List of usage examples for java.math BigDecimal BigDecimal

Introduction

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

Prototype

public BigDecimal(long val) 

Source Link

Document

Translates a long into a BigDecimal .

Usage

From source file:be.ceau.chart.datapoint.BubbleDataPoint.java

/**
 * X Value/*  w w w .  j a  v  a  2s.  c  o  m*/
 */
public BubbleDataPoint setX(int x) {
    this.x = new BigDecimal(x);
    return this;
}

From source file:com.espertech.esper.epl.agg.aggregator.AggregatorAvgBigDecimal.java

public void enter(Object object) {
    if (object == null) {
        return;//from  ww w  . j  a va2 s . c  o  m
    }
    numDataPoints++;
    if (object instanceof BigInteger) {
        sum = sum.add(new BigDecimal((BigInteger) object));
        return;
    }
    sum = sum.add((BigDecimal) object);
}

From source file:com.impetus.kundera.utils.NumericUtils.java

/**
 *  Check if zero//  w  w w  . j  ava 2s. com
 * @param value        value string
 * @param valueClazz   value class 
 * @return             
 */
public static final boolean checkIfZero(String value, Class valueClazz) {
    boolean returnValue = false;
    if (value != null && NumberUtils.isNumber(value) && numberTypes.get(valueClazz) != null) {
        switch (numberTypes.get(valueClazz)) {

        case INTEGER:
            returnValue = Integer.parseInt(value) == (NumberUtils.INTEGER_ZERO);
            break;

        case FLOAT:
            returnValue = Float.parseFloat(value) == (NumberUtils.FLOAT_ZERO);
            break;

        case LONG:
            returnValue = Long.parseLong(value) == (NumberUtils.LONG_ZERO);
            break;

        case BIGDECIMAL:
            returnValue = new BigDecimal(value) == (BigDecimal.ZERO);
            break;

        case BIGINTEGER:
            returnValue = new BigInteger(value) == (BigInteger.ZERO);
            break;

        case SHORT:
            returnValue = new Short(value) == (NumberUtils.SHORT_ZERO);
            break;
        }
    }

    return returnValue;
}

From source file:com.opengamma.engine.position.csv.CSVPositionSourceTest.java

public void parseLineOneIdentifier() {
    Position position = CSVPositionSource.parseLine(new String[] { "98.4", "KIRK", "MY-ID" }, UID);
    assertNotNull(position);//from   w w  w.ja v  a 2  s  .c  om

    assertEquals(UID, position.getUniqueId());

    assertNotNull(position.getQuantity());
    assertEquals(0, new BigDecimal(984).scaleByPowerOfTen(-1).compareTo(position.getQuantity()));

    assertEquals(1, position.getSecurityLink().getExternalId().size());
    ExternalId id = position.getSecurityLink().getExternalId().iterator().next();
    assertNotNull(id);
    assertNotNull(id.getScheme());
    assertEquals("KIRK", id.getScheme().getName());
    assertNotNull(id.getValue());
    assertEquals("MY-ID", id.getValue());
}

From source file:nz.gate5a.schoolstories.importer.NceaQualificationCreator.java

private BigDecimal bigDecimal(String value) {
    try {// ww w  .j a  v a  2s . c o m
        if (StringUtils.isEmpty(value)) {
            return null;
        }
        return new BigDecimal(value);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(value);
    }
}

From source file:com.mycompany.vendingmachinev2.dao.VendingDaoImplTest.java

/**
 * Test of findItemByCode method, of class VendingDaoImpl.
 *///from   www  .j a  v  a2  s. co  m
@Test
public void testFindItemByCode() {
    System.out.println("findItemByCode");
    String itemCode = "A1";
    VendingDaoImpl instance = new VendingDaoImpl();
    Item expResult = new Item("Snickers", new BigDecimal(1.00), 10, "A1");
    instance.addItem(expResult);
    Item result = instance.findItemByCode(itemCode);
    assertEquals(expResult, result);
}

From source file:CommonServlets.EditUser.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String email = null, userName = null, job = null, address = null, password = null, img = null, role = null;
    BigDecimal creditLimit = new BigDecimal(0);

    try {//  www  .  j  av a2 s  .  c o  m
        // Create a factory for disk-based file items
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        // Parse the request
        List<FileItem> items = upload.parseRequest(request);
        Iterator<FileItem> iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = iter.next();
            if (item.isFormField()) {
                //processFormField(item);
                String name = item.getFieldName();
                String value = item.getString();

                if (name.equalsIgnoreCase("email")) {
                    email = value;
                } else if (name.equalsIgnoreCase("userName")) {
                    userName = value;
                } else if (name.equalsIgnoreCase("creditLimit")) {
                    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
                    symbols.setGroupingSeparator(',');
                    symbols.setDecimalSeparator('.');
                    String pattern = "#,##0.0#";
                    DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
                    decimalFormat.setParseBigDecimal(true);
                    creditLimit = (BigDecimal) decimalFormat.parse(value);
                } else if (name.equalsIgnoreCase("job")) {
                    job = value;

                } else if (name.equalsIgnoreCase("address")) {
                    address = value;
                } else if (name.equalsIgnoreCase("password")) {
                    password = value;
                }
            } else if (!item.isFormField() && !item.getName().equals("")) {
                System.out.println(new File(AddProduct.class.getClassLoader().getResource("").getPath()
                        .replace("%20", " ")
                        .substring(0, AddProduct.class.getClassLoader().getResource("").getPath()
                                .replace("%20", " ").length() - 27)
                        + "/web/Resources/users_pics/" + item.getName()));
                item.write(new File(AddProduct.class.getClassLoader().getResource("").getPath()
                        .replace("%20", " ")
                        .substring(0, AddProduct.class.getClassLoader().getResource("").getPath()
                                .replace("%20", " ").length() - 27)
                        + "/web/Resources/users_pics/" + item.getName()));
                img = item.getName();
            }
        }

        User u = new User(email, userName, password, creditLimit, job, address, img, role);
        controlServlet.editUserDate(u);
        HttpSession session = request.getSession(true);
        session.setAttribute("done", "1");
        ControlServlet c = new ControlServlet();
        User myUser = c.getUser(userName);
        session.setAttribute("user", myUser);
        response.sendRedirect("UserHome.jsp");

    } catch (Exception ex) {
        Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:no.dusken.annonseweb.service.ServiceIntegrationTest.java

@Test
public void testSave() {

    Ad ad = new PrintedAd(new BigDecimal("100"), new BigDecimal("10"));
    Customer customer = new Customer("customer", "mail@mail.mail", "12345678", "address");
    // I save customer first, since at least first version of this program should not save more than one entity at a time
    customerService.saveAndFlush(customer);
    AnnonsePerson createdUser = getPerson();

    Sale s = new Sale("description", null, customer, null, false, false);
    ;//from ww  w. ja  v a 2s  .c  om
    ad.setSale(s);
    Sale sale = salesService.saveAndFlush(s);

    assertNotNull(sale);
    assertNotNull(sale.getId());
    //assertEquals(ad, sale.getAds().get(0));
    assertEquals(customer, sale.getCustomer());

}

From source file:org.impotch.calcul.impot.federal.dao.BaremeIFDPersonnePhysiqueTest.java

@Test
public void postNumerandoCelibataire2006() {
    Bareme bareme = fournisseur.getBaremeImpotRevenuPersonnePhysiquePourPersonneSeule(2006);
    assertEquals("Revenu de 10000", new BigDecimal("0.00"), bareme.calcul(new BigDecimal("10000")));
    assertEquals("Revenu de 16800", new BigDecimal("0.00"), bareme.calcul(new BigDecimal("16800")));
    assertEquals("Revenu de 16900", new BigDecimal("25.40"), bareme.calcul(new BigDecimal("16900")));
    assertEquals("Revenu de 23000", new BigDecimal("72.35"), bareme.calcul(new BigDecimal("23000")));
    assertEquals("Revenu de 29800", new BigDecimal("124.70"), bareme.calcul(new BigDecimal("29800")));
    assertEquals("Revenu de 35000", new BigDecimal("170.45"), bareme.calcul(new BigDecimal("35000")));
    assertEquals("Revenu de 117000", new BigDecimal("4636.75"), bareme.calcul(new BigDecimal("117000")));
    assertEquals("Revenu de 127100", new BigDecimal("5525.55"), bareme.calcul(new BigDecimal("127100")));
    assertEquals("Revenu de 200000", new BigDecimal("14288.15"), bareme.calcul(new BigDecimal("200000")));
    assertEquals("Revenu de 750000", new BigDecimal("86250.00"), bareme.calcul(new BigDecimal("750000")));
    assertEquals("Revenu de 843600", new BigDecimal("97014.00"), bareme.calcul(new BigDecimal("843600")));
}

From source file:br.com.artesuzana.app.DataGenerator.java

public static void generate() {

    try {//from   ww w  . j av  a2  s.  c om
        new HibernateUtil().iniciarSessionFactory();

        // if (true) return;
        final IProductRepository prdRepo = ApplicationContext.get().getBean(IProductRepository.class);
        final ICategoryRepository catRepo = ApplicationContext.get().getBean(ICategoryRepository.class);
        final IUserRepository userRepo = ApplicationContext.get().getBean(IUserRepository.class);

        if (catRepo.list().isEmpty()) {

            final Category madeira = new Category("Madeira");
            final Category bolsa = new Category("Bolsa");
            final Category sabonete = new Category("Sabonete");
            final Category bisquit = new Category("Bisquit");
            final Category tecido = new Category("Tecido");
            final Category especial = new Category("Especial");
            final Category roupa = new Category("Roupa");
            final Category toalha = new Category("Toalha");

            catRepo.save(madeira);
            catRepo.save(bolsa);
            catRepo.save(sabonete);
            catRepo.save(bisquit);
            catRepo.save(tecido);
            catRepo.save(especial);
            catRepo.save(roupa);
            catRepo.save(toalha);

            final Product portaBijuteria = new Product();
            portaBijuteria.setName("Porta Bijuteria Aveludado");
            portaBijuteria.setPrice(new BigDecimal(30));
            portaBijuteria.setDescription("Porta bijuterias com divisrias com fundos e lados aveludados");
            portaBijuteria.setCategory(madeira);

            final Transacao transacao = new Transacao();
            transacao.begin();

            final ProductImage imgPortaBijuteria = new ProductImage();
            imgPortaBijuteria.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-bijuteria.jpeg")));

            final ProductImage imgPortaBijuteria2 = new ProductImage();
            imgPortaBijuteria2.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-bijuteria2.jpeg")));

            final ProductImage imgPortaBijuteria3 = new ProductImage();
            imgPortaBijuteria3.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-bijuteria3.jpeg")));

            final Product bolsaDiagonal = new Product();
            bolsaDiagonal.setName("Bolsa Diagonal");
            bolsaDiagonal.setPrice(new BigDecimal(55));
            bolsaDiagonal
                    .setDescription("Bolsa feita em tecido de qualidade com faixa diagonal em grande estilo");
            bolsaDiagonal.setCategory(bolsa);

            final ProductImage imgBolsaDiagonal = new ProductImage();
            imgBolsaDiagonal.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/bolsa-diagonal.jpeg")));

            final Product bolsaPrimavera = new Product();
            bolsaPrimavera.setName("Bolsa Primavera");
            bolsaPrimavera.setPrice(new BigDecimal(65));
            bolsaPrimavera.setDescription(
                    "Bolsa que deixar qualquer mulher mais atraente em qualquer poca do ano, inclusive na Primavera");
            bolsaPrimavera.setCategory(bolsa);

            final ProductImage imgBolsaPrimavera = new ProductImage();
            imgBolsaPrimavera.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/bolsa-primavera.jpeg")));

            final Product portaBolachas = new Product();
            portaBolachas.setName("Porta Bolachas com Biscuit");
            portaBolachas.setPrice(new BigDecimal(20));
            portaBolachas.setDescription("Porta bolachas de vidro com tampa detalhada em biscuit ");
            portaBolachas.setCategory(bisquit);

            final ProductImage imgPortaBolachas = new ProductImage();
            imgPortaBolachas.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-oculos.jpeg")));

            final Product arvoreNatal = new Product();
            arvoreNatal.setName("?rvore de Natal");
            arvoreNatal.setPrice(new BigDecimal(25));
            arvoreNatal.setDescription("?rvore de natal feita de tecido");
            arvoreNatal.setCategory(especial);

            final ProductImage imgArvoreNatal = new ProductImage();
            imgArvoreNatal.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/arvore-natal.jpeg")));

            bolsaPrimavera.addToImages(imgBolsaPrimavera);
            portaBijuteria.addToImages(imgPortaBijuteria);
            portaBijuteria.addToImages(imgPortaBijuteria2);
            portaBijuteria.addToImages(imgPortaBijuteria3);
            bolsaDiagonal.addToImages(imgBolsaDiagonal);
            portaBolachas.addToImages(imgPortaBolachas);
            arvoreNatal.addToImages(imgArvoreNatal);

            prdRepo.save(portaBijuteria);
            prdRepo.save(bolsaDiagonal);
            prdRepo.save(bolsaPrimavera);
            prdRepo.save(portaBolachas);
            prdRepo.save(arvoreNatal);

            transacao.commit();

            final User chico = new User();
            chico.setUsername("chico");
            chico.setName("Francisco");
            chico.setEmail("fsilva1992@gmail.com");
            chico.setPassword(CriptografiaUtil.crypt("12345"));

            final User douglas = new User();
            douglas.setUsername("douglas");
            douglas.setName("Douglas Lucio");
            douglas.setEmail("dlucio10@gmail.com");
            douglas.setPassword(CriptografiaUtil.crypt("12345"));

            final User vitor = new User();
            vitor.setUsername("vitinho");
            vitor.setName("Vitor Orsolini");
            vitor.setEmail("orsolini.vitor@gmail.com");
            vitor.setPassword(CriptografiaUtil.crypt("12345"));

            userRepo.save(chico);
            userRepo.save(vitor);
            userRepo.save(douglas);

            final Post post = new Post();
            post.setAuthor(chico);
            post.setTitle("Produto muito bom!");
            post.setText("Este produto  fantastic!! recomendo a todos.");
            post.setPage(bolsaPrimavera.getPage());

            final Post post2 = new Post();
            post2.setAuthor(douglas);
            post2.setTitle("Minha me que faz!");
            post2.setText("Gente essa bolsa  minha me quem faz..  demais.. eu uso ela todos os dias!!");
            post2.setPage(bolsaPrimavera.getPage());

            ApplicationContext.get().getBean(IPostRepository.class).save(post);
            ApplicationContext.get().getBean(IPostRepository.class).save(post2);
        }
    } catch (final Throwable e) {
        e.printStackTrace();
    }

}