<commit_before>/*
 * Copyright 2010-2011 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.ning.billing.invoice.model;

import java.math.BigDecimal;
import java.util.UUID;

import org.joda.time.DateTime;

import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceItemType;

public class RecurringInvoiceItem extends InvoiceItemBase {
    private final BigDecimal rate;
    private final UUID reversedItemId;

    public RecurringInvoiceItem(final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId, final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency) {
        super(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency, InvoiceItemType.RECURRING);
        this.rate = rate;
        this.reversedItemId = null;
    }

    public RecurringInvoiceItem(final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId, final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency, final UUID reversedItemId) {
        super(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate,
              amount, currency, InvoiceItemType.REVERSAL);
        this.rate = rate;
        this.reversedItemId = reversedItemId;
    }

    public RecurringInvoiceItem(final UUID id, final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId,
                                final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency) {
        super(id, invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency, InvoiceItemType.RECURRING);
        this.rate = rate;
        this.reversedItemId = null;
    }

    public RecurringInvoiceItem(final UUID id, final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId,
                                final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency, final UUID reversedItemId) {
        super(id, invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency, InvoiceItemType.REVERSAL);
        this.rate = rate;
        this.reversedItemId = reversedItemId;
    }

    @Override
    public InvoiceItem asReversingItem() {
        final BigDecimal amountNegated = amount == null ? null : amount.negate();

        return new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate,
                                        amountNegated, rate, currency, id);
    }

    @Override
    public String getDescription() {
        return String.format("%s from %s to %s", phaseName, startDate.toString(), endDate.toString());
    }

    public UUID getReversedItemId() {
        return reversedItemId;
    }

    public boolean reversesItem() {
        return (reversedItemId != null);
    }<commit_msg>invoice: make recurring invoice items description prettier<commit_after>/*
 * Copyright 2010-2011 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.ning.billing.invoice.model;

import java.math.BigDecimal;
import java.util.UUID;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceItemType;

public class RecurringInvoiceItem extends InvoiceItemBase {
    private final DateTimeFormatter dateTimeFormatter = DateTimeFormat.mediumDate();

    private final BigDecimal rate;
    private final UUID reversedItemId;

    public RecurringInvoiceItem(final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId, final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency) {
        super(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency, InvoiceItemType.RECURRING);
        this.rate = rate;
        this.reversedItemId = null;
    }

    public RecurringInvoiceItem(final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId, final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency, final UUID reversedItemId) {
        super(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate,
              amount, currency, InvoiceItemType.REVERSAL);
        this.rate = rate;
        this.reversedItemId = reversedItemId;
    }

    public RecurringInvoiceItem(final UUID id, final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId,
                                final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency) {
        super(id, invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency, InvoiceItemType.RECURRING);
        this.rate = rate;
        this.reversedItemId = null;
    }

    public RecurringInvoiceItem(final UUID id, final UUID invoiceId, final UUID accountId, final UUID bundleId, final UUID subscriptionId,
                                final String planName, final String phaseName,
                                final DateTime startDate, final DateTime endDate,
                                final BigDecimal amount, final BigDecimal rate,
                                final Currency currency, final UUID reversedItemId) {
        super(id, invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency, InvoiceItemType.REVERSAL);
        this.rate = rate;
        this.reversedItemId = reversedItemId;
    }

    @Override
    public InvoiceItem asReversingItem() {
        final BigDecimal amountNegated = amount == null ? null : amount.negate();

        return new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate,
                                        amountNegated, rate, currency, id);
    }

    @Override
    public String getDescription() {
        return String.format("%s from %s to %s", phaseName, startDate.toString(dateTimeFormatter), endDate.toString(dateTimeFormatter));
    }

    public UUID getReversedItemId() {
        return reversedItemId;
    }

    public boolean reversesItem() {
        return (reversedItemId != null);
    }
{'fraction_non_alphanumeric': 0.06662210338680927, 'fraction_numerical': 0.00267379679144385, 'mean_word_length': 2.6153846153846154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '536488', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2215, 'n_words': 763}