SABSSlidingScaleUnitValue.java
package com.tradecloud.domain.sabs;
import com.tradecloud.common.base.HibernateUtils;
import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.item.UnitType;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.ForeignKey;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.*;
@Entity
@Table(name = "sabsslidingscaleunitvalue")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SABSSlidingScaleUnitValue")
public class SABSSlidingScaleUnitValue extends PersistenceBase implements Comparable<SABSSlidingScaleUnitValue> {
private static final long serialVersionUID = 1L;
@XmlAttribute(required = true)
@NotNull(message = "Unit Value is required")
@Column(nullable = false)
private Integer unitValue;
// @XmlAttribute(required = true)
// @NotNull(message = "Unit Type is required")
// @Column(nullable = false)
@ManyToOne
@XmlElement(name = "UnitType", required = true)
@JoinColumn(name = "unittype_code", referencedColumnName = "code")
@ForeignKey(name = "fk_unittype")
private UnitType unitType;
@XmlAttribute(required = true)
@NotNull(message = "Unit Value is required")
@Column(nullable = false)
private Integer sequence;
public SABSSlidingScaleUnitValue(Integer unitValue) {
this.unitValue = unitValue;
}
public SABSSlidingScaleUnitValue(Integer unitValue, UnitType unitType, Integer sequence) {
super();
this.unitValue = unitValue;
this.unitType = unitType;
this.sequence = sequence;
}
public SABSSlidingScaleUnitValue(SABSSlidingScaleUnitValue other) {
super();
this.unitType = other.getUnitType();
this.unitValue = other.getUnitValue();
this.sequence = other.getSequence();
}
/**
* Constructor.
*/
public SABSSlidingScaleUnitValue() {
super();
this.sequence = 0;
}
public Integer getUnitValue() {
return unitValue;
}
public void setUnitValue(Integer unitValue) {
this.unitValue = unitValue;
}
public UnitType getUnitType() {
return unitType;
}
public void setUnitType(UnitType unitType) {
this.unitType = unitType;
}
public Integer getSequence() {
return sequence;
}
public void setSequence(Integer sequence) {
this.sequence = sequence;
}
@Override
public String toString() {
return new ToStringBuilder(this).
append("unitValue", unitValue).
append("unitType", unitType).
append("sequence", sequence).
append("id", super.getId()).
toString();
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (unitValue != null ? unitValue.hashCode() : 0);
result = 31 * result + (unitType != null ? unitType.hashCode() : 0);
result = 31 * result + (sequence != null ? sequence.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!HibernateUtils.proxyClassEquals(this, obj)) {
return false;
}
final SABSSlidingScaleUnitValue other = (SABSSlidingScaleUnitValue) obj;
boolean equals = new EqualsBuilder().appendSuper(super.equals(obj))
.append(sequence, other.getSequence())
.append(unitValue, other.getUnitValue()).isEquals();
return equals;
}
public int compareTo(SABSSlidingScaleUnitValue other) {
if (getUnitType() != null) {
if (getUnitType().compareTo(other.getUnitType()) != 0) {
return getUnitValue().compareTo(other.getUnitValue());
}
}
return 0;
}
}