List of usage examples for java.math BigDecimal longValue
@Override public long longValue()
From source file:org.moqui.impl.entity.EntityJavaUtil.java
public static Object convertFromString(String value, FieldInfo fi, L10nFacade l10n) { Object outValue;//from w w w. j av a 2s . c o m boolean isEmpty = value.length() == 0; try { switch (fi.typeValue) { case 1: outValue = value; break; case 2: // outValue = java.sql.Timestamp.valueOf(value); if (isEmpty) { outValue = null; break; } outValue = l10n.parseTimestamp(value, null); if (outValue == null) throw new BaseException("The value [" + value + "] is not a valid date/time for field " + fi.entityName + "." + fi.name); break; case 3: // outValue = java.sql.Time.valueOf(value); if (isEmpty) { outValue = null; break; } outValue = l10n.parseTime(value, null); if (outValue == null) throw new BaseException("The value [" + value + "] is not a valid time for field " + fi.entityName + "." + fi.name); break; case 4: // outValue = java.sql.Date.valueOf(value); if (isEmpty) { outValue = null; break; } outValue = l10n.parseDate(value, null); if (outValue == null) throw new BaseException("The value [" + value + "] is not a valid date for field " + fi.entityName + "." + fi.name); break; case 5: // outValue = Integer.valueOf(value); break case 6: // outValue = Long.valueOf(value); break case 7: // outValue = Float.valueOf(value); break case 8: // outValue = Double.valueOf(value); break case 9: // outValue = new BigDecimal(value); break if (isEmpty) { outValue = null; break; } BigDecimal bdVal = l10n.parseNumber(value, null); if (bdVal == null) { throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType + "] for field " + fi.entityName + "." + fi.name); } else { bdVal = bdVal.stripTrailingZeros(); switch (fi.typeValue) { case 5: outValue = bdVal.intValue(); break; case 6: outValue = bdVal.longValue(); break; case 7: outValue = bdVal.floatValue(); break; case 8: outValue = bdVal.doubleValue(); break; default: outValue = bdVal; break; } } break; case 10: if (isEmpty) { outValue = null; break; } outValue = Boolean.valueOf(value); break; case 11: outValue = value; break; case 12: try { outValue = new SerialBlob(value.getBytes()); } catch (SQLException e) { throw new BaseException("Error creating SerialBlob for value [" + value + "] for field " + fi.entityName + "." + fi.name); } break; case 13: outValue = value; break; case 14: if (isEmpty) { outValue = null; break; } Timestamp ts = l10n.parseTimestamp(value, null); outValue = new java.util.Date(ts.getTime()); break; // better way for Collection (15)? maybe parse comma separated, but probably doesn't make sense in the first place case 15: outValue = value; break; default: outValue = value; break; } } catch (IllegalArgumentException e) { throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType + "] for field " + fi.entityName + "." + fi.name, e); } return outValue; }
From source file:com.abiquo.server.core.infrastructure.DatacenterDAO.java
/** * TODO: create queries/*from w w w . j av a 2 s .com*/ * * @param datacenterId * @param enterpriseId * @return */ public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId, final int enterpriseId) { Object[] vmResources = (Object[]) getSession().createSQLQuery(SUM_VM_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); Long cpu = vmResources[0] == null ? 0 : ((BigDecimal) vmResources[0]).longValue(); Long ram = vmResources[1] == null ? 0 : ((BigDecimal) vmResources[1]).longValue(); Long hd = vmResources[2] == null ? 0 : ((BigDecimal) vmResources[2]).longValue(); BigDecimal extraHd = (BigDecimal) getSession().createSQLQuery(SUM_EXTRA_HD_RESOURCES) .setParameter("datacenterId", datacenterId).uniqueResult(); Long hdTot = extraHd == null ? hd : hd + extraHd.longValue() * 1024 * 1024; BigDecimal storage = (BigDecimal) getSession().createSQLQuery(SUM_STORAGE_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); BigInteger publicIps = (BigInteger) getSession().createSQLQuery(COUNT_IP_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); BigInteger vlan = (BigInteger) getSession().createSQLQuery(COUNT_VLAN_RESOURCES) .setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); DefaultEntityCurrentUsed used = new DefaultEntityCurrentUsed(cpu.intValue(), ram, hdTot); // Storage usage is stored in MB used.setStorage(storage == null ? 0 : storage.longValue() * 1024 * 1024); used.setPublicIp(publicIps == null ? 0 : publicIps.longValue()); used.setVlanCount(vlan == null ? 0 : vlan.longValue()); return used; }
From source file:com.ar.dev.tierra.api.controller.MetodoPagoFacturaController.java
@RequestMapping(value = "/add", method = RequestMethod.POST) @SuppressWarnings("StringEquality") public ResponseEntity<?> add(OAuth2Authentication authentication, @RequestBody MetodoPagoFactura pagoFactura) throws Exception { Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName()); boolean control = true; JsonResponse msg = new JsonResponse(); @SuppressWarnings("UnusedAssignment") NotaCredito notaCredito = null;/*from w ww. j a v a 2 s . co m*/ switch (pagoFactura.getPlanPago().getIdPlanesPago()) { case 1: PlanPago plan = facadeService.getPlanPagoDAO().searchById(1); pagoFactura.setPlanPago(plan); break; case 4: PlanPago planNota = facadeService.getPlanPagoDAO().searchById(2); notaCredito = facadeService.getNotaCreditoDAO().getByNumero(pagoFactura.getComprobante()); if (notaCredito != null) { if (pagoFactura.getMontoPago().compareTo(notaCredito.getMontoTotal()) == 0) { if (notaCredito.getEstadoUso().equals("SIN USO")) { pagoFactura.setPlanPago(planNota); } else if (notaCredito.getEstadoUso().equals("CANCELADO")) { msg = new JsonResponse("Error", "Nota de credito cancelada."); control = false; } else { msg = new JsonResponse("Error", "Ya ha sido usada la nota de credito."); control = false; } } else { msg = new JsonResponse("Error", "Monto de la nota de credito invalido."); control = false; } } else { msg = new JsonResponse("Error", "Nota de credito invalida."); control = false; } } if (control) { Factura factura = facadeService.getFacturaDAO().searchById(pagoFactura.getFactura().getIdFactura()); List<MetodoPagoFactura> list = facadeService.getMetodoPagoFacturaDAO() .getFacturaMetodo(factura.getIdFactura()); /*POSIBLE FALLA, DECIMAL INMUTABLE NO SE SUMAN ENTRE SI, NECESITA TEST*/ BigDecimal totalFactura = BigDecimal.ZERO; for (MetodoPagoFactura metodoPagoFactura : list) { totalFactura = totalFactura.add(metodoPagoFactura.getMontoPago()); } if (factura.getTotal().longValue() > totalFactura.longValue()) { pagoFactura.setUsuarioCreacion(user.getIdUsuario()); pagoFactura.setFechaCreacion(new Date()); pagoFactura.setEstado(true); if (notaCredito != null) { notaCredito.setFacturaUso(pagoFactura.getFactura().getIdFactura()); notaCredito.setEstadoUso("USADO"); facadeService.getNotaCreditoDAO().update(notaCredito); } facadeService.getMetodoPagoFacturaDAO().add(pagoFactura); msg = new JsonResponse("Success", "Metodo de pago agregado con exito"); return new ResponseEntity<>(msg, HttpStatus.OK); } else { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } } else { return new ResponseEntity<>(msg, HttpStatus.BAD_REQUEST); } }
From source file:org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport.java
private void mergeFromFile(File file, AllTestResults model) { try {/*from w w w . j a v a 2 s. co m*/ InputStream inputStream = new FileInputStream(file); Document document; try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new InputSource(inputStream)); } finally { inputStream.close(); } NodeList testCases = document.getElementsByTagName("testcase"); for (int i = 0; i < testCases.getLength(); i++) { Element testCase = (Element) testCases.item(i); String className = testCase.getAttribute("classname"); String testName = testCase.getAttribute("name"); LocaleSafeDecimalFormat format = new LocaleSafeDecimalFormat(); BigDecimal duration = format.parse(testCase.getAttribute("time")); duration = duration.multiply(BigDecimal.valueOf(1000)); NodeList failures = testCase.getElementsByTagName("failure"); TestResult testResult = model.addTest(className, testName, duration.longValue()); for (int j = 0; j < failures.getLength(); j++) { Element failure = (Element) failures.item(j); testResult.addFailure(failure.getAttribute("message"), failure.getTextContent()); } } NodeList ignoredTestCases = document.getElementsByTagName("ignored-testcase"); for (int i = 0; i < ignoredTestCases.getLength(); i++) { Element testCase = (Element) ignoredTestCases.item(i); String className = testCase.getAttribute("classname"); String testName = testCase.getAttribute("name"); model.addTest(className, testName, 0).ignored(); } String suiteClassName = document.getDocumentElement().getAttribute("name"); ClassTestResults suiteResults = model.addTestClass(suiteClassName); NodeList stdOutElements = document.getElementsByTagName("system-out"); for (int i = 0; i < stdOutElements.getLength(); i++) { suiteResults.addStandardOutput(stdOutElements.item(i).getTextContent()); } NodeList stdErrElements = document.getElementsByTagName("system-err"); for (int i = 0; i < stdErrElements.getLength(); i++) { suiteResults.addStandardError(stdErrElements.item(i).getTextContent()); } } catch (Exception e) { throw new GradleException(String.format("Could not load test results from '%s'.", file), e); } }
From source file:com.ctrip.infosec.rule.RuleTest.java
void R2() { RiskFact $fact = new RiskFact(); $fact.eventPoint = "CP0003001"; $fact.ext.put(Constants.key_ruleNo, "CP0003001"); //??orderID/*from w w w . j av a 2 s .c o m*/ Random random = new Random(); int randomNum = random.nextInt(10000000); $fact.eventBody.put("mobilePhone", randomNum + ""); $fact.eventBody.put("orderDate", "2015-03-30"); $fact.eventBody.put("orderID", randomNum + ""); $fact.eventBody.put("uid", randomNum + ""); $fact.eventBody.put("userIP", "151.235.656.121"); String mobilePhone = $fact.eventBody.get("mobilePhone") == null ? "" : $fact.eventBody.get("mobilePhone").toString(); String orderDate = $fact.eventBody.get("orderDate") == null ? "" : $fact.eventBody.get("orderDate").toString(); String orderId = $fact.eventBody.get("orderID") == null ? "" : $fact.eventBody.get("orderID").toString(); String uid = $fact.eventBody.get("uid") == null ? "" : $fact.eventBody.get("uid").toString(); String userIp = $fact.eventBody.get("userIP") == null ? "" : $fact.eventBody.get("userIP").toString(); $fact.results.clear(); //push to countServer Map kvData = ImmutableMap.of("mobilePhone", mobilePhone, "orderDate", orderDate, "orderId", orderId, "uid", uid, "userIp", userIp); //push to countServer Counter.push("0003", kvData); //???,?IP?>=5 BigDecimal count = ((FlowQueryResponse) Counter.queryFlowData("F0003001", "?IP?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count != null && count.longValue() >= 5) { emit($fact, 80, "???, , ?IP?[" + count.longValue() + "] >= 5"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } //???,?IPuid?>=3 BigDecimal count1 = ((FlowQueryResponse) Counter.queryFlowData("F0003001", "?IPuid?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count1 != null && count1.longValue() >= 3) { emit($fact, 80, "???, , ?IPuid?[" + count1.longValue() + "] >= 3"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } //???,?IP??>=3 BigDecimal count2 = ((FlowQueryResponse) Counter.queryFlowData("F0003001", "?IP?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count2 != null && count2.longValue() >= 3) { emit($fact, 80, "???, , ?IP?[" + count2.longValue() + "] >= 3"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } }
From source file:com.ctrip.infosec.rule.RuleTest.java
void R3() { RiskFact $fact = new RiskFact(); $fact.eventPoint = "CP0003001"; $fact.ext.put(Constants.key_ruleNo, "CP0003001"); //??orderID//from ww w .j av a 2 s . c o m Random random = new Random(); int randomNum = random.nextInt(10000000); $fact.eventBody.put("mobilePhone", randomNum + ""); $fact.eventBody.put("orderDate", "2015-03-30"); $fact.eventBody.put("orderID", randomNum + ""); $fact.eventBody.put("uid", "10001"); $fact.eventBody.put("userIP", randomNum + ""); String mobilePhone = $fact.eventBody.get("mobilePhone") == null ? "" : $fact.eventBody.get("mobilePhone").toString(); String orderDate = $fact.eventBody.get("orderDate") == null ? "" : $fact.eventBody.get("orderDate").toString(); String orderId = $fact.eventBody.get("orderID") == null ? "" : $fact.eventBody.get("orderID").toString(); String uid = $fact.eventBody.get("uid") == null ? "" : $fact.eventBody.get("uid").toString(); String userIp = $fact.eventBody.get("userIP") == null ? "" : $fact.eventBody.get("userIP").toString(); $fact.results.clear(); //push to countServer Map kvData = ImmutableMap.of("mobilePhone", mobilePhone, "orderDate", orderDate, "orderId", orderId, "uid", uid, "userIp", userIp); //push to countServer Counter.push("0003", kvData); //???,?IP?>=5 BigDecimal count = ((FlowQueryResponse) Counter.queryFlowData("F0003002", "?uid?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count != null && count.longValue() >= 8) { emit($fact, 80, "???, , ?uid?[" + count.longValue() + "] >= 8"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } //???,?IPuid?>=3 BigDecimal count1 = ((FlowQueryResponse) Counter.queryFlowData("F0003002", "?uidip?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count1 != null && count1.longValue() >= 3) { emit($fact, 80, "???, , ?uidip?[" + count1.longValue() + "] >= 3"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } //???,?IP??>=3 BigDecimal count2 = ((FlowQueryResponse) Counter.queryFlowData("F0003002", "?uid?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count2 != null && count2.longValue() >= 3) { emit($fact, 80, "???, , ?uid?[" + count2.longValue() + "] >= 3"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } }
From source file:com.ctrip.infosec.rule.RuleTest.java
void R4() { RiskFact $fact = new RiskFact(); $fact.eventPoint = "CP0003001"; $fact.ext.put(Constants.key_ruleNo, "CP0003001"); //??orderID/*from w ww.ja va 2 s.com*/ Random random = new Random(); int randomNum = random.nextInt(10000000); $fact.eventBody.put("mobilePhone", "13516896542"); $fact.eventBody.put("orderDate", "2015-03-30"); $fact.eventBody.put("orderID", randomNum + ""); $fact.eventBody.put("uid", randomNum + ""); $fact.eventBody.put("userIP", randomNum + ""); String mobilePhone = $fact.eventBody.get("mobilePhone") == null ? "" : $fact.eventBody.get("mobilePhone").toString(); String orderDate = $fact.eventBody.get("orderDate") == null ? "" : $fact.eventBody.get("orderDate").toString(); String orderId = $fact.eventBody.get("orderID") == null ? "" : $fact.eventBody.get("orderID").toString(); String uid = $fact.eventBody.get("uid") == null ? "" : $fact.eventBody.get("uid").toString(); String userIp = $fact.eventBody.get("userIP") == null ? "" : $fact.eventBody.get("userIP").toString(); $fact.results.clear(); //push to countServer Map kvData = ImmutableMap.of("mobilePhone", mobilePhone, "orderDate", orderDate, "orderId", orderId, "uid", uid, "userIp", userIp); //push to countServer Counter.push("0003", kvData); //???,?IP?>=5 BigDecimal count = ((FlowQueryResponse) Counter.queryFlowData("F0003003", "??", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count != null && count.longValue() >= 10) { emit($fact, 80, "???, , ??[" + count.longValue() + "] >= 10"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } //???,?IPuid?>=3 BigDecimal count1 = ((FlowQueryResponse) Counter.queryFlowData("F0003003", "?uid?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count1 != null && count1.longValue() >= 3) { emit($fact, 80, "???, , ?uid?[" + count1.longValue() + "] >= 3"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } //???,?IP??>=3 BigDecimal count2 = ((FlowQueryResponse) Counter.queryFlowData("F0003003", "?ip?", FlowAccuracy.EveryMin, "0,-1439", kvData)).getFlowData(); if (count2 != null && count2.longValue() >= 3) { emit($fact, 80, "???, , ?ip?[" + count2.longValue() + "] >= 3"); System.out.println("results: " + JSON.toPrettyJSONString($fact.results)); } }
From source file:com.abiquo.server.core.cloud.VirtualDatacenterDAO.java
public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int virtualDatacenterId) { Object[] vmResources = (Object[]) getSession().createSQLQuery(SUM_VM_RESOURCES) .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult(); Long cpu = vmResources[0] == null ? 0 : ((BigDecimal) vmResources[0]).longValue(); Long ram = vmResources[1] == null ? 0 : ((BigDecimal) vmResources[1]).longValue(); Long hd = vmResources[2] == null ? 0 : ((BigDecimal) vmResources[2]).longValue(); BigDecimal extraHd = (BigDecimal) getSession().createSQLQuery(SUM_EXTRA_HD_RESOURCES) .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult(); Long hdTot = extraHd == null ? hd : hd + extraHd.longValue() * 1024 * 1024; BigDecimal storage = (BigDecimal) getSession().createSQLQuery(SUM_VOLUMES_RESOURCES) .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult(); BigInteger publicIps = (BigInteger) getSession().createSQLQuery(COUNT_PUBLIC_IP_RESOURCES) .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult(); DefaultEntityCurrentUsed used = new DefaultEntityCurrentUsed(cpu.intValue(), ram, hdTot); // Storage usage is stored in MB used.setStorage(storage == null ? 0 : storage.longValue() * 1024 * 1024); used.setPublicIp(publicIps == null ? 0 : publicIps.longValue()); used.setVlanCount(getVLANUsage(virtualDatacenterId).size()); return used;// w w w . j a v a2 s.c om }
From source file:org.auraframework.components.test.java.controller.TestControllerLocalization.java
/** * Wait for delayMs milliseconds and then return a auratest:text component * whose value is the current buffer contents plus the current append. *///from w w w. ja va 2 s. c om @AuraEnabled public Component appendBuffer(@Key("id") String id, @Key("delayMs") BigDecimal delayMs, @Key("append") String append) throws Exception { StringBuffer buffer = buffers.get(id); buffer.append(append); long delay = delayMs.longValue(); if (delay > 0) { Thread.sleep(delay); } Map<String, Object> atts = ImmutableMap.of("value", (Object) (buffer + ".")); return instanceService.getInstance("auratest:text", ComponentDef.class, atts); }
From source file:com.fusesource.forge.jmstest.executor.BenchmarkJMSProducerWrapper.java
private void runProducers(long rate, long duration) { BigDecimal bd = new BigDecimal(1000000).divide(new BigDecimal(rate), BigDecimal.ROUND_HALF_DOWN); long delayInMicroSeconds; try {/*www . j ava 2 s .c om*/ delayInMicroSeconds = bd.longValueExact(); } catch (ArithmeticException e) { delayInMicroSeconds = bd.longValue(); log().warn("Publish rate cannot be expressed as a precise microsecond value, rounding to nearest value " + "[actualDelay: " + delayInMicroSeconds + "]"); } int producersNeeded = (int) (rate / getPartConfig().getMaxConsumerRatePerThread()); if (producersNeeded == 0) { producersNeeded++; } log.debug("Running " + producersNeeded + " producers for " + duration + "s"); producers = new ArrayList<BenchmarkProducer>(producersNeeded); sendingDelay = delayInMicroSeconds * producersNeeded; executor = new ScheduledThreadPoolExecutor(producersNeeded); for (int i = 0; i < producersNeeded; i++) { try { BenchmarkProducer producer = new BenchmarkProducer(this); producer.start(); producer.setMessageCounter(getProbe()); producers.add(producer); } catch (Exception e) { throw new BenchmarkConfigurationException("Unable to create BenchmarkProducer instance", e); } } for (BenchmarkProducer producer : producers) { // TODO should really hold onto these and monitor for failures until the // executor is shutdown executor.scheduleAtFixedRate(new MessageSender(producer), 0, sendingDelay, sendingDelayUnit); } final CountDownLatch latch = new CountDownLatch(1); new ScheduledThreadPoolExecutor(1).schedule(new Runnable() { public void run() { try { log.debug("Shutting down producers."); executor.shutdown(); for (BenchmarkProducer producer : producers) { try { producer.release(); } catch (Exception e) { log().error("Error releasing producer."); } } latch.countDown(); } catch (Exception e) { } } }, duration, TimeUnit.SECONDS); try { latch.await(); } catch (InterruptedException ie) { log().warn("Producer run has been interrupted ..."); } }