TransporterCostline.java

package com.tradecloud.domain.transporter;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.costing.CostLine;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;

@Entity
@Table(name = "transporter_costline")
@Access(AccessType.FIELD)
public class TransporterCostline extends PersistenceBase implements Serializable, Comparable<TransporterCostline> {

    @ManyToOne
    @NotNull(message = "costLine is required")
    private CostLine costLine;

    private BigDecimal amount;

    private BigDecimal vat;

    @NotNull(message = "transporterCostingId is required")
    @Column(name = "transporter_costing_id")
    private Long transporterCostingId;

    public TransporterCostline() {
    }

    public TransporterCostline(CostLine costLine, Long transporterCostingId) {
        this.costLine = costLine;
        this.transporterCostingId = transporterCostingId;
    }

    public TransporterCostline(CostLine costLine) {
        this.costLine = costLine;
    }

    public CostLine getCostLine() {
        return costLine;
    }

    public void setCostLine(CostLine costLine) {
        this.costLine = costLine;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public BigDecimal getVat() {
        return vat;
    }

    public void setVat(BigDecimal vat) {
        this.vat = vat;
    }

    public Long getTransporterCostingId() {
        return transporterCostingId;
    }

    public void setTransporterCostingId(Long transporterCostingId) {
        this.transporterCostingId = transporterCostingId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof TransporterCostline that)) return false;
        return Objects.equals(getCostLine(), that.getCostLine()) && Objects.equals(getTransporterCostingId(), that.getTransporterCostingId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getCostLine(), getTransporterCostingId());
    }

    @Override
    public int compareTo(TransporterCostline o) {
        return this.getCostLine().compareTo(o.getCostLine());
    }
}