コード例 #1
0
 @Override
 public int hashCode() {
   int result = accountId != null ? accountId.hashCode() : 0;
   result = 31 * result + (bundleId != null ? bundleId.hashCode() : 0);
   result = 31 * result + (subscriptionId != null ? subscriptionId.hashCode() : 0);
   result = 31 * result + (externalKey != null ? externalKey.hashCode() : 0);
   result = 31 * result + (startDate != null ? startDate.hashCode() : 0);
   result = 31 * result + (productName != null ? productName.hashCode() : 0);
   result = 31 * result + (productCategory != null ? productCategory.hashCode() : 0);
   result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0);
   result = 31 * result + (phaseType != null ? phaseType.hashCode() : 0);
   result = 31 * result + (priceList != null ? priceList.hashCode() : 0);
   result = 31 * result + (planName != null ? planName.hashCode() : 0);
   result = 31 * result + (state != null ? state.hashCode() : 0);
   result = 31 * result + (sourceType != null ? sourceType.hashCode() : 0);
   result = 31 * result + (cancelledDate != null ? cancelledDate.hashCode() : 0);
   result = 31 * result + (chargedThroughDate != null ? chargedThroughDate.hashCode() : 0);
   result = 31 * result + (billingStartDate != null ? billingStartDate.hashCode() : 0);
   result = 31 * result + (billingEndDate != null ? billingEndDate.hashCode() : 0);
   result = 31 * result + (billCycleDayLocal != null ? billCycleDayLocal.hashCode() : 0);
   result = 31 * result + (events != null ? events.hashCode() : 0);
   result = 31 * result + (priceOverrides != null ? priceOverrides.hashCode() : 0);
   return result;
 }
コード例 #2
0
  @VisibleForTesting
  LocalDate getOptimizedRawUsageStartDate(
      final LocalDate firstEventStartDate,
      final LocalDate targetDate,
      final Iterable<InvoiceItem> existingUsageItems,
      final Map<String, Usage> knownUsage) {

    if (!existingUsageItems.iterator().hasNext()) {
      return firstEventStartDate;
    }
    // Extract all usage billing period known in that catalog
    final Set<BillingPeriod> knownUsageBillingPeriod =
        ImmutableSet.copyOf(
            Iterables.transform(
                knownUsage.values(),
                new Function<Usage, BillingPeriod>() {
                  @Nullable
                  @Override
                  public BillingPeriod apply(final Usage input) {
                    return input.getBillingPeriod();
                  }
                }));

    // Make sure all usage items are sorted by endDate
    final List<InvoiceItem> sortedUsageItems = USAGE_ITEM_ORDERING.sortedCopy(existingUsageItems);

    // Compute an array with one date per BillingPeriod:
    // If BillingPeriod is never defined in the catalog (no need to look for items), we initialize
    // its value
    // such that it cannot be chosen
    //
    final LocalDate[] perBillingPeriodMostRecentConsumableInArrearItemEndDate =
        new LocalDate[BillingPeriod.values().length - 1]; // Exclude the NO_BILLING_PERIOD
    int idx = 0;
    for (BillingPeriod bp : BillingPeriod.values()) {
      if (bp != BillingPeriod.NO_BILLING_PERIOD) {
        final LocalDate makerDateThanCannotBeChosenAsTheMinOfAllDates =
            targetDate.plusMonths(config.getMaxRawUsagePreviousPeriod() * bp.getNumberOfMonths());
        perBillingPeriodMostRecentConsumableInArrearItemEndDate[idx++] =
            (knownUsageBillingPeriod.contains(bp))
                ? null
                : makerDateThanCannotBeChosenAsTheMinOfAllDates;
      }
    }

    final ListIterator<InvoiceItem> iterator =
        sortedUsageItems.listIterator(sortedUsageItems.size());
    while (iterator.hasPrevious()) {
      final InvoiceItem previous = iterator.previous();
      Preconditions.checkState(previous instanceof UsageInvoiceItem);
      final UsageInvoiceItem item = (UsageInvoiceItem) previous;
      final Usage usage = knownUsage.get(item.getUsageName());

      if (perBillingPeriodMostRecentConsumableInArrearItemEndDate[
              usage.getBillingPeriod().ordinal()]
          == null) {
        perBillingPeriodMostRecentConsumableInArrearItemEndDate[
                usage.getBillingPeriod().ordinal()] =
            item.getEndDate();
        if (!containsNullEntries(perBillingPeriodMostRecentConsumableInArrearItemEndDate)) {
          break;
        }
      }
    }

    // Extract the min from all the dates
    LocalDate targetStartDate = null;
    idx = 0;
    for (BillingPeriod bp : BillingPeriod.values()) {
      if (bp != BillingPeriod.NO_BILLING_PERIOD) {
        final LocalDate tmp = perBillingPeriodMostRecentConsumableInArrearItemEndDate[idx];
        final LocalDate targetBillingPeriodDate =
            tmp != null
                ? tmp.minusMonths(config.getMaxRawUsagePreviousPeriod() * bp.getNumberOfMonths())
                : null;
        if (targetStartDate == null
            || (targetBillingPeriodDate != null
                && targetBillingPeriodDate.compareTo(targetStartDate) < 0)) {
          targetStartDate = targetBillingPeriodDate;
        }
        idx++;
      }
    }

    final LocalDate result =
        targetStartDate.compareTo(firstEventStartDate) > 0 ? targetStartDate : firstEventStartDate;
    return result;
  }
コード例 #3
0
 @Override
 public int hashCode() {
   int result = billingPeriod != null ? billingPeriod.hashCode() : 0;
   result = 31 * result + (recurringPrice != null ? recurringPrice.hashCode() : 0);
   return result;
 }