protected SortedSet<BillingEvent> eventsToRemove(final List<DisabledDuration> disabledDuration, final SortedSet<BillingEvent> billingEvents, final SubscriptionBase subscription) { final SortedSet<BillingEvent> result = new TreeSet<BillingEvent>(); final SortedSet<BillingEvent> filteredBillingEvents = filter(billingEvents, subscription); for (final DisabledDuration duration : disabledDuration) { for (final BillingEvent event : filteredBillingEvents) { if (duration.getEnd() == null || event.getEffectiveDate().isBefore(duration.getEnd())) { if (event.getEffectiveDate().isAfter(duration.getStart())) { //between the pair result.add(event); } } else { //after the last event of the pair no need to keep checking break; } } } return result; }
protected SortedSet<BillingEvent> createNewEvents(final List<DisabledDuration> disabledDuration, final SortedSet<BillingEvent> billingEvents, final Account account, final SubscriptionBase subscription) { final SortedSet<BillingEvent> result = new TreeSet<BillingEvent>(); for (final DisabledDuration duration : disabledDuration) { // The first one before the blocked duration final BillingEvent precedingInitialEvent = precedingBillingEventForSubscription(duration.getStart(), billingEvents, subscription); // The last one during of before the duration final BillingEvent precedingFinalEvent = precedingBillingEventForSubscription(duration.getEnd(), billingEvents, subscription); if (precedingInitialEvent != null) { // there is a preceding billing event result.add(createNewDisableEvent(duration.getStart(), precedingInitialEvent)); if (duration.getEnd() != null) { // no second event in the pair means they are still disabled (no re-enable) result.add(createNewReenableEvent(duration.getEnd(), precedingFinalEvent)); } } else if (precedingFinalEvent != null) { // can happen - e.g. phase event result.add(createNewReenableEvent(duration.getEnd(), precedingFinalEvent)); } // N.B. if there's no precedingInitial and no precedingFinal then there's nothing to do } return result; }
assertNotNull(pairs.get(0).getStart()); assertEquals(pairs.get(0).getStart(), now.plusDays(1)); assertNull(pairs.get(0).getEnd()); assertNotNull(pairs.get(0).getStart()); assertEquals(pairs.get(0).getStart(), now.plusDays(1)); assertNotNull(pairs.get(0).getEnd()); assertEquals(pairs.get(0).getEnd(), now.plusDays(2)); assertNotNull(pairs.get(0).getStart()); assertEquals(pairs.get(0).getStart(), now.plusDays(1)); assertNotNull(pairs.get(0).getEnd()); assertEquals(pairs.get(0).getEnd(), now.plusDays(2)); assertNotNull(pairs.get(0).getStart()); assertEquals(pairs.get(0).getStart(), now.plusDays(1)); assertNotNull(pairs.get(0).getEnd()); assertEquals(pairs.get(0).getEnd(), now.plusDays(3)); assertNotNull(pairs.get(0).getStart()); assertEquals(pairs.get(0).getStart(), now.plusDays(1)); assertNotNull(pairs.get(0).getEnd()); assertEquals(pairs.get(0).getEnd(), now.plusDays(4)); assertEquals(pairs.get(0).getStart(), now.plusDays(1)); assertEquals(pairs.get(0).getEnd(), now.plusDays(3)); assertEquals(pairs.get(0).getStart(), now.plusDays(1)); assertEquals(pairs.get(0).getEnd(), now.plusDays(3));