List of usage examples for java.math BigDecimal ONE
BigDecimal ONE
To view the source code for java.math BigDecimal ONE.
Click Source Link
From source file:com.ikanow.aleph2.data_model.utils.TestJsonUtils.java
@Test public void test_foldTuple() { final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); LinkedHashMap<String, Object> test1 = new LinkedHashMap<String, Object>(); test1.put("long", 10L); test1.put("double", 1.1); test1.put("string", "val"); test1.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); final JsonNode j1 = JsonUtils.foldTuple(test1, mapper, Optional.empty()); assertEquals("{\"misc\":true,\"long\":10,\"string\":\"val\",\"double\":1.1}", j1.toString()); LinkedHashMap<String, Object> test2 = new LinkedHashMap<String, Object>(); test2.put("misc", false); test2.put("long", 10L); test2.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); test2.put("double", 1.1); test2.put("string", "val"); final JsonNode j2 = JsonUtils.foldTuple(test2, mapper, Optional.of("json")); assertEquals("{\"misc\":false,\"long\":10,\"string\":\"val\",\"double\":1.1}", j2.toString()); LinkedHashMap<String, Object> test3 = new LinkedHashMap<String, Object>(); test3.put("long", mapper.createObjectNode()); test3.put("double", mapper.createArrayNode()); test3.put("string", BeanTemplateUtils.build(TestBean.class).with("test1", 4).done().get()); test3.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); final JsonNode j3 = JsonUtils.foldTuple(test3, mapper, Optional.of("json")); assertEquals("{\"misc\":true,\"long\":{},\"string\":{\"test1\":4},\"double\":[]}", j3.toString()); LinkedHashMap<String, Object> test4 = new LinkedHashMap<String, Object>(); test4.put("misc", BigDecimal.ONE); test4.put("long", (int) 10); test4.put("double", (float) 1.1); test4.put("json", "{\"misc\":true,\"long\":1, \"string\":\"\"}"); test4.put("string", "val"); final JsonNode j4 = JsonUtils.foldTuple(test4, mapper, Optional.of("json")); assertEquals("{\"misc\":1,\"long\":10,\"string\":\"val\",\"double\":1.1}", j4.toString().replaceFirst("1[.]1[0]{6,}[0-9]+", "1.1")); try {// ww w .ja v a2 s . c om test4.put("json", "{\"misc\":true,\"long\":1, string\":\"\"}"); // (Added json error) JsonUtils.foldTuple(test4, mapper, Optional.of("json")); fail("Should have thrown JSON exception"); } catch (Exception e) { } // json error, check new JsonUtils(); // (just for coverage) }
From source file:engine.Pi.java
/** * Compute the value, in radians, of the arctangent of * the inverse of the supplied integer to the specified * number of digits after the decimal point. The value * is computed using the power series expansion for the * arc tangent:/*from w w w . j a v a 2s .c o m*/ * * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + * (x^9)/9 ... */ public static BigDecimal arctan(int inverseX, int scale) { BigDecimal result, numer, term; BigDecimal invX = BigDecimal.valueOf(inverseX); BigDecimal invX2 = BigDecimal.valueOf(inverseX * inverseX); numer = BigDecimal.ONE.divide(invX, scale, roundingMode); result = numer; int i = 1; do { numer = numer.divide(invX2, scale, roundingMode); int denom = 2 * i + 1; term = numer.divide(BigDecimal.valueOf(denom), scale, roundingMode); if ((i % 2) != 0) { result = result.subtract(term); } else { result = result.add(term); } i++; } while (term.compareTo(BigDecimal.ZERO) != 0); return result; }
From source file:org.osiam.resource_server.storage.helper.NumberPadder.java
/** * Removes the offset and padding from a number * * @param value/* w ww. j a v a 2s.c o m*/ * the padded number as {@link String} * @return the number decreased by offset and leading '0's removed */ public String unpad(String value) { BigDecimal decimalValue = new BigDecimal(value); BigDecimal returnDecimalValue = new BigDecimal(decimalValue.toBigInteger().subtract(BIG_OFFSET)); BigDecimal signum = new BigDecimal(returnDecimalValue.signum()); BigDecimal fractionalPart = decimalValue.remainder(BigDecimal.ONE).multiply(signum); returnDecimalValue = returnDecimalValue.add(fractionalPart); return returnDecimalValue.toString(); }
From source file:org.openlmis.fulfillment.web.OrderNumberConfigurationControllerIntegrationTest.java
@Before public void setUp() { this.setUpBootstrapData(); ProgramDto programDto = new ProgramDto(); programDto.setId(UUID.fromString("35316636-6264-6331-2d34-3933322d3462")); programDto.setCode("code"); Order order = new Order(); order.setId(UUID.randomUUID()); order.setExternalId(UUID.randomUUID()); order.setEmergency(true);/*w ww . j a v a 2 s. c o m*/ order.setFacilityId(facility); order.setProcessingPeriodId(UUID.fromString("a510d22f-f370-46c7-88e2-981573c427f5")); order.setCreatedById(UUID.randomUUID()); order.setProgramId(programDto.getId()); order.setRequestingFacilityId(facility); order.setReceivingFacilityId(facility); order.setSupplyingFacilityId(facility); order.setOrderCode("order_code"); order.setStatus(OrderStatus.ORDERED); order.setQuotedCost(BigDecimal.ONE); firstOrderNumberConfiguration = new OrderNumberConfiguration("prefix", true, true, true); secondOrderNumberConfiguration = new OrderNumberConfiguration("prefix", false, false, false); given(orderRepository.findOne(order.getId())).willReturn(order); given(orderRepository.exists(order.getId())).willReturn(true); given(orderNumberConfigurationRepository.save(any(OrderNumberConfiguration.class))) .willAnswer(new SaveAnswer<OrderNumberConfiguration>()); }
From source file:org.yes.cart.shoppingcart.impl.AddSkuToWishListEventCommandImpl.java
private BigDecimal getQuantityValue(final Map parameters) { final Object strQty = parameters.get(CMD_ADDTOWISHLIST_P_QTY); if (strQty instanceof String) { try {/* w w w.ja v a 2 s . c om*/ return new BigDecimal((String) strQty); } catch (Exception exp) { ShopCodeContext.getLog(this).error("Invalid quantity in add to cart command", exp); } } return BigDecimal.ONE; // if no parameter specified assume 1 unit }
From source file:org.excalibur.discovery.jackson.databind.test.JsonYamlObjectMapperTest.java
public void must_create_an_valid_yaml_only_with_applications() throws Exception { ApplicationDescriptor description = new ApplicationDescriptor(UUID.randomUUID().toString()).setName("sw"); description.setRequirements(new Requirements().setMaximalCostPerHour(BigDecimal.ONE).setMemorySize(4) .setNumberOfCpuCores(4).setPlatform(Platform.LINUX)); description.setUser(new User().setUsername("user")); marshallAndUnmarshall(description);/*w ww. j a v a2s . c o m*/ }
From source file:pe.gob.mef.gescon.hibernate.impl.CategoriaDaoImpl.java
@Override public List<Mtcategoria> getMtcategoriaHijos(Mtcategoria mtcategoria) throws Exception { DetachedCriteria criteria = DetachedCriteria.forClass(Mtcategoria.class); criteria.add(Restrictions.eq("ncategoriasup", mtcategoria.getNcategoriaid())); criteria.add(Restrictions.eq("nestado", BigDecimal.ONE)); criteria.addOrder(Order.asc("nnivel")); criteria.addOrder(Order.asc("ncategoriaid")); return (List<Mtcategoria>) getHibernateTemplate().findByCriteria(criteria); }
From source file:pe.gob.mef.gescon.hibernate.impl.UserDaoImpl.java
@Override public List<Mtuser> getMtuserActivedByPerfil(BigDecimal perfil) throws Exception { DetachedCriteria criteria = DetachedCriteria.forClass(Mtuser.class); criteria.add(Restrictions.eq("nactivo", BigDecimal.ONE)); criteria.add(Restrictions.eq("nperfilid", perfil)); return (List<Mtuser>) getHibernateTemplate().findByCriteria(criteria); }
From source file:io.silverware.microservices.monitoring.MetricsManager.java
/** * Method responsible for adding new time to values collection and also updating min, max, avg and count metrics. * * @param elapsedTime/*from ww w .j a v a 2s.c o m*/ * runtime of microservice method. */ public void addTime(BigDecimal elapsedTime) { if (elapsedTime.compareTo(BigDecimal.ZERO) <= 0) { throw new IllegalArgumentException("Elapsed time is negative or zero"); } mapValues.put(longAdder.longValue(), elapsedTime); longAdder.increment(); final BigDecimal count = new BigDecimal(metrics.getCount()); final BigDecimal averageTime = metrics.getAverageTime(); final BigDecimal minTime = metrics.getMinTime(); final BigDecimal maxTime = metrics.getMaxTime(); metrics.incrementCount(); metrics.setAverageTime((averageTime.multiply(count).add(elapsedTime)).divide(count.add(BigDecimal.ONE), BigDecimal.ROUND_HALF_UP)); if (elapsedTime.compareTo(maxTime) >= 1) { metrics.setMaxTime(elapsedTime); } else { metrics.setMinTime(elapsedTime); } }
From source file:InvestmentTest.java
@Test public void usd() throws ParseException { MoneyAmount oneDollar = new MoneyAmount(BigDecimal.ONE, "USD"); MoneyAmount oneUSDIn1951PurchasingPower = Inflation.USD_INFLATION.adjust(oneDollar, 2016, 5, 1951, 9); MoneyAmount oneUSDIn1951PurchasingPowerInPesos = ForeignExchanges.getForeignExchange("USD", "ARS") .exchange(oneUSDIn1951PurchasingPower, "ARS", 2016, 5); MoneyAmount pesosBackThen = Inflation.ARS_INFLATION.adjust(oneUSDIn1951PurchasingPowerInPesos, 2016, 5, 1951, 9);//from w ww . j a v a2 s.c o m }