List of usage examples for java.math RoundingMode CEILING
RoundingMode CEILING
To view the source code for java.math RoundingMode CEILING.
Click Source Link
From source file:org.apache.gobblin.salesforce.SalesforceSource.java
/** * Compute the target partition size./*w ww. j a v a 2 s . co m*/ */ private int computeTargetPartitionSize(Histogram histogram, int minTargetPartitionSize, int maxPartitions) { return Math.max(minTargetPartitionSize, DoubleMath.roundToInt((double) histogram.totalRecordCount / maxPartitions, RoundingMode.CEILING)); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
@Override protected void setUp() throws Exception { super.setUp(); userContext = TestObjectFactory.getContext(); accountPersistence = new AccountPersistence(); savedInitialRoundOffMultiple = AccountingRules.getInitialRoundOffMultiple(); savedFinalRoundOffMultiple = AccountingRules.getFinalRoundOffMultiple(); savedCurrencyRoundingMode = AccountingRules.getCurrencyRoundingMode(); savedDigitAfterDecimal = AccountingRules.getDigitsAfterDecimal(); savedInitialRoundingMode = AccountingRules.getInitialRoundingMode(); savedFinalRoundingMode = AccountingRules.getFinalRoundingMode(); AccountingRules.setInitialRoundOffMultiple(new BigDecimal("1")); AccountingRules.setFinalRoundOffMultiple(new BigDecimal("1")); AccountingRules.setCurrencyRoundingMode(RoundingMode.CEILING); AccountingRules.setInitialRoundingMode(RoundingMode.CEILING); AccountingRules.setFinalRoundingMode(RoundingMode.CEILING); AccountingRules.setDigitsAfterDecimal((short) 1); loanDao = new LoanDao(); }
From source file:com.meltmedia.dropwizard.etcd.cluster.ClusterAssignmentIT.java
@Test public void shouldBlueGreenDeployWithNewServices() throws InterruptedException { int processCount = 20; for (int i = 0; i < processCount; i++) { dao.put("id" + i, processNode(null, "name" + i)); }/*from w w w. j av a2s .c o m*/ int halfFloorCount = IntMath.divide(processCount, 2, RoundingMode.FLOOR); int halfCeilCount = IntMath.divide(processCount, 2, RoundingMode.CEILING); ClusterNode node0 = new ClusterNode().withId("node0").withStartedAt(new DateTime()); MetricRegistry registry = new MetricRegistry(); ClusterService currentClusterService = ClusterService.builder().withEtcdFactory(factoryRule.getFactory()) .withExecutor(executor).withNodesDirectory(nodeDir).withThisNode(node0).withMetricRegistry(registry) .build(); currentClusterService.start(); ProcessService<ObjectNode> currentProcessService = currentClusterService.newProcessService(processDir, ClusterAssignmentIT::toLifecycle, new TypeReference<ObjectNode>() { }); currentProcessService.start(); assertState("only green running", s -> s.assignments("node0") == processCount); for (int i = 1; i < 4; i++) { ClusterNode nextNode = new ClusterNode().withId("node" + i).withStartedAt(new DateTime()); MetricRegistry nextRegistry = new MetricRegistry(); ClusterService nextClusterService = ClusterService.builder().withEtcdFactory(factoryRule.getFactory()) .withExecutor(executor).withNodesDirectory(nodeDir).withThisNode(nextNode) .withMetricRegistry(nextRegistry).build(); nextClusterService.start(); ProcessService<ObjectNode> nextProcessService = nextClusterService.newProcessService(processDir, ClusterAssignmentIT::toLifecycle, new TypeReference<ObjectNode>() { }); nextProcessService.start(); assertState( "blue and green running", s -> s.maxAssignments() == halfCeilCount && s.minAssignments() == halfFloorCount && s.unassigned() == 0, s -> s.unassigned() > 1); final Runnable stopProcess = currentProcessService::stop; final Runnable stopClusterService = currentClusterService::stop; executor.schedule(() -> { stopProcess.run(); stopClusterService.run(); }, 1, TimeUnit.MILLISECONDS); assertState("blue now green", s -> s.assignments(nextProcessService.getId()) == processCount, s -> s.unassigned() > 1); currentProcessService = nextProcessService; currentClusterService = nextClusterService; } currentProcessService.stop(); currentClusterService.stop(); assertState("all stopped", s -> s.unassigned() == processCount); }
From source file:jp.furplag.util.commons.NumberUtilsTest.java
/** * {@link jp.furplag.util.commons.NumberUtils#ceil(java.lang.Object)}. *//*w ww . j a v a 2s .c om*/ @Test public void testCeilObject() { assertEquals("null", null, ceil((Object) null)); assertEquals("null", null, ceil("")); assertEquals("null", null, ceil("not a number.")); assertEquals("PI: Float: ", 4f, ceil("3.141592653589793f")); assertEquals("PI: Double: ", 4d, ceil("3.141592653589793d")); assertEquals("PI: BigDecimal: ", BigDecimal.valueOf(Math.PI).setScale(0, RoundingMode.CEILING), ceil((Object) BigDecimal.valueOf(Math.PI))); }
From source file:jp.furplag.util.commons.NumberUtils.java
/** * {@link java.lang.Math#ceil(double)}.//from w ww . j a v a2s . co m * * @param o the object, number or string. * @param scale scale of fraction. * @param type return type. * @return {@code ceil(o)}. Return null if o could not convertible to number. */ public static <T extends Number> T ceil(final Object o, final Number scale, final Class<T> type) { return setScale(o, scale, RoundingMode.CEILING, type); }
From source file:org.yes.cart.payment.impl.PostFinancePaymentGatewayImpl.java
private void populateItems(final Payment payment, final Map<String, String> params) { BigDecimal totalItemsGross = Total.ZERO; for (final PaymentLine item : payment.getOrderItems()) { totalItemsGross = totalItemsGross.add(item.getQuantity().multiply(item.getUnitPrice())); }// www . j a v a2 s .c o m final int it = payment.getOrderItems().size(); BigDecimal orderDiscountRemainder = Total.ZERO; BigDecimal orderDiscountPercent = Total.ZERO; final BigDecimal payGross = payment.getPaymentAmount(); if (payGross.compareTo(totalItemsGross) < 0) { orderDiscountRemainder = totalItemsGross.subtract(payGross); orderDiscountPercent = orderDiscountRemainder.divide(totalItemsGross, 10, RoundingMode.HALF_UP); } int i = 1; boolean hasOrderDiscount = MoneyUtils.isFirstBiggerThanSecond(orderDiscountRemainder, Total.ZERO); for (final PaymentLine item : payment.getOrderItems()) { final BigDecimal itemGrossAmount = item.getUnitPrice().multiply(item.getQuantity()) .setScale(Total.ZERO.scale(), RoundingMode.HALF_UP); params.put("ITEMID" + i, item.getSkuCode().length() > ITEMID ? item.getSkuCode().substring(0, ITEMID - 1) + "~" : item.getSkuCode()); params.put("ITEMNAME" + i, item.getSkuName().length() > ITEMNAME ? item.getSkuName().substring(0, ITEMNAME - 1) + "~" : item.getSkuName()); params.put("ITEMQUANT" + i, item.getQuantity().toPlainString()); if (hasOrderDiscount && MoneyUtils.isFirstBiggerThanSecond(orderDiscountRemainder, Total.ZERO) && MoneyUtils.isFirstBiggerThanSecond(itemGrossAmount, Total.ZERO)) { BigDecimal discount; if (i == it) { // last item discount = orderDiscountRemainder; } else { BigDecimal itemDiscount = itemGrossAmount.multiply(orderDiscountPercent) .setScale(Total.ZERO.scale(), RoundingMode.CEILING); if (MoneyUtils.isFirstBiggerThanSecond(orderDiscountRemainder, itemDiscount)) { discount = itemDiscount; orderDiscountRemainder = orderDiscountRemainder.subtract(itemDiscount); } else { discount = orderDiscountRemainder; orderDiscountRemainder = Total.ZERO; } } final BigDecimal scaleRate = discount.divide(itemGrossAmount.subtract(discount), 10, RoundingMode.CEILING); final BigDecimal scaledTax = item.getTaxAmount().multiply(scaleRate).setScale(Total.ZERO.scale(), RoundingMode.FLOOR); params.put("ITEMDISCOUNT" + i, discount.toPlainString()); params.put("ITEMPRICE" + i, itemGrossAmount.subtract(discount).subtract(item.getTaxAmount()) .add(scaledTax).toPlainString()); params.put("ITEMVAT" + i, item.getTaxAmount().subtract(scaledTax).toPlainString()); } else { params.put("ITEMPRICE" + i, itemGrossAmount.subtract(item.getTaxAmount()).toPlainString()); params.put("ITEMVAT" + i, item.getTaxAmount().toPlainString()); } i++; } }
From source file:org.mifos.config.AccountingRulesIntegrationTest.java
@Test public void testGetRoundingRule() { RoundingMode defaultValue = RoundingMode.CEILING; String roundingMode = "FLOOR"; RoundingMode configRoundingMode = RoundingMode.FLOOR; ConfigurationManager configMgr = ConfigurationManager.getInstance(); configMgr.addProperty(AccountingRulesConstants.ROUNDING_RULE, roundingMode); // return value from accounting rules class has to be the value defined // in the config file Assert.assertEquals(configRoundingMode, AccountingRules.getRoundingRule(defaultValue)); // clear the RoundingRule property from the config file configMgr.clearProperty(AccountingRulesConstants.ROUNDING_RULE); // now the return value from accounting rules class has to be the // default value (value from db) Assert.assertEquals(defaultValue, AccountingRules.getRoundingRule(defaultValue)); // now set a wrong rounding mode in config roundingMode = "UP"; configMgr.addProperty(AccountingRulesConstants.ROUNDING_RULE, roundingMode); try {/*w w w . j av a 2 s .co m*/ AccountingRules.getRoundingRule(defaultValue); } catch (RuntimeException e) { Assert.assertEquals(e.getMessage(), "The rounding mode defined in the config file is not CEILING, FLOOR, HALF_UP. It is " + roundingMode); } configMgr.clearProperty(AccountingRulesConstants.ROUNDING_RULE); }
From source file:com.qcadoo.mes.operationTimeCalculations.OrderRealizationTimeServiceImpl.java
@Override public int evaluateOperationDurationOutOfCycles(final BigDecimal cycles, final Entity operationComponent, final Entity productionLine, final boolean maxForWorkstation, final boolean includeTpz, final boolean includeAdditionalTime) { boolean isTjDivisable = operationComponent.getBooleanField("isTjDivisible"); Integer workstationsCount = retrieveWorkstationTypesCount(operationComponent, productionLine); BigDecimal cyclesPerOperation = cycles; if (maxForWorkstation) { cyclesPerOperation = cycles.divide(BigDecimal.valueOf(workstationsCount), numberService.getMathContext()); if (!isTjDivisable) { cyclesPerOperation = cyclesPerOperation.setScale(0, RoundingMode.CEILING); }/*from ww w .jav a2 s . c om*/ } int tj = getIntegerValue(operationComponent.getField("tj")); int operationTime = cyclesPerOperation.multiply(BigDecimal.valueOf(tj), numberService.getMathContext()) .intValue(); if (includeTpz) { int tpz = getIntegerValue(operationComponent.getField("tpz")); operationTime += (maxForWorkstation ? tpz : (tpz * workstationsCount)); } if (includeAdditionalTime) { int additionalTime = getIntegerValue(operationComponent.getField("timeNextOperation")); operationTime += (maxForWorkstation ? additionalTime : (additionalTime * workstationsCount)); } return operationTime; }
From source file:ca.osmcanada.osvuploadr.JPMain.java
private long getSequence(ImageProperties imp, String accessToken) { try {/* w ww . j a va 2 s . c o m*/ URL url = new URL(URL_SEQUENCE); URLConnection con = url.openConnection(); HttpURLConnection http = (HttpURLConnection) con; http.setRequestMethod("POST"); // PUT is another valid option http.setDoOutput(true); DecimalFormat df = new DecimalFormat("#.##############"); df.setRoundingMode(RoundingMode.CEILING); System.out.println("Getting Sequence ID.."); Map<String, String> arguments = new HashMap<>(); arguments.put("uploadSource", "OSVUploadr"); arguments.put("access_token", accessToken); arguments.put("currentCoordinate", df.format(imp.getLatitude()) + "," + df.format(imp.getLongitude())); System.out.println( "currentCoordinate:" + df.format(imp.getLatitude()) + "," + df.format(imp.getLongitude())); StringJoiner sj = new StringJoiner("&"); for (Map.Entry<String, String> entry : arguments.entrySet()) sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + URLEncoder.encode(entry.getValue(), "UTF-8")); byte[] out = sj.toString().getBytes(StandardCharsets.UTF_8); int length = out.length; System.out.println("Sending request:" + sj.toString()); http.setFixedLengthStreamingMode(length); http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); http.connect(); try (OutputStream os = http.getOutputStream()) { os.write(out); os.close(); } System.out.println("Request Sent getting sequence response..."); InputStream is = http.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte buf[] = new byte[1024]; int letti; while ((letti = is.read(buf)) > 0) baos.write(buf, 0, letti); String data = new String(baos.toByteArray()); int start = data.indexOf("\"osv\":{\"sequence\":{\"id\":\""); int end = data.indexOf("\"", start + 25); System.out.println("Received request:" + data); String sequence_id = data.substring(start + 25, end); System.out.println("Obtained Sequence ID: sequence_id"); http.disconnect(); return Long.parseLong(sequence_id); } catch (Exception ex) { System.out.println(ex.toString()); Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex); } return -1; }
From source file:org.egov.ptis.service.utils.PropertyTaxCommonUtils.java
public String formatAmount(BigDecimal tax) { tax = tax.setScale(0, RoundingMode.CEILING); return NumberUtil.formatNumber(tax); }