@Test public void test01() { BookingBean b = BookingBeanTest.newInstance(LocalDate.of(2012, 02, 02), LocalDate.of(2012, 2, 5)); b.setPaymentDone(true); float result = c.calculateEarnings(b); assertThat(result, is(0f)); }
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(); if (logger.isDebugEnabled()) { logger.debug("Calculating earnings for\n" + bookings.stream().map(b -> b.toString()).collect(Collectors.joining("\n"))); } for (BookingBean b : bookings) { if (b.getNumberOfNights() > LocalDate.now().getMonth().minLength()) { if (logger.isDebugEnabled()) { logger.debug("Days in month " + LocalDate.now().getMonth() + ": " + LocalDate.now().getMonth().minLength()); } if (logger.isInfoEnabled()) { logger.info("Airbnb long term booking, looking at manual registered payments"); } Optional<Payment> op = Payments.getLastPayment(b.getPayments()); MonetaryAmount payment; if (op.isPresent()) { payment = op.get().getAmount(); } else { payment = moneyFactory.setNumber(0).create(); } if(logger.isDebugEnabled()){ logger.debug("Payment is " + payment); } result = result.add(payment); } else result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }
AirbnbEarningsCalculator 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(); if (logger.isDebugEnabled()) { logger.debug("Calculating earnings for\n" + bookings.stream().map(b -> b.toString()).collect(Collectors.joining("\n"))); } for (BookingBean b : bookings) { if (b.getNumberOfNights() > LocalDate.now().getMonth().minLength()) { if (logger.isDebugEnabled()) { logger.debug("Days in month " + LocalDate.now().getMonth() + ": " + LocalDate.now().getMonth().minLength()); } if (logger.isInfoEnabled()) { logger.info("Airbnb long term booking, looking at manual registered payments"); } Optional<Payment> op = Payments.getLastPayment(b.getPayments()); MonetaryAmount payment; if (op.isPresent()) { payment = op.get().getAmount(); } else { payment = moneyFactory.setNumber(0).create(); } if(logger.isDebugEnabled()){ logger.debug("Payment is " + payment); } result = result.add(payment); } else result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); } }
AirbnbEarningsCalculator 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(); if (logger.isDebugEnabled()) { logger.debug("Calculating earnings for\n" + bookings.stream().map(b -> b.toString()).collect(Collectors.joining("\n"))); } for (BookingBean b : bookings) { if (b.getNumberOfNights() > LocalDate.now().getMonth().minLength()) { if (logger.isDebugEnabled()) { logger.debug("Days in month " + LocalDate.now().getMonth() + ": " + LocalDate.now().getMonth().minLength()); } if (logger.isInfoEnabled()) { logger.info("Airbnb long term booking, looking at manual registered payments"); } Optional<Payment> op = Payments.getLastPayment(b.getPayments()); MonetaryAmount payment; if (op.isPresent()) { payment = op.get().getAmount(); } else { payment = moneyFactory.setNumber(0).create(); } if(logger.isDebugEnabled()){ logger.debug("Payment is " + payment); } result = result.add(payment); } else result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }  }
AirbnbEarningsCalculator 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(); if (logger.isDebugEnabled()) { logger.debug("Calculating earnings for\n" + bookings.stream().map(b -> b.toString()).collect(Collectors.joining("\n"))); } for (BookingBean b : bookings) { if (b.getNumberOfNights() > LocalDate.now().getMonth().minLength()) { if (logger.isDebugEnabled()) { logger.debug("Days in month " + LocalDate.now().getMonth() + ": " + LocalDate.now().getMonth().minLength()); } if (logger.isInfoEnabled()) { logger.info("Airbnb long term booking, looking at manual registered payments"); } Optional<Payment> op = Payments.getLastPayment(b.getPayments()); MonetaryAmount payment; if (op.isPresent()) { payment = op.get().getAmount(); } else { payment = moneyFactory.setNumber(0).create(); } if(logger.isDebugEnabled()){ logger.debug("Payment is " + payment); } result = result.add(payment); } else result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }  AirbnbEarningsCalculator filterToDateRange(Range<LocalDate> dateRange); AirbnbEarningsCalculator filterForPaymentDone(boolean paymentDone); AirbnbEarningsCalculator filterForNetEarnings(boolean netEarnigns); Range<LocalDate> getDateRange(); float calculateEarnings(Collection<? extends BookingBean> bookings); }
AirbnbEarningsCalculator 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(); if (logger.isDebugEnabled()) { logger.debug("Calculating earnings for\n" + bookings.stream().map(b -> b.toString()).collect(Collectors.joining("\n"))); } for (BookingBean b : bookings) { if (b.getNumberOfNights() > LocalDate.now().getMonth().minLength()) { if (logger.isDebugEnabled()) { logger.debug("Days in month " + LocalDate.now().getMonth() + ": " + LocalDate.now().getMonth().minLength()); } if (logger.isInfoEnabled()) { logger.info("Airbnb long term booking, looking at manual registered payments"); } Optional<Payment> op = Payments.getLastPayment(b.getPayments()); MonetaryAmount payment; if (op.isPresent()) { payment = op.get().getAmount(); } else { payment = moneyFactory.setNumber(0).create(); } if(logger.isDebugEnabled()){ logger.debug("Payment is " + payment); } result = result.add(payment); } else result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create()); } return result.getNumber().floatValue(); }  AirbnbEarningsCalculator filterToDateRange(Range<LocalDate> dateRange); AirbnbEarningsCalculator filterForPaymentDone(boolean paymentDone); AirbnbEarningsCalculator filterForNetEarnings(boolean netEarnigns); Range<LocalDate> getDateRange(); float calculateEarnings(Collection<? extends BookingBean> bookings);  }