SABSSlidingScaleIncrement.java

package com.tradecloud.domain.sabs;

import com.tradecloud.common.base.HibernateUtils;
import com.tradecloud.common.base.PersistenceBase;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import java.math.BigDecimal;

@Entity
@Table(name = "sabsslidingscaleincrement")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SABSSlidingScaleIncrements")
public class SABSSlidingScaleIncrement extends PersistenceBase implements Comparable<SABSSlidingScaleIncrement> {

    private static final long serialVersionUID = 1L;

    @XmlAttribute(required = true)
    @NotNull(message = "Unit Number is required")
    @Column(nullable = false)
    private Integer unitNumber;

    @XmlAttribute(required = true)
    @NotNull(message = "Tariff Value is required")
    @Column(nullable = false)
    private BigDecimal tariffValue;

    @XmlAttribute(required = true)
    @NotNull(message = "Unit Value is required")
    @Column(nullable = false)
    private Integer sequence;

    public SABSSlidingScaleIncrement(Integer unitNumber, BigDecimal tariffValue, Integer sequence) {
        super();
        this.unitNumber = unitNumber;
        this.tariffValue = tariffValue;
        this.sequence = sequence;
    }

    public SABSSlidingScaleIncrement(SABSSlidingScaleIncrement other) {
        super();
        this.unitNumber = other.getUnitNumber();
        this.tariffValue = other.getTariffValue();
        this.sequence = other.getSequence();
    }

    public SABSSlidingScaleIncrement() {
        super();
        this.sequence = 0;
    }

    public Integer getUnitNumber() {
        return unitNumber;
    }

    public void setUnitNumber(Integer unitNumber) {
        this.unitNumber = unitNumber;
    }

    public BigDecimal getTariffValue() {
        return tariffValue;
    }

    public void setTariffValue(BigDecimal tariffValue) {
        this.tariffValue = tariffValue;
    }

    public Integer getSequence() {
        return sequence;
    }

    public void setSequence(Integer sequence) {
        this.sequence = sequence;
    }

    // TODO. Use HashCodeBuilder
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((tariffValue == null) ? 0 : tariffValue.hashCode());
        result = prime * result + ((unitNumber == null) ? 0 : unitNumber.hashCode());
        result = prime * result + ((sequence == null) ? 0 : sequence.hashCode());
        return result;
    }

    // TODO. Use EqualsBuilder
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (!HibernateUtils.proxyClassEquals(this, obj))
            return false;
        SABSSlidingScaleIncrement other = (SABSSlidingScaleIncrement) obj;
        if (tariffValue == null) {
            if (other.tariffValue != null)
                return false;
        } else if (!unitNumber.equals(other.unitNumber))
            return false;
        if (sequence == null) {
            if (other.sequence != null)
                return false;
        } else if (!sequence.equals(other.sequence))
            return false;
        return true;
    }

    @Override
    public int compareTo(SABSSlidingScaleIncrement other) {
        if (getUnitNumber() != null) {
            if (getUnitNumber().compareTo(other.getUnitNumber()) != 0) {
                return getTariffValue().compareTo(other.getTariffValue());
            }
        }
        return 0;
    }

}