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:Main.java

/**
 * Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since
 * the epoch./*from  w  w w. j  av a2 s .  c  o m*/
 *
 * @param value The attribute value to parse.
 * @return The parsed timestamp in milliseconds since the epoch.
 */
public static long parseXsDateTime(String value) throws ParseException {
    Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
    if (!matcher.matches()) {
        throw new ParseException("Invalid date/time format: " + value, 0);
    }

    int timezoneShift;
    if (matcher.group(9) == null) {
        // No time zone specified.
        timezoneShift = 0;
    } else if (matcher.group(9).equalsIgnoreCase("Z")) {
        timezoneShift = 0;
    } else {
        timezoneShift = ((Integer.parseInt(matcher.group(12)) * 60 + Integer.parseInt(matcher.group(13))));
        if (matcher.group(11).equals("-")) {
            timezoneShift *= -1;
        }
    }

    Calendar dateTime = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    dateTime.clear();
    // Note: The month value is 0-based, hence the -1 on group(2)
    dateTime.set(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1,
            Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4)),
            Integer.parseInt(matcher.group(5)), Integer.parseInt(matcher.group(6)));
    if (!TextUtils.isEmpty(matcher.group(8))) {
        final BigDecimal bd = new BigDecimal("0." + matcher.group(8));
        // we care only for milliseconds, so movePointRight(3)
        dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue());
    }

    long time = dateTime.getTimeInMillis();
    if (timezoneShift != 0) {
        time -= timezoneShift * 60000;
    }

    return time;
}

From source file:ch.ralscha.extdirectspring.provider.RemoteProviderFormLoad.java

@ExtDirectMethod(value = ExtDirectMethodType.FORM_LOAD, group = "group3", event = "test")
public FormInfo method1(@RequestParam(value = "d") double d) {
    FormInfo info = new FormInfo();
    info.setBack(d);//from   w ww .j  a  va  2 s.  c  o m
    info.setAdmin(true);
    info.setAge(31);
    info.setBirthday(new GregorianCalendar(1980, Calendar.JANUARY, 15).getTime());
    info.setName("Bob");
    info.setSalary(new BigDecimal("10000.55"));
    return info;
}

From source file:net.sf.morph.util.TestClass.java

public static Map getMyMapProperty() {
    Map myMap = new HashMap();
    myMap.put("one", new Integer(1));
    myMap.put("two", new Object[] { new Integer(1), new BigDecimal(2) });
    return myMap;
}

From source file:com.oreilly.springdata.jpa.core.ProductRepositoryIntegrationTest.java

@Test
public void createProduct() {

    Product product = new Product("Camera bag", new BigDecimal(49.99));
    product = repository.save(product);/*from   w w w . j  av  a2  s  .  c  o m*/
}

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

@Test
public void processesEquities() {

    Deal deal = new Deal(new Equity("Deutsche Bank"));

    Result result = processor.process(deal);
    assertThat(result.getFee(), is(new BigDecimal(10.5)));
}

From source file:nl.talsmasoftware.reflection.dto.DtoJsonMappingTest.java

@Before
public void setup() {
    mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    dto42 = new DtoRepresentationV1();
    dto42.number = 42L;//w w  w  . jav a  2s . c  o m
    dto42.name = "The Answer to the Ultimate Question of Life, the Universe, and Everything";
    dto42.amountInEuros = new BigDecimal("42.00");
    dto42.subObject = new DtoRepresentationV1();
    dto42.subObject.number = 13L;
    dto42.subObject.name = "Bad luck";
    dto42.subObject.amountInEuros = new BigDecimal("13.13");
}

From source file:Main.java

