Skip to content

Commit

Permalink
junction: Refactor method BlockingCalculator#precedingBillingEventFor…
Browse files Browse the repository at this point in the history
…Subscription
  • Loading branch information
sbrossie committed Apr 30, 2017
1 parent b6e886d commit b968f80
Showing 1 changed file with 8 additions and 12 deletions.
Expand Up @@ -172,7 +172,7 @@ protected SortedSet<BillingEvent> eventsToRemove(final List<DisabledDuration> di
for (final DisabledDuration duration : disabledDuration) {
for (final BillingEvent event : subscriptionBillingEvents) {
if (duration.getEnd() == null || event.getEffectiveDate().isBefore(duration.getEnd())) {
if (!event.getEffectiveDate().isBefore(duration.getStart())) { //between the pair
if (!event.getEffectiveDate().isBefore(duration.getStart())) {
result.add(event);
}
} else { //after the last event of the pair no need to keep checking
Expand Down Expand Up @@ -207,29 +207,25 @@ protected SortedSet<BillingEvent> createNewEvents(final List<DisabledDuration> d
return result;
}


protected BillingEvent precedingBillingEventForSubscription(final DateTime disabledDurationStart, final SortedSet<BillingEvent> subscriptionBillingEvents) {
if (disabledDurationStart == null) {
return null;
}

BillingEvent result = subscriptionBillingEvents.first();

// Use case where we first Block and the create the subscription for instance
// (disabledDurationStart could be before start subscription or align right at the same exact time)
if (!disabledDurationStart.isAfter(result.getEffectiveDate())) {
return null;
}

// We look for the first billingEvent strictly prior our disabledDurationStart or null if none
BillingEvent prev = null;
for (final BillingEvent event : subscriptionBillingEvents) {
if (!event.getEffectiveDate().isBefore(disabledDurationStart)) {
return result;
return prev;
} else {
result = event;
prev = event;
}
}
return result;
return prev;
}


protected SortedSet<BillingEvent> filter(final SortedSet<BillingEvent> billingEvents, final SubscriptionBase subscription) {
final SortedSet<BillingEvent> result = new TreeSet<BillingEvent>();
for (final BillingEvent event : billingEvents) {
Expand Down

0 comments on commit b968f80

Please sign in to comment.