List of usage examples for java.math BigDecimal doubleValue
@Override public double doubleValue()
From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java
/** * Tests the aggregated plate statistics method using an array. *//*w w w.ja v a 2s . c o m*/ @Test public void testAggregatedSetArray() { WellSetBigDecimal[] setArray = new WellSetBigDecimal[array.length]; for (int i = 0; i < setArray.length; i++) { setArray[i] = array[i].dataSet(); } Map<WellSetBigDecimal, Integer> aggregatedReturnedMap = n.setsAggregated(setArray); Map<WellSetBigDecimal, Integer> aggregatedResultMap = new TreeMap<WellSetBigDecimal, Integer>(); for (WellSetBigDecimal set : setArray) { 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 : setArray) { 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 an array. *///from www.java2s .c om @Test public void testAggregatedSetArray() { WellSet[] setArray = new WellSet[array.length]; for (int i = 0; i < setArray.length; i++) { setArray[i] = array[i].dataSet(); } Map<WellSet, Integer> aggregatedReturnedMap = n.setsAggregated(setArray); Map<WellSet, Integer> aggregatedResultMap = new TreeMap<WellSet, Integer>(); for (WellSet set : setArray) { 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 : setArray) { int result = aggregatedResultMap.get(set); int returned = aggregatedReturnedMap.get(set); assertEquals(result, returned); } }
From source file:com.startup.musicstore.services.Impl.CreditCardServiceImpl.java
@Override public String processPayment(String number, BigDecimal amount, Date expiryDate) { //Search Credit card By creditNumber property on The Entity to Find if it is in the System CreditCard creditCard = getCreditCardByNumber(number); //Test if we have a credit card. // If Not Jump to the Last ELSE and throw CC Rejection Exception --Wrong Number if (creditCard != null) { // If we have a Card Check For sufficient Funds //If Less Funds Throw Exception ELSE APPROVE if (amount.doubleValue() > creditCard.getBalance().doubleValue()) { throw new CreditCardRejectionException("Insufficient Funds In the Account"); } else if (expiryDate.after(creditCard.getExpiryDate())) { //IF expiry Date is Before Credit card EXPIRY DATE Throw Exception throw new CreditCardRejectionException("Sorry Credit Date Expired"); } else {/*from w ww. j a v a2 s . c om*/ return "APPROVED"; } } else { throw new CreditCardRejectionException("Credit Number is Wrong"); } }
From source file:com.ipcglobal.fredimport.xls.DistinctCategoriesSpreadsheet.java
/** * Populate cell./*from w w w.ja v a2 s. c o m*/ * * @param rowData the row data * @param colCnt the col cnt * @param dataType the data type * @param obj the obj * @throws Exception the exception */ private void populateCell(Row rowData, int colCnt, DataType dataType, Object obj) throws Exception { int cellType = 0; if (dataType == DataType.Numeric) cellType = XSSFCell.CELL_TYPE_NUMERIC; else if (dataType == DataType.NumericDec2) cellType = XSSFCell.CELL_TYPE_NUMERIC; else if (dataType == DataType.Text) cellType = XSSFCell.CELL_TYPE_STRING; else if (dataType == DataType.Date) cellType = XSSFCell.CELL_TYPE_STRING; else if (dataType == DataType.Accounting) cellType = XSSFCell.CELL_TYPE_NUMERIC; else if (dataType == DataType.Percent) cellType = XSSFCell.CELL_TYPE_NUMERIC; Cell cellData = rowData.createCell(colCnt, cellType); short findFormat = -1; if (dataType == DataType.Date) findFormat = formatMmDdYyyy; else if (dataType == DataType.Percent) findFormat = formatPercent; else if (dataType == DataType.Accounting) findFormat = formatAccounting; else if (dataType == DataType.Numeric) findFormat = formatNumeric; else if (dataType == DataType.NumericDec2) findFormat = formatNumericDec2; else findFormat = formatGeneral; CellStyle style = findCellStyle("Arial", HSSFColor.BLACK.index, (short) 11, XSSFFont.BOLDWEIGHT_NORMAL, cellStyleFromDataAlign(findAlignByDataType(dataType)), XSSFCellStyle.VERTICAL_TOP, BG_COLOR_NONE, CellBorder.All_Thin, findFormat); cellData.setCellStyle(style); if (dataType == DataType.Numeric || dataType == DataType.NumericDec2 || dataType == DataType.Accounting || dataType == DataType.Percent) { if (obj == null) ; // leave the cell empty else if (obj instanceof BigDecimal) { BigDecimal value = (BigDecimal) obj; if (value != null) cellData.setCellValue(value.doubleValue()); } else if (obj instanceof Integer) { Integer value = (Integer) obj; if (value != null) cellData.setCellValue(value.intValue()); } else if (obj instanceof Long) { Long value = (Long) obj; if (value != null) cellData.setCellValue(value.longValue()); } else if (obj instanceof Double) { Double value = (Double) obj; if (value != null) cellData.setCellValue(value.doubleValue()); } else if (obj instanceof Short) { Short value = (Short) obj; if (value != null) cellData.setCellValue(value.shortValue()); } else if (obj instanceof String) { String value = (String) obj; if (value != null) cellData.setCellValue(value); } else throw new Exception("Unsupported numeric type: " + obj.getClass().getSimpleName()); } else if (dataType == DataType.Date) { Date date = (Date) obj; if (date != null) cellData.setCellValue(date); } else { cellData.setCellValue((String) obj); } }
From source file:com.capitalone.dashboard.collector.DefaultNexusIQClient.java
/** * Get the report details given a url for the report data. * @param url url of the report/*from w w w .j av a2 s . co m*/ * @return LibraryPolicyResult */ @SuppressWarnings({ "PMD.AvoidDeeplyNestedIfStmts", "PMD.NPathComplexity" }) // agreed PMD, fixme @Override public LibraryPolicyResult getDetailedReport(String url) { LibraryPolicyResult policyResult = null; try { JSONObject obj = parseAsObject(url); JSONArray componentArray = (JSONArray) obj.get("components"); if ((componentArray == null) || (componentArray.isEmpty())) return null; for (Object element : componentArray) { JSONObject component = (JSONObject) element; int licenseLevel = 0; JSONArray pathArray = (JSONArray) component.get("pathnames"); String componentName = !CollectionUtils.isEmpty(pathArray) ? (String) pathArray.get(0) : getComponentNameFromIdentifier((JSONObject) component.get("componentIdentifier")); JSONObject licenseData = (JSONObject) component.get("licenseData"); if (licenseData != null) { //process license data JSONArray effectiveLicenseThreats = (JSONArray) licenseData.get("effectiveLicenseThreats"); if (!CollectionUtils.isEmpty(effectiveLicenseThreats)) { for (Object et : effectiveLicenseThreats) { JSONObject etJO = (JSONObject) et; Long longvalue = toLong(etJO, "licenseThreatGroupLevel"); if (longvalue != null) { int newlevel = longvalue.intValue(); if (licenseLevel == 0) { licenseLevel = newlevel; } else { licenseLevel = nexusIQSettings.isSelectStricterLicense() ? Math.max(licenseLevel, newlevel) : Math.min(licenseLevel, newlevel); } } } } } if (policyResult == null) { policyResult = new LibraryPolicyResult(); } if (licenseLevel > 0) { policyResult.addThreat(LibraryPolicyType.License, LibraryPolicyThreatLevel.fromInt(licenseLevel), componentName); } JSONObject securityData = (JSONObject) component.get("securityData"); if (securityData != null) { //process security data JSONArray securityIssues = (JSONArray) securityData.get("securityIssues"); if (!CollectionUtils.isEmpty(securityIssues)) { for (Object si : securityIssues) { JSONObject siJO = (JSONObject) si; BigDecimal bigDecimalValue = decimal(siJO, "severity"); double securityLevel = (bigDecimalValue == null) ? getSeverityLevel(str(siJO, "threatCategory")) : bigDecimalValue.doubleValue(); policyResult.addThreat(LibraryPolicyType.Security, LibraryPolicyThreatLevel.fromDouble(securityLevel), componentName); } } } } } catch (ParseException e) { LOG.error("Could not parse response from: " + url, e); } catch (RestClientException rce) { LOG.error("RestClientException from: " + url + ". Error code=" + rce.getMessage()); } return policyResult; }
From source file:jbosscomp.view.backing.Comparator.java
public BigDecimal getSubscriptionCost() { RichInputNumberSpinbox rinsTotalJBossCores = (RichInputNumberSpinbox) get( "#{backingBeanScope.backing_comparator.jbossCoresY1}"); BigDecimal totalCores = new BigDecimal(rinsTotalJBossCores.getValue().toString()); Double index = totalCores.doubleValue() / 16.0; index = Math.ceil(index);// w w w . ja va2 s .com int i = index.intValue(); if (i >= subscriptionCosts.length) i = 0; return new BigDecimal(subscriptionCosts[i]); }
From source file:ch.cyberduck.cli.TerminalStreamListener.java
private void increment() { final TransferProgress progress = meter.getStatus(); if (System.currentTimeMillis() - timestamp.get() < 100L) { if (!progress.isComplete()) { return; }/* w ww. j a v a 2 s . c o m*/ } try { lock.acquire(); final BigDecimal fraction; if (progress.getTransferred() == 0L) { fraction = BigDecimal.ZERO; } else { fraction = new BigDecimal(progress.getTransferred()).divide(new BigDecimal(progress.getSize()), 1, RoundingMode.DOWN); } console.printf("\r%s[", Ansi.ansi().saveCursorPosition().eraseLine(Ansi.Erase.ALL).restoreCursorPosition()); int i = 0; for (; i <= (int) (fraction.doubleValue() * width); i++) { console.printf("\u25AE"); } for (; i < width; i++) { console.printf(StringUtils.SPACE); } console.printf("] %s%s", progress.getProgress(), Ansi.ansi().reset()); timestamp.set(System.currentTimeMillis()); } catch (InterruptedException e) { // } finally { lock.release(); } }
From source file:com.school.exam.web.student.StudentController.java
@RequestMapping(value = "submitpaper", method = RequestMethod.POST) @Token(remove = true)/*ww w .ja v a 2 s .c o m*/ public String submitPaper(Model model, ServletRequest request) { ShiroDbRealm.ShiroUser user = getCurrentUser(); Map<String, String[]> param = request.getParameterMap(); Long examId = Long.valueOf(param.get("id")[0]); //????? Integer isNothas = resultService.hasExamPaperByPersonId(user.id, examId); if (isNothas > 0) { //model.addAttribute("message", "??,?????!"); return "redirect:examlist"; } else { TeMakeExamVO examvo = questionService.findExamQuestions(examId); examvo = addRemark(examvo, examId); List<TeExamResultVO> resultList = Lists.newArrayList(); Double sumScore = 0.0; List<TeExamQuestionVO> eqlist = examvo.getQuestionList(); for (TeExamQuestionVO vo : eqlist) { String[] selectval = param.get(vo.getId().toString()); // TeExamResultVO rvo = new TeExamResultVO(); rvo.setPersonId(user.id); rvo.setPersonName(user.getName()); rvo.setDepdId(examvo.getId()); rvo.setExamQuestionId(vo.getId()); rvo.setQuestionAnswer(vo.getQuestionAnswerId()); rvo.setState(1); if (null != selectval) { if (vo.getType().equals(1)) { if (vo.getQuestionAnswerId().equals(selectval[0])) { rvo.setQuestionScore(vo.getQuestionScore()); } else { rvo.setQuestionScore(0.0); } rvo.setChooseQuestionId(selectval[0]); } if (vo.getType().equals(2)) { if (vo.getQuestionAnswerId().contentEquals(StringUtils.toDelimitedString(selectval, ","))) { rvo.setQuestionScore(vo.getQuestionScore()); } else { rvo.setQuestionScore(0.0); } rvo.setChooseQuestionId(StringUtils.toDelimitedString(selectval, ",")); } } if (null != rvo.getQuestionScore()) { BigDecimal bd = BigDecimal.valueOf(rvo.getQuestionScore()); BigDecimal sum = BigDecimal.valueOf(sumScore).add(bd); sumScore = sum.doubleValue(); } resultList.add(rvo); } //? questionService.saveExamResult(resultList); TeExamPaperResultVO resultvo = new TeExamPaperResultVO(); resultvo.setExamId(examId); resultvo.setExamName(examvo.getExamName()); resultvo.setExamRemark(examvo.getExamRemark()); resultvo.setSumScore(sumScore); resultvo.setState(1); resultvo.setPersonId(user.id); resultvo.setPersonName(user.getName()); //? resultService.saveExamPaperResult(resultvo); model.addAttribute("sumScore", sumScore); model.addAttribute("examvo", examvo); model.addAttribute("resultlist", resultList); model.addAttribute("nav", NAV_MAP); model.addAttribute("project", examvo.getProject().getProjectName()); return "student/resultlist"; } }
From source file:net.authorize.api.controller.test.ApiCoreTestBase.java
public BigDecimal setValidTaxAmount(BigDecimal amount) { return new BigDecimal(amount.doubleValue() * TAX_RATE); }
From source file:es.logongas.encuestas.modelo.resultados.InferenciaEstadistica.java
public InferenciaEstadistica(EstadisticaDescriptiva estadisticaDescriptiva, BigDecimal nivelConfianza, int numDecimals) { this.numDecimals = numDecimals; if (nivelConfianza.compareTo(BigDecimal.ZERO) <= 0) { throw new IllegalArgumentException("El nivelConfianza debe ser mayor que 0"); }/*from w ww . j ava 2 s. c o m*/ if (nivelConfianza.compareTo(BigDecimal.ONE) >= 0) { throw new IllegalArgumentException("El nivelConfianza debe ser menor que 1"); } TDistribution tDistribution = new TDistribution(estadisticaDescriptiva.getNumMuestras() - 1); double t = tDistribution.inverseCumulativeProbability(nivelConfianza.doubleValue()); BigDecimal delta = new BigDecimal(t * (estadisticaDescriptiva.getDesviacionEstandar().doubleValue() / Math.sqrt(estadisticaDescriptiva.getNumMuestras()))); BigDecimal min = estadisticaDescriptiva.getMedia().subtract(delta).setScale(this.numDecimals, RoundingMode.HALF_UP); BigDecimal max = estadisticaDescriptiva.getMedia().add(delta).setScale(this.numDecimals, RoundingMode.HALF_UP); intervaloConfianzaMedia = new IntervaloConfianza(min, max, nivelConfianza); }