public static double getCpuUsage1() {
    try {/*from  w  w w.j  av  a  2s .  c o m*/
        RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
        String load = reader.readLine();
        String[] toks = load.split(" ");

        double user1 = Double.parseDouble(toks[2]);
        double system1 = Double.parseDouble(toks[4]);
        double irq1 = Double.parseDouble(toks[7]);
        double idle1 = Double.parseDouble(toks[5]);
        try {
            Thread.sleep(360);
        } catch (Exception e) {
            e.printStackTrace();
        }
        reader.seek(0);
        load = reader.readLine();
        reader.close();
        toks = load.split(" ");
        double user2 = Double.parseDouble(toks[2]);
        double system2 = Double.parseDouble(toks[4]);
        double irq2 = Double.parseDouble(toks[7]);
        double idle2 = Double.parseDouble(toks[5]);

        double user_pass = user2 - user1;
        double system_pass = system2 - system1;
        double irq_pass = irq2 - irq1;
        double idle_pass = idle2 - idle1;
        double usage = (user_pass + system_pass + irq_pass) * 100.00
                / (user_pass + irq_pass + system_pass + idle_pass);
        BigDecimal b = new BigDecimal(usage);
        double res = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return res;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    return 0;

}

From source file:com.mycompany.carshop.test.repository.AutomobileRepositoryTest.java

@Test(enabled = true)
public void createAutomobile() {
    automobileRepository = ctx.getBean(AutomobileRepository.class);

    Colour colour = new Colour();
    colour.setBodyColour("Black");
    colour.setInteriorColour("White");

    Accessories accessoty = new Accessories();
    accessoty.setAccessoryNumber("102031");
    accessoty.setAccessoryName("Seats Cover");
    accessoty.setUnitPrice(new BigDecimal(150.00));

    Automobile car = new Automobile.Builder("558 465 2CA").autoName("BMW M3").manufacturer("BMW")
            .modelYear("2013").unitPrice(new BigDecimal(120000.00)).sales(10).inventory(30).accessory(accessoty)
            .colour(colour).build();/*from  w  w w.  j ava2 s.c  o m*/

    automobileRepository.save(car);
    id = car.getId();
    Assert.assertNotNull(car);

}

From source file:com.iisigroup.cap.rule.service.impl.FactorMntServiceImpl.java

@Override
public void insertTestCaseInfoData() {
    BigDecimal[] amount = new BigDecimal[] { new BigDecimal(100000), new BigDecimal(150000),
            new BigDecimal(900000), new BigDecimal(999999), new BigDecimal(50000), new BigDecimal(330000),
            new BigDecimal(550000), new BigDecimal(330000), new BigDecimal(150000), new BigDecimal(260000),
            new BigDecimal(440000), new BigDecimal(100000), new BigDecimal(880000), new BigDecimal(330000),
            new BigDecimal(150000), new BigDecimal(150000), new BigDecimal(250000), new BigDecimal(440000),
            new BigDecimal(130000), new BigDecimal(300000) };

    Integer[] overDueDay = new Integer[] { 20, 90, 20, 31, 20, 20, 44, 29, 20, 77, 30, 66, 88, 20, 66, 90, 11,
            30, 20, 15 };//from   www  . j a  v a2 s  .c  o m
    List<CaseInfo> caseList = new ArrayList<CaseInfo>();
    Calendar cal = Calendar.getInstance();
    int count = 1;
    for (int j = 1; j <= 20; j++) {
        for (int i = count; i <= (5000 * j); i++) {
            CaseInfo cas = new CaseInfo();
            cas.setCasNo(StringUtils.leftPad(String.valueOf(i), 20, '0'));
            int result = (int) (Math.random() * (20 - 1) + 1);
            cas.setAmount(amount[result]);
            result = (int) (Math.random() * (20 - 1) + 1);
            cas.setOverDueDay(overDueDay[result]);
            cas.setCreator("System");
            cas.setCreateTime(new Timestamp(cal.getTimeInMillis()));
            caseList.add(cas);
            count++;
        }
        caseInfoDao.save(caseList);
        System.out.println(" case info records :: " + caseList.size());
    }
}

From source file:com.ning.billing.invoice.dao.InvoiceItemDaoTests.java

@Test
public void testInvoiceItemCreation() {
    UUID invoiceId = UUID.randomUUID();
    UUID subscriptionId = UUID.randomUUID();
    DateTime startDate = new DateTime(2011, 10, 1, 0, 0, 0, 0);
    DateTime endDate = new DateTime(2011, 11, 1, 0, 0, 0, 0);
    BigDecimal rate = new BigDecimal("20.00");

    InvoiceItem item = new DefaultInvoiceItem(invoiceId, subscriptionId, startDate, endDate, "test", rate, rate,
            Currency.USD);/*from w  w w  . ja  v a  2s .  c  om*/
    invoiceItemDao.create(item);

    InvoiceItem thisItem = invoiceItemDao.getById(item.getId().toString());
    assertNotNull(thisItem);
    assertEquals(thisItem.getId(), item.getId());
    assertEquals(thisItem.getInvoiceId(), item.getInvoiceId());
    assertEquals(thisItem.getSubscriptionId(), item.getSubscriptionId());
    assertEquals(thisItem.getStartDate(), item.getStartDate());
    assertEquals(thisItem.getEndDate(), item.getEndDate());
    assertEquals(thisItem.getDescription(), item.getDescription());
    assertEquals(thisItem.getAmount().compareTo(item.getAmount()), 0);
    assertEquals(thisItem.getRate().compareTo(item.getRate()), 0);
    assertEquals(thisItem.getCurrency(), item.getCurrency());
}