List of usage examples for java.math BigDecimal doubleValue
@Override public double doubleValue()
From source file:com.github.jessemull.microflexbigdecimal.stat.SampleVarianceTest.java
/** * Tests the plate statistics method using the values between the indices. *///from w ww . j a v a2 s. c o m @Test public void testPlateIndices() { for (Plate plate : arrayIndices) { int size = arrayIndices[0].first().size(); int begin = random.nextInt(size - 5); int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1); Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>(); Map<Well, BigDecimal> returnedMap = variance.plate(plate, begin, end - begin, mc); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } double[] inputArray = ArrayUtils.subarray(input, begin, end); DescriptiveStatistics stat = new DescriptiveStatistics(inputArray); double resultDouble = stat.getVariance(); BigDecimal result = new BigDecimal(resultDouble); resultMap.put(well, result); } for (Well well : plate) { BigDecimal result = resultMap.get(well); BigDecimal returned = returnedMap.get(well); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.SampleVarianceBigDecimalTest.java
/** * Tests set calculation using indices./*from ww w . ja v a2 s. c o m*/ */ @Test public void testSetIndices() { for (PlateBigDecimal plate : arrayIndices) { int size = arrayIndices[0].first().size(); int begin = random.nextInt(size - 5); int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1); Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>(); Map<WellBigDecimal, BigDecimal> returnedMap = variance.set(plate.dataSet(), begin, end - begin, mc); for (WellBigDecimal well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } double[] inputArray = ArrayUtils.subarray(input, begin, end); DescriptiveStatistics stat = new DescriptiveStatistics(inputArray); double resultDouble = stat.getVariance(); BigDecimal result = new BigDecimal(resultDouble); resultMap.put(well, result); } for (WellBigDecimal well : plate) { BigDecimal result = resultMap.get(well); BigDecimal returned = returnedMap.get(well); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflexbigdecimal.stat.SampleVarianceTest.java
/** * Tests set calculation using indices.//from w w w . jav a 2s. c om */ @Test public void testSetIndices() { for (Plate plate : arrayIndices) { int size = arrayIndices[0].first().size(); int begin = random.nextInt(size - 5); int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1); Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>(); Map<Well, BigDecimal> returnedMap = variance.set(plate.dataSet(), begin, end - begin, mc); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } double[] inputArray = ArrayUtils.subarray(input, begin, end); DescriptiveStatistics stat = new DescriptiveStatistics(inputArray); double resultDouble = stat.getVariance(); BigDecimal result = new BigDecimal(resultDouble); resultMap.put(well, result); } for (Well well : plate) { BigDecimal result = resultMap.get(well); BigDecimal returned = returnedMap.get(well); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflexbigdecimal.stat.PercentileTest.java
/** * Tests well calculation./*from w w w. j a va 2 s . c o m*/ */ @Test public void testWell() { for (Plate plate : array) { for (Well well : plate) { int inputPercentile = 1 + random.nextInt(100); double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getPercentile(inputPercentile); BigDecimal returned = percentile.well(well, inputPercentile); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.PercentileBigDecimalTest.java
/** * Tests well calculation.// www .ja va 2 s .c om */ @Test public void testWell() { for (PlateBigDecimal plate : array) { for (WellBigDecimal well : plate) { int inputPercentile = 1 + random.nextInt(100); double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getPercentile(inputPercentile); BigDecimal returned = percentile.well(well, inputPercentile); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.PopulationVarianceBigDecimalTest.java
/** * Tests well calculation./* ww w . j a v a 2 s. c om*/ */ @Test public void testWell() { for (PlateBigDecimal plate : array) { 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 resultDouble = stat.getVariance(); resultDouble *= well.size() - 1; resultDouble /= well.size(); BigDecimal returned = variance.well(well, mc); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflexbigdecimal.stat.PercentileTest.java
/** * Tests well calculation using indices. *///from w w w. j ava 2 s .c o m @Test public void testWellIndices() { for (Plate plate : arrayIndices) { for (Well well : plate) { int inputPercentile = 1 + random.nextInt(100); double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } int size = arrayIndices[0].first().size(); int begin = random.nextInt(size - 5); int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1); DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end)); double resultDouble = stat.getPercentile(inputPercentile); BigDecimal returned = percentile.well(well, begin, end - begin, inputPercentile); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflexbigdecimal.stat.PopulationVarianceTest.java
/** * Tests well calculation./*from ww w .j a v a2 s . c o m*/ */ @Test public void testWell() { for (Plate plate : array) { 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 resultDouble = stat.getVariance(); resultDouble *= well.size() - 1; resultDouble /= well.size(); BigDecimal returned = variance.well(well, mc); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.salesmanager.core.service.tax.TaxService.java
/** * Calculates tax on a BigDecimal price, returns the price with tax * /*from w w w.ja v a 2 s .c om*/ * @param amount * @param customer * @param merchantId * @return * @throws Exception */ @Transactional public BigDecimal calculateTax(BigDecimal amount, long taxClassId, Customer customer, int merchantId) throws Exception { // no tax calculation id taxClassId==-1 if (taxClassId == -1) { return amount; } MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService); ConfigurationRequest request = new ConfigurationRequest(merchantId, ShippingConstants.MODULE_TAX_BASIS); ConfigurationResponse response = mservice.getConfiguration(request); String taxBasis = TaxConstants.SHIPPING_TAX_BASIS; // get tax basis MerchantConfiguration taxConf = response.getMerchantConfiguration(TaxConstants.MODULE_TAX_BASIS); if (taxConf != null && !StringUtils.isBlank(taxConf.getConfigurationValue())) {// tax // basis taxBasis = taxConf.getConfigurationValue(); } Collection taxCollection = null; if (taxBasis.equals(TaxConstants.SHIPPING_TAX_BASIS)) { taxCollection = taxRateDao.findByCountryIdZoneIdAndClassId(customer.getCustomerCountryId(), customer.getCustomerZoneId(), taxClassId, merchantId); } else { taxCollection = taxRateDao.findByCountryIdZoneIdAndClassId(customer.getCustomerBillingCountryId(), customer.getCustomerBillingZoneId(), taxClassId, merchantId); } BigDecimal currentAmount = new BigDecimal(0); currentAmount.setScale(2, BigDecimal.ROUND_HALF_UP); if (taxCollection != null) { Iterator i = taxCollection.iterator(); while (i.hasNext()) { TaxRate trv = (TaxRate) i.next(); BigDecimal amountForCalculation = amount; if (trv.isPiggyback()) { amountForCalculation = amountForCalculation.add(currentAmount); } double value = ((trv.getTaxRate().doubleValue() * amountForCalculation.doubleValue()) / 100) + amountForCalculation.doubleValue(); currentAmount = currentAmount.add(new BigDecimal(value)); } } return currentAmount; }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.PercentileBigDecimalTest.java
/** * Tests well calculation using indices. *//*from ww w.j a v a2 s .c o m*/ @Test public void testWellIndices() { for (PlateBigDecimal plate : arrayIndices) { for (WellBigDecimal well : plate) { int inputPercentile = 1 + random.nextInt(100); double[] input = new double[well.size()]; int index = 0; for (BigDecimal bd : well) { input[index++] = bd.doubleValue(); } int size = arrayIndices[0].first().size(); int begin = random.nextInt(size - 5); int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1); DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end)); double resultDouble = stat.getPercentile(inputPercentile); BigDecimal returned = percentile.well(well, begin, end - begin, inputPercentile); BigDecimal result = new BigDecimal(resultDouble); BigDecimal[] corrected = correctRoundingErrors(returned, result); assertEquals(corrected[0], corrected[1]); } } }