Example usage for java.math BigDecimal doubleValue

List of usage examples for java.math BigDecimal doubleValue

Introduction

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

Prototype

@Override
public double doubleValue() 

Source Link

Document

Converts this BigDecimal to a double .

Usage

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests the plate statistics method./*from  w  ww  .  jav a2s . c  o m*/
 */
@Test
public void testPlate() {

    for (Plate plate : array) {

        Map<Well, Integer> resultMap = new TreeMap<Well, Integer>();
        Map<Well, Integer> returnedMap = n.plate(plate);

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getN();

            resultMap.put(well, (int) result);
        }

        for (Well well : plate) {

            int result = resultMap.get(well);
            int returned = returnedMap.get(well);

            assertEquals(result, returned);
        }
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests set calculation.//from w w w.j  a  v  a2 s.c o m
 */
@Test
public void testSet() {

    for (PlateBigDecimal plate : array) {

        Map<WellBigDecimal, Integer> resultMap = new TreeMap<WellBigDecimal, Integer>();
        Map<WellBigDecimal, Integer> returnedMap = n.set(plate.dataSet());

        for (WellBigDecimal well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getN();

            resultMap.put(well, (int) result);
        }

        for (WellBigDecimal well : plate) {

            int result = resultMap.get(well);
            int returned = returnedMap.get(well);

            assertEquals(result, returned);
        }
    }

}

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests set calculation.// w  ww. j  a v a2s. c o m
 */
@Test
public void testSet() {

    for (Plate plate : array) {

        Map<Well, Integer> resultMap = new TreeMap<Well, Integer>();
        Map<Well, Integer> returnedMap = n.set(plate.dataSet());

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getN();

            resultMap.put(well, (int) result);
        }

        for (Well well : plate) {

            int result = resultMap.get(well);
            int returned = returnedMap.get(well);

            assertEquals(result, returned);
        }
    }

}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *//*from   w  w  w. ja v a  2  s.  c  o  m*/
@Test
public void testAggregatedPlateCollection() {

    List<PlateBigDecimal> collection = Arrays.asList(array);
    Map<PlateBigDecimal, Integer> aggregatedReturnedMap = n.platesAggregated(collection);
    Map<PlateBigDecimal, Integer> aggregatedResultMap = new TreeMap<PlateBigDecimal, Integer>();

    for (PlateBigDecimal plate : collection) {

        List<Double> resultList = new ArrayList<Double>();

        for (WellBigDecimal well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(plate, (int) resultAggregated);
    }

    for (PlateBigDecimal plate : collection) {

        int result = aggregatedResultMap.get(plate);
        int returned = aggregatedReturnedMap.get(plate);

        assertEquals(result, returned);
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *//* w w w . j av  a2  s  . c o m*/
@Test
public void testAggregatedPlateArray() {

    Map<PlateBigDecimal, Integer> aggregatedReturnedMap = n.platesAggregated(array);
    Map<PlateBigDecimal, Integer> aggregatedResultMap = new TreeMap<PlateBigDecimal, Integer>();

    for (PlateBigDecimal plate : array) {

        List<Double> resultList = new ArrayList<Double>();

        for (WellBigDecimal well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(plate, (int) resultAggregated);
    }

    for (PlateBigDecimal plate : array) {

        int result = aggregatedResultMap.get(plate);
        int returned = aggregatedReturnedMap.get(plate);

        assertEquals(result, returned);
    }

}

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *///from  ww w .jav a  2  s .  c om
@Test
public void testAggregatedPlateCollection() {

    List<Plate> collection = Arrays.asList(array);
    Map<Plate, Integer> aggregatedReturnedMap = n.platesAggregated(collection);
    Map<Plate, Integer> aggregatedResultMap = new TreeMap<Plate, Integer>();

    for (Plate plate : collection) {

        List<Double> resultList = new ArrayList<Double>();

        for (Well well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(plate, (int) resultAggregated);
    }

    for (Plate plate : collection) {

        int result = aggregatedResultMap.get(plate);
        int returned = aggregatedReturnedMap.get(plate);

        assertEquals(result, returned);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests the aggregated plate statistics method using an array.
 *//*from   w  w w  .j a va  2s  .c  o m*/
@Test
public void testAggregatedPlateArray() {

    Map<Plate, Integer> aggregatedReturnedMap = n.platesAggregated(array);
    Map<Plate, Integer> aggregatedResultMap = new TreeMap<Plate, Integer>();

    for (Plate plate : array) {

        List<Double> resultList = new ArrayList<Double>();

        for (Well well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(plate, (int) resultAggregated);
    }

    for (Plate plate : array) {

        int result = aggregatedResultMap.get(plate);
        int returned = aggregatedReturnedMap.get(plate);

        assertEquals(result, returned);
    }

}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 *///from   w ww . j ava  2  s  . c  o  m
@Test
public void testAggregatedSetCollection() {

    List<WellSetBigDecimal> collection = new ArrayList<WellSetBigDecimal>();

    for (PlateBigDecimal plate : array) {
        collection.add(plate.dataSet());
    }

    Map<WellSetBigDecimal, Integer> aggregatedReturnedMap = n.setsAggregated(collection);
    Map<WellSetBigDecimal, Integer> aggregatedResultMap = new TreeMap<WellSetBigDecimal, Integer>();

    for (WellSetBigDecimal set : collection) {

        List<Double> resultList = new ArrayList<Double>();

        for (WellBigDecimal well : set) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(set, (int) resultAggregated);
    }

    for (WellSetBigDecimal set : collection) {

        int result = aggregatedResultMap.get(set);
        int returned = aggregatedReturnedMap.get(set);

        assertEquals(result, returned);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests the aggregated plate statistics method using a collection.
 */// w w w  .ja va2s . c  o  m
@Test
public void testAggregatedSetCollection() {

    List<WellSet> collection = new ArrayList<WellSet>();

    for (Plate plate : array) {
        collection.add(plate.dataSet());
    }

    Map<WellSet, Integer> aggregatedReturnedMap = n.setsAggregated(collection);
    Map<WellSet, Integer> aggregatedResultMap = new TreeMap<WellSet, Integer>();

    for (WellSet set : collection) {

        List<Double> resultList = new ArrayList<Double>();

        for (Well well : set) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        aggregatedResultMap.put(set, (int) resultAggregated);
    }

    for (WellSet set : collection) {

        int result = aggregatedResultMap.get(set);
        int returned = aggregatedReturnedMap.get(set);

        assertEquals(result, returned);
    }
}

From source file:com.webbfontaine.valuewebb.timer.RatesUpdater.java

@Asynchronous
@Transactional/* w  w w .j  av a  2 s .  c om*/
public QuartzTriggerHandle scheduleTask(@Expiration Date when, @IntervalCron String interval) {

    HashMap<String, BigDecimal> ratesFromBank = ratesFromBank();
    if (ratesFromBank.isEmpty()) {
        LOGGER.error("No rates passed to update, check web site and source code!");
        return null;
    }

    EntityManager entityManager = Utils.getEntityManager();

    List<Rate> existingRates = entityManager.createQuery("from Rate r where r.eov is null").getResultList();

    Transaction tx = ((org.jboss.seam.persistence.HibernateSessionProxy) entityManager.getDelegate())
            .getTransaction();

    try {

        tx.begin();

        for (Rate existingRecord : existingRates) {

            BigDecimal latestRateForCurrency = ratesFromBank.get(existingRecord.getCod());

            if (latestRateForCurrency == null) {
                LOGGER.warn("Currency code '{0}' exists but absent in updates", existingRecord.getCod());
                continue;
            }

            if (existingRecord.getExch().doubleValue() != latestRateForCurrency.doubleValue()) { //i get double value because bigdecimal can return 0.2240 which is not equal to 0.224 when comparing BD values
                /* close existing rate and open new one from today */
                Date tomorrowDate = Utils.getTomorrowDate();
                existingRecord.setEov(tomorrowDate); // since scheduler works at 21:00
                Rate newRecord = new Rate(null, existingRecord.getCod(), 1, latestRateForCurrency, tomorrowDate,
                        null);
                entityManager.persist(existingRecord);
                entityManager.persist(newRecord);
                LOGGER.info("Updated Exchange rate for {0}, old: {1}, new: {2}", newRecord.getCod(),
                        existingRecord.unitRate(), newRecord.unitRate());
            }
        }

        entityManager.flush();
        tx.commit();

    } catch (Exception e) {
        LOGGER.error("Exception on updating rates", e);
        if (tx != null) {
            tx.rollback();
        }
    }

    return null;
}