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.opengamma.financial.property.DefaultPropertyFunctionsTest.java
private SimplePosition createPosition(final SecuritySource securities) { final SimplePosition position = new SimplePosition(); position.setQuantity(BigDecimal.ONE); position.setSecurityLink(createSecurityLink(securities)); return position; }
From source file:org.yes.cart.web.support.service.impl.ProductServiceFacadeImplTest.java
@Test public void testGetSkuPriceSearchAndProductDetailsNoPriceB2B() throws Exception { final PriceService priceService = context.mock(PriceService.class, "priceService"); final PricingPolicyProvider pricingPolicyProvider = context.mock(PricingPolicyProvider.class, "pricingPolicyProvider"); final ShopService shopService = context.mock(ShopService.class, "shopService"); final ShoppingCart cart = context.mock(ShoppingCart.class, "cart"); final ShoppingContext cartCtx = context.mock(ShoppingContext.class, "cartCtx"); final PricingPolicyProvider.PricingPolicy policy = context.mock(PricingPolicyProvider.PricingPolicy.class, "policy"); final Shop b2b = context.mock(Shop.class, "b2b"); context.checking(new Expectations() { {/*from w w w. j a v a 2s.co m*/ allowing(cart).getShoppingContext(); will(returnValue(cartCtx)); allowing(cartCtx).getShopId(); will(returnValue(234L)); allowing(cartCtx).getCustomerShopId(); will(returnValue(345L)); allowing(cartCtx).getShopCode(); will(returnValue("SHOP10")); allowing(cartCtx).getCountryCode(); will(returnValue("GB")); allowing(cartCtx).getStateCode(); will(returnValue("GB-LON")); allowing(cart).getCustomerEmail(); will(returnValue("bob@doe.com")); allowing(cart).getCurrencyCode(); will(returnValue("EUR")); allowing(pricingPolicyProvider).determinePricingPolicy("SHOP10", "EUR", "bob@doe.com", "GB", "GB-LON"); will(returnValue(policy)); allowing(policy).getID(); will(returnValue("P1")); allowing(priceService).getMinimalPrice(123L, "ABC", 345L, 234L, "EUR", BigDecimal.ONE, false, "P1"); will(returnValue(null)); allowing(shopService).getById(345L); will(returnValue(b2b)); allowing(b2b).isB2BStrictPriceActive(); will(returnValue(false)); } }); final ProductServiceFacade facade = new ProductServiceFacadeImpl(null, null, null, null, null, null, pricingPolicyProvider, priceService, null, null, null, shopService, null); final ProductPriceModel model = facade.getSkuPrice(cart, 123L, "ABC", BigDecimal.ONE); assertNotNull(model); assertNull(model.getRef()); assertEquals("EUR", model.getCurrency()); assertNull(model.getQuantity()); assertNull(model.getRegularPrice()); assertNull(model.getSalePrice()); assertFalse(model.isTaxInfoEnabled()); assertFalse(model.isTaxInfoUseNet()); assertFalse(model.isTaxInfoShowAmount()); assertNull(model.getPriceTaxCode()); assertNull(model.getPriceTaxRate()); assertFalse(model.isPriceTaxExclusive()); assertNull(model.getPriceTax()); context.assertIsSatisfied(); }
From source file:com.acc.fulfilmentprocess.test.PaymentIntegrationTest.java
protected OrderModel placeTestOrder(final boolean valid) throws InvalidCartException, CalculationException { final CartModel cart = cartService.getSessionCart(); final UserModel user = userService.getCurrentUser(); cartService.addNewEntry(cart, productService.getProductForCode("testProduct1"), 1, null); cartService.addNewEntry(cart, productService.getProductForCode("testProduct2"), 2, null); cartService.addNewEntry(cart, productService.getProductForCode("testProduct3"), 3, null); final AddressModel deliveryAddress = new AddressModel(); deliveryAddress.setOwner(user);// www.j av a2 s .c o m deliveryAddress.setFirstname("Der"); deliveryAddress.setLastname("Buck"); deliveryAddress.setTown("Muenchen"); deliveryAddress.setCountry(commonI18NService.getCountry("DE")); modelService.save(deliveryAddress); final DebitPaymentInfoModel paymentInfo = new DebitPaymentInfoModel(); paymentInfo.setOwner(cart); paymentInfo.setBank("MeineBank"); paymentInfo.setUser(user); paymentInfo.setAccountNumber("34434"); paymentInfo.setBankIDNumber("1111112"); paymentInfo.setBaOwner("Ich"); paymentInfo.setCode("testPaymentInfo1"); modelService.save(paymentInfo); cart.setDeliveryMode(deliveryService.getDeliveryModeForCode("free")); cart.setDeliveryAddress(deliveryAddress); cart.setPaymentInfo(paymentInfo); final CardInfo card = new CardInfo(); card.setCardType(CreditCardType.VISA); card.setCardNumber("4111111111111111"); card.setExpirationMonth(Integer.valueOf(12)); if (valid) { card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 2)); } else { card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) - 2)); } final PaymentTransactionModel paymentTransaction = paymentService.authorize("code4" + codeNo++, BigDecimal.ONE, Currency.getInstance("EUR"), deliveryAddress, deliveryAddress, card) .getPaymentTransaction(); cart.setPaymentTransactions(Collections.singletonList(paymentTransaction)); modelService.save(cart); calculationService.calculate(cart); return commerceCheckoutService.placeOrder(cart); }
From source file:net.pms.util.Rational.java
/** * Returns an instance by parsing the specified {@link String}. The format * must be either {@code number/number}, {@code number:number} or * {@code number}. Signs are understood for both numerator and denominator. * If {@code value} is blank or {@code null}, {@code null} is returned. If * {@code value} can't be parsed, a {@link NumberFormatException} is thrown. * * @param value the {@link String} value to parse. * @param numberFormat the {@link NumberFormat} to use when parsing numbers. * If {@code null} or not an instance of {@link DecimalFormat}, * "standard formatted" numbers are expected (no grouping, * {@code .} as decimal separator etc.). * @return An instance that represents the value of {@code value}. * @throws NumberFormatException If {@code value} cannot be parsed. *//* www . j a va 2 s . c o m*/ @Nullable public static Rational valueOf(@Nullable String value, @Nullable NumberFormat numberFormat) { if (StringUtils.isBlank(value)) { return null; } String[] numbers = value.trim().split("\\s*(?:/|:)\\s*", 2); DecimalFormat decimalFormat = numberFormat instanceof DecimalFormat ? (DecimalFormat) numberFormat : null; BigDecimal decimalNumerator = parseBigDecimal(numbers[0], decimalFormat); if (decimalNumerator == null) { return null; } BigDecimal decimalDenominator; if (numbers.length > 1) { decimalDenominator = parseBigDecimal(numbers[1], decimalFormat); } else { decimalDenominator = BigDecimal.ONE; } if (decimalDenominator == null) { return null; } return valueOf(decimalNumerator, decimalDenominator); }
From source file:org.openhab.binding.denon.internal.DenonConnector.java
private String toDenonValue(BigDecimal percent) { // Round to nearest number divisible by 0.5 percent = percent.divide(POINTFIVE).setScale(0, RoundingMode.UP).multiply(POINTFIVE) .min(connection.getMainVolumeMax()).max(BigDecimal.ZERO); String dbString = String.valueOf(percent.intValue()); if (percent.compareTo(BigDecimal.TEN) == -1) { dbString = "0" + dbString; }//from www . j a v a 2s. c o m if (percent.remainder(BigDecimal.ONE).equals(POINTFIVE)) { dbString = dbString + "5"; } return dbString; }
From source file:org.libreplan.business.planner.entities.StretchesFunction.java
private BigDecimal calculateLeftFor(BigDecimal sumOfProportions) { BigDecimal left = BigDecimal.ONE.subtract(sumOfProportions); left = left.signum() <= 0 ? BigDecimal.ZERO : left; return left;/*from w w w . ja v a 2 s . c o m*/ }
From source file:org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement.java
private BigDecimal getAvancement(SQLRowAccessor r) { Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("ECHEANCE_CLIENT")); long totalEch = 0; for (SQLRowAccessor row : rows) { if (!row.getBoolean("REGLE") && !row.getBoolean("REG_COMPTA")) { totalEch += row.getLong("MONTANT"); }/*from www .j av a2 s .c o m*/ } SQLRowAccessor avoir = r.getForeign("ID_AVOIR_CLIENT"); BigDecimal avoirTTC = BigDecimal.ZERO; if (avoir != null && !avoir.isUndefined()) { avoirTTC = new BigDecimal(avoir.getLong("MONTANT_TTC")); } final BigDecimal totalAregler = new BigDecimal(r.getLong("T_TTC")).subtract(avoirTTC); if (totalAregler.signum() > 0 && totalEch > 0) { return totalAregler.subtract(new BigDecimal(totalEch)).divide(totalAregler, MathContext.DECIMAL128) .movePointRight(2).setScale(2, RoundingMode.HALF_UP); } else { return BigDecimal.ONE.movePointRight(2); } }
From source file:com.opengamma.web.analytics.blotter.OtcTradeBuilderTest.java
/** * directly update a position that has no trades *///from w w w .j a v a 2 s . co m @Test public void updatePositionWithNoTrade() { ManageableSecurity security = _securityMaster.add(new SecurityDocument(BlotterTestUtils.FX_FORWARD)) .getSecurity(); ManageablePosition position = new ManageablePosition(); position.setQuantity(BigDecimal.ONE); position.setSecurityLink(new ManageableSecurityLink(security.getUniqueId())); ManageablePosition savedPosition = _positionMaster.add(new PositionDocument(position)).getPosition(); BeanDataSource updatedTradeData = createTradeData("counterparty", "updatedCounterparty", "tradeDate", "2012-12-22", "premium", "4321"); BeanDataSource updatedSecurityData = BlotterTestUtils.overrideBeanData( BlotterTestUtils.FX_FORWARD_DATA_SOURCE, "payCurrency", "AUD", "payAmount", "200"); _builder.updatePosition(savedPosition.getUniqueId(), updatedTradeData, updatedSecurityData, null); ManageablePosition loadedPosition = _positionMaster.get(savedPosition.getUniqueId()).getPosition(); assertEquals(1, loadedPosition.getTrades().size()); ManageableTrade trade = loadedPosition.getTrades().get(0); assertEquals("updatedCounterparty", trade.getCounterpartyExternalId().getValue()); assertEquals(LocalDate.of(2012, 12, 22), trade.getTradeDate()); assertEquals(4321d, trade.getPremium()); FXForwardSecurity updatedSecurity = (FXForwardSecurity) _securityMaster .get(trade.getSecurityLink().getObjectId(), VersionCorrection.LATEST).getSecurity(); assertEquals(Currency.AUD, updatedSecurity.getPayCurrency()); assertEquals(200d, updatedSecurity.getPayAmount()); }
From source file:org.multibit.utils.CSMiscUtils.java
public static BigInteger getRawUnitsFromDisplayString(CSAsset asset, String display) { BigDecimal result = null;//from ww w. jav a2 s . co m try { //System.out.println("Start to get raw units from: " + display); result = new BigDecimal(display); } catch (NumberFormatException nfe) { nfe.printStackTrace(); return null; } // Reverse apply the multiple int decimalPlaces = CSMiscUtils.getNumberOfDisplayDecimalPlaces(asset); if (decimalPlaces != 0) { result = result.movePointRight(decimalPlaces); } // FIXME: what if multiple is 0.0? ignore? error? // double multiple = asset.getMultiple(); // BigDecimal m = new BigDecimal(String.valueOf(multiple)); // result = result.divide(m, MathContext.DECIMAL32); //System.out.println("multiplier=" + m + ", removed multiplier =" + display); double interestRate = asset.getInterestRate(); BigDecimal rate = new BigDecimal(String.valueOf(interestRate)); rate = rate.divide(new BigDecimal(100)); rate = rate.add(BigDecimal.ONE); Date issueDate = asset.getIssueDate(); DateTime d1 = new DateTime(issueDate); DateTime d2 = new DateTime(); int seconds = Math.abs(Seconds.secondsBetween(d1, d2).getSeconds()); //System.out.println("...Number of seconds difference: " + seconds); BigDecimal elapsedSeconds = new BigDecimal(seconds); BigDecimal elapsedYears = elapsedSeconds.divide(new BigDecimal(COINSPARK_SECONDS_IN_YEAR), MathContext.DECIMAL32); //System.out.println("...Number of years difference: " + elapsedYears.toPlainString()); double base = elapsedSeconds.doubleValue(); double exp = elapsedYears.doubleValue(); //System.out.println("...base=" + base + " exponent=" + exp); double interestMultipler = Math.pow(rate.doubleValue(), elapsedYears.doubleValue()); //System.out.println("interest multipler =" + interestMultipler); result = result.divide(new BigDecimal(String.valueOf(interestMultipler)), MathContext.DECIMAL32); //System.out.println("result = " + result.toPlainString()); result = result.setScale(0, RoundingMode.DOWN); result = result.stripTrailingZeros(); //System.out.println("result floored = " + result.toPlainString()); String resultString = result.toPlainString(); return new BigInteger(resultString); }
From source file:pe.gob.mef.gescon.web.ui.AlertaMB.java
public void activar(ActionEvent event) { try {/*from w w w.j a v a 2 s. com*/ if (event != null) { if (this.getSelectedAlerta() != null) { LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); AlertaService service = (AlertaService) ServiceFinder.findBean("AlertaService"); this.getSelectedAlerta().setNactivo(BigDecimal.ONE); this.getSelectedAlerta().setDfechamodificacion(new Date()); this.getSelectedAlerta().setVusuariomodificacion(user.getVlogin()); service.saveOrUpdate(this.getSelectedAlerta()); this.setListaAlerta(service.getAlertas()); } else { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA, "Debe seleccionar la alerta a activar."); FacesContext.getCurrentInstance().addMessage(null, message); } } } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } }