CreditorBillingEffectiveDateConfig.java

package com.tradecloud.domain.creditorbilling.transaction;

import com.tradecloud.common.base.PersistenceBase;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * Used to configure which actual date to use when looking up the. rate in the
 * rates table when creating or updating a creditor invoice transaction
 */
@Entity
@Table(name = "cbeffectivedateconfig")
public class CreditorBillingEffectiveDateConfig extends PersistenceBase implements Comparable {

    /*"Freight", "Destination landing Charges", "Forwarding" costgroups*/
    @NotNull
    @Column(name = "costgroup")
    private String costGroup;

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "cbeffectivedate")
    private CreditorBillingEffectiveDate creditorInvoiceEffectiveDateConfig;

    public CreditorBillingEffectiveDateConfig() {
    }

    public CreditorBillingEffectiveDateConfig(String costGroup, CreditorBillingEffectiveDate creditorInvoiceEffectiveDateConfig) {
        this.costGroup = costGroup;
        this.creditorInvoiceEffectiveDateConfig = creditorInvoiceEffectiveDateConfig;
    }

    public String getCostGroup() {
        return costGroup;
    }

    public void setCostGroup(String costGroup) {
        this.costGroup = costGroup;
    }

    public CreditorBillingEffectiveDate getCreditorInvoiceEffectiveDateConfig() {
        return creditorInvoiceEffectiveDateConfig;
    }

    public void setCreditorInvoiceEffectiveDateConfig(CreditorBillingEffectiveDate creditorInvoiceEffectiveDateConfig) {
        this.creditorInvoiceEffectiveDateConfig = creditorInvoiceEffectiveDateConfig;
    }

    @Override
    public int compareTo(Object o) {

        if (o instanceof CreditorBillingEffectiveDateConfig) {
            CreditorBillingEffectiveDateConfig creditorBillDatesConfig = (CreditorBillingEffectiveDateConfig) o;
            return this.costGroup.compareTo(creditorBillDatesConfig.getCostGroup());
        }

        return -1;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof CreditorBillingEffectiveDateConfig) {
            CreditorBillingEffectiveDateConfig creditorBillDate = (CreditorBillingEffectiveDateConfig) obj;
            return this.costGroup.equals(creditorBillDate.getCostGroup());
        }

        return false;

    }

    @Override
    public int hashCode() {
        return this.costGroup.hashCode();
    }
}