@Test public void test03() { c = new BookingEarningsCalculator(); BookingBean b = BookingBeanTest.newInstance(LocalDate.of(2018, 01, 27), LocalDate.of(2018, 8, 5)); b.setPaymentDone(true); b.setGrossEarningsExpression("8252.86"); assertThat(b.getNumberOfNights(), is(190)); float result = c.calculateEarnings(b); assertThat(result, is(8252.86f)); }
public float calculateEarnings(Collection<? extends BookingBean> bookings) { if (isPaymentDone()) { bookings = bookings.stream().filter(b -> b.isPaymentDone()).collect(Collectors.toCollection(LinkedHashSet::new)); } if (getDateRange() != null) { bookings = bookings.stream().filter(b -> getDateRange().contains(b.getCheckOut())).collect(Collectors.toCollection(LinkedHashSet::new)); } MonetaryAmountFactory<?> moneyFactory = Monetary.getDefaultAmountFactory().setCurrency(DrBookingsApplication.DEFAULT_CURRENCY.getCurrencyCode()); MonetaryAmount result = moneyFactory.setNumber(0).create(); for (BookingBean b : bookings) { result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }
BookingEarningsCalculator extends EarningsCalculator { public float calculateEarnings(Collection<? extends BookingBean> bookings) { if (isPaymentDone()) { bookings = bookings.stream().filter(b -> b.isPaymentDone()).collect(Collectors.toCollection(LinkedHashSet::new)); } if (getDateRange() != null) { bookings = bookings.stream().filter(b -> getDateRange().contains(b.getCheckOut())).collect(Collectors.toCollection(LinkedHashSet::new)); } MonetaryAmountFactory<?> moneyFactory = Monetary.getDefaultAmountFactory().setCurrency(DrBookingsApplication.DEFAULT_CURRENCY.getCurrencyCode()); MonetaryAmount result = moneyFactory.setNumber(0).create(); for (BookingBean b : bookings) { result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); } }
BookingEarningsCalculator extends EarningsCalculator { public float calculateEarnings(Collection<? extends BookingBean> bookings) { if (isPaymentDone()) { bookings = bookings.stream().filter(b -> b.isPaymentDone()).collect(Collectors.toCollection(LinkedHashSet::new)); } if (getDateRange() != null) { bookings = bookings.stream().filter(b -> getDateRange().contains(b.getCheckOut())).collect(Collectors.toCollection(LinkedHashSet::new)); } MonetaryAmountFactory<?> moneyFactory = Monetary.getDefaultAmountFactory().setCurrency(DrBookingsApplication.DEFAULT_CURRENCY.getCurrencyCode()); MonetaryAmount result = moneyFactory.setNumber(0).create(); for (BookingBean b : bookings) { result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }  }
BookingEarningsCalculator extends EarningsCalculator { public float calculateEarnings(Collection<? extends BookingBean> bookings) { if (isPaymentDone()) { bookings = bookings.stream().filter(b -> b.isPaymentDone()).collect(Collectors.toCollection(LinkedHashSet::new)); } if (getDateRange() != null) { bookings = bookings.stream().filter(b -> getDateRange().contains(b.getCheckOut())).collect(Collectors.toCollection(LinkedHashSet::new)); } MonetaryAmountFactory<?> moneyFactory = Monetary.getDefaultAmountFactory().setCurrency(DrBookingsApplication.DEFAULT_CURRENCY.getCurrencyCode()); MonetaryAmount result = moneyFactory.setNumber(0).create(); for (BookingBean b : bookings) { result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }  BookingEarningsCalculator filterToDateRange(Range<LocalDate> dateRange); BookingEarningsCalculator filterForPaymentDone(boolean paymentDone); BookingEarningsCalculator filterForNetEarnings(boolean netEarnigns); float calculateEarnings(Collection<? extends BookingBean> bookings); }
BookingEarningsCalculator extends EarningsCalculator { public float calculateEarnings(Collection<? extends BookingBean> bookings) { if (isPaymentDone()) { bookings = bookings.stream().filter(b -> b.isPaymentDone()).collect(Collectors.toCollection(LinkedHashSet::new)); } if (getDateRange() != null) { bookings = bookings.stream().filter(b -> getDateRange().contains(b.getCheckOut())).collect(Collectors.toCollection(LinkedHashSet::new)); } MonetaryAmountFactory<?> moneyFactory = Monetary.getDefaultAmountFactory().setCurrency(DrBookingsApplication.DEFAULT_CURRENCY.getCurrencyCode()); MonetaryAmount result = moneyFactory.setNumber(0).create(); for (BookingBean b : bookings) { result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }  BookingEarningsCalculator filterToDateRange(Range<LocalDate> dateRange); BookingEarningsCalculator filterForPaymentDone(boolean paymentDone); BookingEarningsCalculator filterForNetEarnings(boolean netEarnigns); float calculateEarnings(Collection<? extends BookingBean> bookings);  }