FinanceRate.java

package com.tradecloud.domain.rate;

/**
 * Created by ds on 2017/01/09.
 */

import com.tradecloud.domain.item.ItemCategory;
import com.tradecloud.domain.model.payment.PaymentMethod;
import com.tradecloud.domain.model.payment.PaymentTerm;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import java.math.BigDecimal;

@Entity
@Table(name = "financeRate")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
public class FinanceRate extends Rate implements MinMaxRate {

    private static final long serialVersionUID = 1L;

    @NotNull
    @ManyToOne
    private PaymentMethod paymentMethod;

    @ManyToOne
    private PaymentTerm paymentTerm;

    private BigDecimal minimum;
    private BigDecimal maximum;
    @ManyToOne
    private ItemCategory itemCategory;

    public PaymentMethod getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public PaymentTerm getPaymentTerm() {
        return paymentTerm;
    }

    public void setPaymentTerm(PaymentTerm paymentTerm) {
        this.paymentTerm = paymentTerm;
    }

    public void setMaximum(BigDecimal maximum) {
        this.maximum = maximum;
    }

    public void setMinimum(BigDecimal minimum) {
        this.minimum = minimum;
    }

    public BigDecimal getMinimum() {
        return minimum;
    }

    public BigDecimal getMaximum() {
        return maximum;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        FinanceRate that = (FinanceRate) o;

        return new EqualsBuilder().append(paymentMethod, that.getPaymentMethod()).append(paymentTerm, that.getPaymentTerm()).
                append(minimum, that.getMinValue()).append(maximum, that.getMaxValue())
                .append(getOrganisationalUnit(), that.getOrganisationalUnit()).append(itemCategory, that.getItemCategory()).isEquals();
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        int hashCode = new HashCodeBuilder().append(paymentMethod).append(paymentTerm).append(minimum).append(maximum).
                append(getOrganisationalUnit()).append(itemCategory).toHashCode();
        return result + hashCode;
    }

    @Override
    public BigDecimal getMinValue() {
        return minimum;
    }

    @Override
    public BigDecimal getMaxValue() {
        return maximum;
    }

    public ItemCategory getItemCategory() {
        return itemCategory;
    }

    public void setItemCategory(ItemCategory itemCategory) {
        this.itemCategory = itemCategory;
    }
}