Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.smartdukaan.cron.offercircular;

import java.util.Collections;
import java.util.List;

/**
 * One row of the Pine Labs affordability circular, exactly as printed.
 *
 * The nine columns are kept verbatim - no interpretation happens here. Everything
 * downstream (benefit amounts, tenures, banks, products) is derived from these
 * strings, and they are also what the review screen displays, so a row that cannot
 * be parsed is still recorded rather than dropped.
 */
public class CircularRow {

    private final int pageNo;
    private final int rowNo;
    private final String oemLabel;
    private final String additionalCashback;
    private final String description;
    private final String emiTenure;
    private final String debitCards;
    private final String creditCards;
    private final String eligibleProducts;
    private final String startDateRaw;
    private final String endDateRaw;

    /** @param middle the six cells between the OEM label and the two dates */
    public CircularRow(int pageNo, int rowNo, String oemLabel, List<String> middle,
                       String startDateRaw, String endDateRaw) {
        if (middle == null || middle.size() != MIDDLE_CELL_COUNT) {
            throw new IllegalArgumentException(
                    "expected " + MIDDLE_CELL_COUNT + " middle cells, got "
                            + (middle == null ? "null" : middle.size()));
        }
        this.pageNo = pageNo;
        this.rowNo = rowNo;
        this.oemLabel = oemLabel;
        this.additionalCashback = middle.get(0);
        this.description = middle.get(1);
        this.emiTenure = middle.get(2);
        this.debitCards = middle.get(3);
        this.creditCards = middle.get(4);
        this.eligibleProducts = middle.get(5);
        this.startDateRaw = startDateRaw;
        this.endDateRaw = endDateRaw;
    }

    public static final int MIDDLE_CELL_COUNT = 6;

    public int getPageNo() { return pageNo; }
    public int getRowNo() { return rowNo; }
    public String getOemLabel() { return oemLabel; }
    public String getAdditionalCashback() { return additionalCashback; }
    public String getDescription() { return description; }
    public String getEmiTenure() { return emiTenure; }
    public String getDebitCards() { return debitCards; }
    public String getCreditCards() { return creditCards; }
    public String getEligibleProducts() { return eligibleProducts; }
    public String getStartDateRaw() { return startDateRaw; }
    public String getEndDateRaw() { return endDateRaw; }

    public List<String> getMiddleCells() {
        return Collections.unmodifiableList(java.util.Arrays.asList(
                additionalCashback, description, emiTenure,
                debitCards, creditCards, eligibleProducts));
    }

    @Override
    public String toString() {
        return "p" + pageNo + "r" + rowNo + " [" + oemLabel + "] " + description
                + " | " + startDateRaw + " -> " + endDateRaw;
    }
}