@Test public final void shouldValuesEqualsReturnCorrectValue() { Assert.assertTrue(BigDecimalUtils.valueEquals(null, null)); Assert.assertFalse(BigDecimalUtils.valueEquals(null, BigDecimal.ZERO)); Assert.assertFalse(BigDecimalUtils.valueEquals(BigDecimal.ZERO, null)); Assert.assertFalse(BigDecimalUtils.valueEquals(BigDecimal.ONE, BigDecimal.ZERO)); Assert.assertTrue( BigDecimalUtils.valueEquals(BigDecimal.ZERO.setScale(100), BigDecimal.ZERO.setScale(2))); }
public class BillSubtotalUpdate extends Update { private BigDecimal amount = BigDecimal.ZERO.setScale(2); public BillSubtotalUpdate(BigDecimal amount) { this.amount = amount; } @Override public boolean equals(Object other) { // check for self-comparison if (this == other) return true; // use instanceof instead of getClass here for two reasons // 1. if need be, it can match any supertype, and not just one class; // 2. it renders an explict check for "that == null" redundant, since // it does the check for null already - "null instanceof [type]" always // returns false. (See Effective Java by Joshua Bloch.) if (!(other instanceof BillSubtotalUpdate)) return false; // cast to native object is now safe BillSubtotalUpdate otherBSA = (BillSubtotalUpdate) other; // now a proper field-by-field evaluation can be made return EqualsUtil.areEqual(this.amount, otherBSA.amount); } public BigDecimal getAmount() { return this.amount; } public String toString() { return "BillSubtotal(" + this.amount + ")"; } }
@Test @WithMockUser(roles = "Tutor") public void noAppointmentBill() throws Exception { mockMvc .perform(get("/bill").principal(this.authUser)) .andExpect(model().attribute("balance", BigDecimal.ZERO.setScale(2))); }
public BigDecimal getBudgetIncomeAmount() { if (isBudgetIncome() && (budgetIncomeAmount == null || BigDecimal.ZERO.setScale(2).equals(budgetIncomeAmount.setScale(2)))) { return getAmount(); } if (!isBudgetIncome()) { return BigDecimal.ZERO; } return budgetIncomeAmount; }
public BigDecimal getTotalFee() { BigDecimal fee = BigDecimal.ZERO.setScale(8); for (Transaction transaction : this.getTransactions()) { fee = fee.add(transaction.getFee()); } fee = fee.add(BigDecimal.valueOf(this.atFees, 8)); return fee; }
@Transient public BigDecimal getValue(Date currentStartDate, Date currentEndDate, Currency targetCurrency) { BigDecimal valueForDate = BigDecimal.ZERO.setScale(4); for (PortfolioShare portfolioShare : this.getListShares().values()) { BigDecimal psValueForDate = portfolioShare.getValue(currentStartDate, currentEndDate, targetCurrency); valueForDate = valueForDate.add(psValueForDate); } return valueForDate; }
public BigDecimal costoUnitarioCargoLegajo() { int meshoras = 0; try { meshoras = this.ContarHorasDedicacionCargoLegajo() * 4; if (meshoras > 0) { return this.ContarSueldoBasicoCargoLegajo() .divide(BigDecimal.valueOf(Double.valueOf("" + meshoras)), RoundingMode.HALF_UP) .setScale(2); } else { return BigDecimal.ZERO.setScale(2, RoundingMode.CEILING); } } catch (Exception ex) { System.out.println( "No se realizo la consulta en la extraccion de costo unitario por cargos " + ex); return BigDecimal.ZERO.setScale(2); } }
protected JSONObject execute(Map<String, Object> parameters, String data) { final DataToJsonConverter jsonConverter = new DataToJsonConverter(); JSONObject json = null; try { String orderId = (String) parameters.get("orderId"); Order objOrder = OBDal.getInstance().get(Order.class, orderId); Order objCloneOrder = (Order) DalUtil.copy(objOrder, false); BigDecimal bLineNetAmt = getLineNetAmt(orderId); objCloneOrder.setDocumentAction("CO"); objCloneOrder.setDocumentStatus("DR"); objCloneOrder.setPosted("N"); objCloneOrder.setProcessed(false); objCloneOrder.setSalesTransaction(true); objCloneOrder.setDocumentNo(null); objCloneOrder.setSalesTransaction(objOrder.isSalesTransaction()); // save the cloned order object OBDal.getInstance().save(objCloneOrder); objCloneOrder.setSummedLineAmount(objCloneOrder.getSummedLineAmount().subtract(bLineNetAmt)); objCloneOrder.setGrandTotalAmount(objCloneOrder.getGrandTotalAmount().subtract(bLineNetAmt)); // get the lines associated with the order and clone them to the new // order line. for (OrderLine ordLine : objOrder.getOrderLineList()) { String strPriceVersionId = getPriceListVersion(objOrder.getPriceList().getId(), objOrder.getClient().getId()); BigDecimal bdPriceList = getPriceList(ordLine.getProduct().getId(), strPriceVersionId); OrderLine objCloneOrdLine = (OrderLine) DalUtil.copy(ordLine, false); objCloneOrdLine.setReservedQuantity(new BigDecimal("0")); objCloneOrdLine.setDeliveredQuantity(new BigDecimal("0")); objCloneOrdLine.setInvoicedQuantity(new BigDecimal("0")); if (!"".equals(bdPriceList) || bdPriceList != null || !bdPriceList.equals(BigDecimal.ZERO.setScale(bdPriceList.scale()))) { objCloneOrdLine.setListPrice(bdPriceList); } objCloneOrder.getOrderLineList().add(objCloneOrdLine); objCloneOrdLine.setSalesOrder(objCloneOrder); } OBDal.getInstance().save(objCloneOrder); OBDal.getInstance().flush(); OBDal.getInstance().refresh(objCloneOrder); json = jsonConverter.toJsonObject(objCloneOrder, DataResolvingMode.FULL); OBDal.getInstance().commitAndClose(); return json; } catch (Exception e) { throw new OBException(e); } }
@org.junit.Test public void testBorderValue2Equality() throws IOException { final java.util.List<java.math.BigDecimal> borderValue2 = new java.util.ArrayList<java.math.BigDecimal>( java.util.Arrays.asList(java.math.BigDecimal.ZERO.setScale(2))); final StaticJson.Bytes borderValue2JsonSerialized = jsonSerialization.serialize(borderValue2); final java.util.List<java.math.BigDecimal> borderValue2JsonDeserialized = jsonSerialization.deserializeList( java.math.BigDecimal.class, borderValue2JsonSerialized.content, borderValue2JsonSerialized.length); MoneyAsserts.assertNullableListOfNullableEquals(borderValue2, borderValue2JsonDeserialized); }
@org.junit.Test public void testBorderValue4Equality() throws IOException { final java.util.List<java.math.BigDecimal> borderValue4 = new java.util.ArrayList<java.math.BigDecimal>( java.util.Arrays.asList( java.math.BigDecimal.ZERO.setScale(2), java.math.BigDecimal.ONE, new java.math.BigDecimal( "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679") .setScale(2, java.math.BigDecimal.ROUND_HALF_UP), new java.math.BigDecimal("-1E-2"), new java.math.BigDecimal("1E19"))); final StaticJson.Bytes borderValue4JsonSerialized = jsonSerialization.serialize(borderValue4); final java.util.List<java.math.BigDecimal> borderValue4JsonDeserialized = jsonSerialization.deserializeList( java.math.BigDecimal.class, borderValue4JsonSerialized.content, borderValue4JsonSerialized.length); MoneyAsserts.assertNullableListOfNullableEquals(borderValue4, borderValue4JsonDeserialized); }
public boolean isEmpty() { return (getAmount() == null || getAmount().setScale(2).equals(BigDecimal.ZERO.setScale(2))) && (getVatAmount() == null || getVatAmount().setScale(2).equals(BigDecimal.ZERO.setScale(2))); }
/** * JavaDoc here * * @author Victor Polischuk * @since 29.09.13 14:37 */ public class SuperJokerTop1Test extends AbstractDroolsTest { private static final BigDecimal ZERO = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); private static final BigDecimal LOCAL = new BigDecimal("1.5").setScale(2, RoundingMode.HALF_UP); private static final BigDecimal OTHER = new BigDecimal("2.5").setScale(2, RoundingMode.HALF_UP); private static final int HOUR = DateTimeConstants.MILLIS_PER_HOUR; private final Customer callee = new Customer("007", Tariff.SMART, Subscription.TOP_ONE); private final Customer called = new Customer("008", Tariff.SIMPLE); private final Interval billingPeriod = new Interval(new DateTime(2013, 9, 1, 0, 0, 0, 0), new DateTime(2013, 10, 1, 0, 0, 0, 0)); @Test public void testSMSWithinBounds_Single() { DateTime instant = new DateTime(2013, 9, 20, 4, 40, 11); BigDecimal expectedResult = ZERO; BigDecimal actualResult = executeGetInvoice( callee, generateSMS("007", "any", instant, 0, 1), billingPeriod, callee, called) .getAmount(); assertEquals(expectedResult, actualResult); } @Test public void testCallWithinBounds_Multiple() { DateTime instant = new DateTime(2013, 9, 20, 4, 40, 11); BigDecimal expectedResult = ZERO; BigDecimal actualResult = executeGetInvoice( callee, generateSMS("007", "any", instant, HOUR * 2, 11), billingPeriod, callee, called) .getAmount(); assertEquals(expectedResult, actualResult); } @Test public void testLocalCallOutOfBounds() { DateTime instant = new DateTime(2013, 9, 20, 4, 40, 11); BigDecimal expectedResult = ZERO; BigDecimal actualResult = executeGetInvoice( callee, generateSMS("007", "008", instant, HOUR, 11), billingPeriod, callee, called) .getAmount(); assertEquals(expectedResult, actualResult); } @Test public void testOthersCallOutOfBounds_OtherIsFree() { DateTime instant = new DateTime(2013, 9, 20, 4, 40, 11); BigDecimal expectedResult = new BigDecimal("16.50"); BigDecimal actualResult = executeGetInvoice( callee, join( generateSMS("007", "008", instant, HOUR, 10), generateSMS("007", "008", instant, HOUR + 20, 10), generateSMS("007", "any", instant.plusMillis(HOUR + 100), 0, 1)), billingPeriod, callee, called) .getAmount(); assertEquals(expectedResult, actualResult); } @Test public void testOthersCallOutOfBounds_OtherIsMax() { DateTime instant = new DateTime(2013, 9, 20, 4, 40, 11); BigDecimal expectedResult = new BigDecimal("15.00"); BigDecimal actualResult = executeGetInvoice( callee, join( generateSMS("007", "008", instant, HOUR, 10), generateSMS("007", "008", instant, HOUR + 20, 10), generateSMS("007", "any", instant.plusMillis(HOUR * 11 + 100), 0, 1)), billingPeriod, callee, called) .getAmount(); assertEquals(expectedResult, actualResult); } }
public boolean sellAll(Player player) { // make a list of all commodities List<Commodities> commodities = plugin.getDatabase().find(Commodities.class).findList(); // run thru each slot in the player's inventory for commodities int index = 0; BigDecimal sale = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); for (@SuppressWarnings("unused") ItemStack stack : player .getInventory() .getContents()) { // we do it this way incase a user has an expanded inventory via // another plugin ItemStack slot = player.getInventory().getItem(index); int slotId = slot.getTypeId(); BigDecimal slotAmount = new BigDecimal(slot.getAmount()).setScale(0, RoundingMode.HALF_UP); Byte slotByteData = Byte.valueOf("0"); try { slotByteData = slot.getData().getData(); } catch (NullPointerException e) { slotByteData = Byte.valueOf("0"); } for (int x = 0; x < commodities.size(); x++) { if ((commodities.get(x).getNumber() == slotId) && (Byte.valueOf(String.valueOf(commodities.get(x).getData())).compareTo(slotByteData) == 0)) { Invoice thisSale = generateInvoice( 0, // perform sale of this slot commodities.get(x), slotAmount.intValue()); sale = sale.add(BigDecimal.valueOf(thisSale.getTotal())); // rack up our total // save the new value commodities.get(x).setValue(thisSale.getValue()); plugin.getDatabase().save(commodities.get(x)); player.getInventory().clear(index); // remove the item(s) economy.depositPlayer( player.getName(), // "pay the man" thisSale.getTotal()); // give nice output player.sendMessage( ChatColor.GREEN + "Sold " + ChatColor.WHITE + slotAmount + " " + ChatColor.GRAY + commodities.get(x).getName() + ChatColor.GREEN + " for " + ChatColor.WHITE + BigDecimal.valueOf(thisSale.getTotal()).setScale(2, RoundingMode.HALF_UP)); break; } } index++; } // give a nice total column if (sale == BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)) player.sendMessage("Nothing to Sell"); player.sendMessage(ChatColor.GREEN + "--------------------------------"); player.sendMessage( ChatColor.GREEN + "Total Sale: " + ChatColor.WHITE + sale.setScale(2, RoundingMode.HALF_UP)); return true; }
public BigDecimal getNormalizedTotalCosts() { if (totalCosts == null) { return BigDecimal.ZERO.setScale(PriceConverter.NORMALIZED_PRICE_SCALING); } return totalCosts.setScale(PriceConverter.NORMALIZED_PRICE_SCALING, RoundingMode.HALF_UP); }