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:org.yes.cart.web.support.service.impl.ProductServiceFacadeImplTest.java
@Test public void testGetSkuPriceSearchAndProductDetailsPriceListOnlyNoTaxInfo() 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 SkuPrice skuPrice = context.mock(SkuPrice.class, "skuPrice"); final Shop shop = context.mock(Shop.class, "shop"); context.checking(new Expectations() { {//from ww w.j ava2 s . c o m allowing(cart).getShoppingContext(); will(returnValue(cartCtx)); allowing(cartCtx).getShopId(); will(returnValue(234L)); allowing(cartCtx).getCustomerShopId(); will(returnValue(234L)); 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", 234L, null, "EUR", BigDecimal.ONE, false, "P1"); will(returnValue(skuPrice)); allowing(skuPrice).getSkuCode(); will(returnValue("ABC")); allowing(skuPrice).getQuantity(); will(returnValue(BigDecimal.ONE)); allowing(skuPrice).getRegularPrice(); will(returnValue(new BigDecimal("100.00"))); allowing(skuPrice).getSalePriceForCalculation(); will(returnValue(null)); allowing(shopService).getById(234L); will(returnValue(shop)); allowing(cartCtx).isTaxInfoEnabled(); 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); assertEquals("ABC", model.getRef()); assertEquals("EUR", model.getCurrency()); assertEquals("1", model.getQuantity().toPlainString()); assertEquals("100.00", model.getRegularPrice().toPlainString()); 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:org.libreplan.web.planner.allocation.FormBinder.java
private void resetStateForResourcesPerDayInputsWhenDoingRecommendedAllocation() { if (allResourcesPerDay.isDisabled()) { allResourcesPerDay.setValue((BigDecimal) null); AllocationRow.unknownResourcesPerDay(rows); } else {//ww w.j a v a 2 s.c om allResourcesPerDay.setValue(BigDecimal.ONE); distributeResourcesPerDayToRows(); allResourcesPerDay.focus(); } }
From source file:org.finra.herd.service.helper.HerdHelperTest.java
/** * Tests case where validation is run against the definition generated by createValidEmrClusterDefinition() The master spot price is negative. The * definition is not valid. All prices must be positive. *//*from w w w . j av a 2s . c o m*/ @Test public void testValidateEmrClusterDefinitionConfigurationMasterSpotPriceNegative() { EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition(); emrClusterDefinition.getInstanceDefinitions().getMasterInstances() .setInstanceSpotPrice(BigDecimal.ONE.negate()); try { herdHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition); fail("expected IllegalArgumentException, but no exception was thrown"); } catch (Exception e) { assertEquals("thrown exception", IllegalArgumentException.class, e.getClass()); } }
From source file:org.openvpms.esci.adapter.map.invoice.InvoiceMapperImpl.java
/** * Verifies that the invoice line's <em>BaseQuantity</em> is specified correctly, if present. * * @param line the invoice line/*from www .ja va2 s . c o m*/ * @param unitCode the expected unit code */ private void checkBaseQuantity(UBLInvoiceLine line, String unitCode) { BigDecimal quantity = line.getBaseQuantity(); if (quantity != null) { if (quantity.compareTo(BigDecimal.ONE) != 0) { ErrorContext context = new ErrorContext(line, "BaseQuantity"); throw new ESCIAdapterException(ESCIAdapterMessages.ublInvalidValue(context.getPath(), context.getType(), context.getID(), "1", quantity.toString())); } String baseQuantityUnitCode = line.getBaseQuantityUnitCode(); if (!StringUtils.equals(unitCode, baseQuantityUnitCode)) { ErrorContext context = new ErrorContext(line, "BaseQuantity@unitCode"); throw new ESCIAdapterException(ESCIAdapterMessages.ublInvalidValue(context.getPath(), context.getType(), context.getID(), unitCode, baseQuantityUnitCode)); } } }
From source file:org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao.java
public FIN_Payment getNewPayment(boolean isReceipt, Organization organization, DocumentType docType, String strPaymentDocumentNo, BusinessPartner businessPartner, FIN_PaymentMethod paymentMethod, FIN_FinancialAccount finAccount, String strPaymentAmount, Date paymentDate, String referenceNo, Currency paymentCurrency, BigDecimal finTxnConvertRate, BigDecimal finTxnAmount) { final FIN_Payment newPayment = OBProvider.getInstance().get(FIN_Payment.class); newPayment.setReceipt(isReceipt);/*w ww . ja v a 2 s .c o m*/ newPayment.setDocumentType(docType); newPayment.setDocumentNo(strPaymentDocumentNo); newPayment.setOrganization(organization); newPayment.setClient(organization.getClient()); newPayment.setStatus("RPAP"); newPayment.setBusinessPartner(businessPartner); newPayment.setPaymentMethod(paymentMethod); newPayment.setAccount(finAccount); final BigDecimal paymentAmount = new BigDecimal(strPaymentAmount); newPayment.setAmount(paymentAmount); newPayment.setPaymentDate(paymentDate); if (paymentCurrency != null) { newPayment.setCurrency(paymentCurrency); } else { newPayment.setCurrency(finAccount.getCurrency()); } newPayment.setReferenceNo(referenceNo); if (finTxnConvertRate == null || finTxnConvertRate.compareTo(BigDecimal.ZERO) <= 0) { finTxnConvertRate = BigDecimal.ONE; } if (finTxnAmount == null || finTxnAmount.compareTo(BigDecimal.ZERO) == 0) { finTxnAmount = paymentAmount.multiply(finTxnConvertRate); } // This code commented due to fix in bug 17829 // else if (paymentAmount != null && paymentAmount.compareTo(BigDecimal.ZERO) != 0) { // // Correct exchange rate for rounding that occurs in UI // finTxnConvertRate = finTxnAmount.divide(paymentAmount, MathContext.DECIMAL64); // } newPayment.setFinancialTransactionConvertRate(finTxnConvertRate); newPayment.setFinancialTransactionAmount(finTxnAmount); OBDal.getInstance().save(newPayment); return newPayment; }
From source file:org.egov.ptis.actions.common.AjaxCommonAction.java
/** * API to calculate Mutation Fee dynamically * * @return// w w w. j av a 2s. com */ @Action(value = "/ajaxCommon-calculateMutationFee") public String calculateMutationFee() { // Maximum among partyValue and departmentValue will be considered as // the documentValue final BigDecimal documentValue = partyValue.compareTo(departmentValue) > 0 ? partyValue : departmentValue; if (documentValue.compareTo(ZERO) > 0) { BigDecimal excessDocValue; BigDecimal multiplicationFactor; final MutationFeeDetails mutationFeeDetails = (MutationFeeDetails) getPersistenceService().find( "from MutationFeeDetails where lowLimit <= ? and (highLimit is null OR highLimit >= ?) and toDate > now()", documentValue, documentValue); if (mutationFeeDetails != null) { if (mutationFeeDetails.getFlatAmount() != null && mutationFeeDetails.getFlatAmount().compareTo(ZERO) > 0) if (mutationFeeDetails.getIsRecursive().toString().equalsIgnoreCase(RECURSIVEFACTOR_N)) mutationFee = mutationFeeDetails.getFlatAmount(); else { excessDocValue = documentValue.subtract(mutationFeeDetails.getLowLimit()) .add(BigDecimal.ONE); multiplicationFactor = excessDocValue.divide(mutationFeeDetails.getRecursiveAmount(), BigDecimal.ROUND_CEILING); mutationFee = mutationFeeDetails.getFlatAmount() .add(multiplicationFactor.multiply(mutationFeeDetails.getRecursiveFactor())); } if (mutationFeeDetails.getPercentage() != null && mutationFeeDetails.getPercentage().compareTo(ZERO) > 0) if (mutationFeeDetails.getIsRecursive().toString().equalsIgnoreCase(RECURSIVEFACTOR_N)) mutationFee = documentValue.multiply(mutationFeeDetails.getPercentage()) .divide(PropertyTaxConstants.BIGDECIMAL_100); mutationFee = mutationFee.setScale(0, BigDecimal.ROUND_HALF_UP); } } return RESULT_MUTATION_FEE; }
From source file:org.helianto.task.domain.Report.java
/** * Remaining progress, additional to progress already occured. * /*w w w . j av a 2 s . c om*/ * <p> * Formula: (1 - (${complete}/100)). * </p> */ public BigDecimal getRemainingProgress() { return BigDecimal.ONE.add(new BigDecimal(getComplete()).divide(new BigDecimal(-100))); }
From source file:org.finra.dm.service.helper.DmHelperTest.java
/** * Tests case where validation is run against the definition generated by createValidEmrClusterDefinition() The master spot price is negative. The * definition is not valid. All prices must be positive. *//*w w w . j ava 2s . co m*/ @Test public void testValidateEmrClusterDefinitionConfigurationMasterSpotPriceNegative() { EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition(); emrClusterDefinition.getInstanceDefinitions().getMasterInstances() .setInstanceSpotPrice(BigDecimal.ONE.negate()); try { dmHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition); fail("expected IllegalArgumentException, but no exception was thrown"); } catch (Exception e) { assertEquals("thrown exception", IllegalArgumentException.class, e.getClass()); } }
From source file:pe.gob.mef.gescon.hibernate.impl.ConsultaDaoImpl.java
@Override public List<HashMap<String, Object>> listarReporte(HashMap filters) { final String fCategoria = (String) filters.get("fCategoria"); final Date fFromDate = (Date) filters.get("fFromDate"); final Date fToDate = (Date) filters.get("fToDate"); final String fType = (String) filters.get("fType"); final String fCodesBL = (String) filters.get("fCodesBL"); final String fCodesPR = (String) filters.get("fCodesPR"); final String fCodesC = (String) filters.get("fCodesC"); final String order = (String) filters.get("order"); SimpleDateFormat sdf = new SimpleDateFormat(Constante.FORMAT_DATE_SHORT); final StringBuilder sql = new StringBuilder(); Object object = null;// ww w . ja va2 s.co m try { sql.append("SELECT x.ID, x.NOMBRE, x.SUMILLA, x.IDCATEGORIA, x.CATEGORIA, x.FECHA, "); sql.append( " x.IDTIPOCONOCIMIENTO, x.TIPOCONOCIMIENTO, x.IDESTADO, x.ESTADO, x.SUMA, x.CONTADOR, "); sql.append(" DECODE(x.CONTADOR,0,0,x.SUMA/x.CONTADOR) AS PROMEDIO, x.USUARIOCREA, x.FECHACREA "); sql.append("FROM (SELECT "); sql.append(" a.nbaselegalid AS ID, a.vnumero AS NOMBRE, a.vnombre AS SUMILLA, "); sql.append( " a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, "); sql.append( " 1 AS IDTIPOCONOCIMIENTO, 'Base Legal' AS TIPOCONOCIMIENTO, a.nestadoid AS IDESTADO, c.vnombre AS ESTADO, "); sql.append( " a.vusuariocreacion AS USUARIOCREA, TO_CHAR(a.dfechacreacion,'dd/MM/yyyy') AS FECHACREA, "); sql.append( " NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR "); sql.append(" FROM TBASELEGAL a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTESTADO_BASELEGAL c ON a.nestadoid = c.nestadoid "); sql.append(" LEFT OUTER JOIN TCALIFICACION_BASELEGAL e ON a.nbaselegalid = e.nbaselegalid "); sql.append(" WHERE a.nactivo = :ACTIVO "); sql.append(" AND c.nestadoid IN (3,4,5,6) AND b.NESTADO = 1 "); if (StringUtils.isNotBlank(fCategoria)) { sql.append(" AND a.ncategoriaid IN (").append(fCategoria).append(") "); } if (fFromDate != null) { sql.append(" AND TRUNC(a.dfechapublicacion) >= TO_DATE('").append(sdf.format(fFromDate)) .append("','dd/mm/yyyy') "); } if (fToDate != null) { sql.append(" AND TRUNC(a.dfechapublicacion) <= TO_DATE('").append(sdf.format(fToDate)) .append("','dd/mm/yyyy') "); } if (StringUtils.isNotBlank(fCodesBL)) { sql.append(" AND a.nbaselegalid IN (").append(fCodesBL).append(") "); } sql.append(" GROUP BY a.nbaselegalid, a.vnumero, a.vnombre, a.ncategoriaid, b.vnombre, "); sql.append( " a.dfechapublicacion, 1, 'Base Legal', a.nestadoid, c.vnombre, a.vusuariocreacion, a.dfechacreacion "); sql.append(" ) x "); sql.append("WHERE 1 IN (").append(fType).append(") "); //BASE LEGAL sql.append("UNION "); sql.append("SELECT y.ID, y.NOMBRE, y.SUMILLA, y.IDCATEGORIA, y.CATEGORIA, y.FECHA, "); sql.append( " y.IDTIPOCONOCIMIENTO, y.TIPOCONOCIMIENTO, y.IDESTADO, y.ESTADO, y.SUMA, y.CONTADOR, "); sql.append(" DECODE(y.CONTADOR,0,0,y.SUMA/y.CONTADOR) AS PROMEDIO, y.USUARIOCREA, y.FECHACREA "); sql.append("FROM (SELECT "); sql.append( " a.npreguntaid AS ID, a.vasunto AS NOMBRE, a.vdetalle AS SUMILLA, a.ncategoriaid AS IDCATEGORIA, "); sql.append( " b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, 2 AS IDTIPOCONOCIMIENTO, "); sql.append( " 'Preguntas y Respuestas' AS TIPOCONOCIMIENTO, a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO, "); sql.append( " a.vusuariocreacion AS USUARIOCREA, TO_CHAR(a.dfechacreacion,'dd/MM/yyyy') AS FECHACREA, "); sql.append( " NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR "); sql.append(" FROM TPREGUNTA a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid "); sql.append(" LEFT OUTER JOIN TCALIFICACION_PREGUNTA e ON a.npreguntaid = e.npreguntaid "); sql.append(" WHERE a.nactivo = :ACTIVO "); sql.append(" AND c.nsituacionid = 6 AND b.NESTADO = 1 "); if (StringUtils.isNotBlank(fCategoria)) { sql.append(" AND a.ncategoriaid IN (").append(fCategoria).append(") "); } if (fFromDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) >= TO_DATE('").append(sdf.format(fFromDate)) .append("','dd/mm/yyyy') "); } if (fToDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) <= TO_DATE('").append(sdf.format(fToDate)) .append("','dd/mm/yyyy') "); } if (StringUtils.isNotBlank(fCodesPR)) { sql.append(" AND a.npreguntaid IN (").append(fCodesPR).append(") "); } sql.append(" GROUP BY a.npreguntaid, a.vasunto, a.vdetalle, a.ncategoriaid, b.vnombre, "); sql.append( " a.dfechapublicacion, 2, 'Preguntas y Respuestas', a.nsituacionid, c.vnombre, a.vusuariocreacion, a.dfechacreacion "); sql.append(" ) y "); sql.append("WHERE 2 IN (").append(fType).append(") "); //PREGUNTAS Y RESPUESTAS sql.append("UNION "); sql.append("SELECT z.ID, z.NOMBRE, z.SUMILLA, z.IDCATEGORIA, z.CATEGORIA, z.FECHA, "); sql.append( " z.IDTIPOCONOCIMIENTO, z.TIPOCONOCIMIENTO, z.IDESTADO, z.ESTADO, z.SUMA, z.CONTADOR, "); sql.append(" DECODE(z.CONTADOR,0,0,z.SUMA/z.CONTADOR) AS PROMEDIO, z.USUARIOCREA, z.FECHACREA "); sql.append("FROM (SELECT "); sql.append(" a.nconocimientoid AS ID, a.vtitulo AS NOMBRE, a.vdescripcion AS SUMILLA, "); sql.append( " a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, "); sql.append(" a.ntpoconocimientoid AS IDTIPOCONOCIMIENTO, d.vnombre AS TIPOCONOCIMIENTO, "); sql.append( " a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO, a.vusuariocreacion AS USUARIOCREA, "); sql.append(" TO_CHAR(a.dfechacreacion,'dd/MM/yyyy') AS FECHACREA, "); sql.append( " NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR "); sql.append(" FROM TCONOCIMIENTO a "); sql.append(" INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid "); sql.append(" INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid "); sql.append(" INNER JOIN MTTIPO_CONOCIMIENTO d ON a.ntpoconocimientoid = d.ntpoconocimientoid "); sql.append(" AND a.ntpoconocimientoid IN (").append(fType).append(") "); sql.append(" LEFT OUTER JOIN TCALIFICACION e ON a.nconocimientoid = e.nconocimientoid "); sql.append(" WHERE a.nactivo = :ACTIVO "); sql.append(" AND c.nsituacionid = 6 AND b.nestado = 1 "); if (StringUtils.isNotBlank(fCategoria)) { sql.append(" AND a.ncategoriaid IN (").append(fCategoria).append(") "); } if (fFromDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) >= TO_DATE('").append(sdf.format(fFromDate)) .append("','dd/mm/yyyy') "); } if (fToDate != null) { sql.append(" AND TRUNC(a.dfechacreacion) <= TO_DATE('").append(sdf.format(fToDate)) .append("','dd/mm/yyyy') "); } if (StringUtils.isNotBlank(fCodesC)) { sql.append(" AND a.nconocimientoid IN (").append(fCodesC).append(") "); } sql.append( " GROUP BY a.nconocimientoid, a.vtitulo, a.vdescripcion, a.ncategoriaid, b.vnombre, "); sql.append( " a.dfechapublicacion, a.ntpoconocimientoid, d.vnombre, a.nsituacionid, c.vnombre, a.vusuariocreacion, a.dfechacreacion "); sql.append(" ) z "); sql.append("WHERE (3 IN (").append(fType).append(") OR 4 IN (").append(fType).append(") OR 5 IN (") .append(fType).append(") OR 6 IN (").append(fType).append(")) "); //WIKI if (StringUtils.isNotBlank(order)) { sql.append("ORDER BY ").append(order); } else { sql.append("ORDER BY 6 DESC "); } object = getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { Query query = session.createSQLQuery(sql.toString()); query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); if (StringUtils.isNotBlank(sql.toString())) { query.setParameter("ACTIVO", BigDecimal.ONE); } return query.list(); } }); } catch (DataAccessException e) { e.getMessage(); e.printStackTrace(); } return (List<HashMap<String, Object>>) object; }
From source file:org.finra.herd.service.helper.HerdHelperTest.java
/** * Tests case where validation is run against the definition generated by createValidEmrClusterDefinition() The master instance spot price and max search * price is specified. The definition is not valid. The two parameters are exclusive. *//*from w w w. jav a 2s. c o m*/ @Test public void testValidateEmrClusterDefinitionConfigurationMasterSpotPriceAndMaxSearchPriceSpecified() { EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition(); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceSpotPrice(BigDecimal.ONE); emrClusterDefinition.getInstanceDefinitions().getMasterInstances() .setInstanceMaxSearchPrice(BigDecimal.ONE); try { herdHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition); fail("expected IllegalArgumentException, but no exception was thrown"); } catch (Exception e) { assertEquals("thrown exception", IllegalArgumentException.class, e.getClass()); } }