OtherDuty.java
package com.tradecloud.domain.duties;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* A embeddable value class that holds 3 tightly coupled fields for convenience.
*/
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "OtherDuty")
@Embeddable
public class OtherDuty implements Serializable, Cloneable {
/**
* A duty that will be applied on additional parts of the product.
*/
@XmlAttribute
@Column(precision = 19, scale = 5)
private BigDecimal value;
/**
* The type of unit associated to {@link #value}.
*/
@Enumerated(value = EnumType.STRING)
@XmlAttribute
private DutyUnit unit;
/**
* An additional duty value that will be applied to the product.
*/
@XmlAttribute
@Column(precision = 19, scale = 5)
private BigDecimal additionalValue;
/**
* Proof value is only eligible to Scedule1 Part2A.
*/
@XmlAttribute
@Column(precision = 19, scale = 5)
private BigDecimal proof;
public OtherDuty() {
}
public OtherDuty(OtherDuty otherDuty) {
value = otherDuty.value;
unit = otherDuty.unit;
additionalValue = otherDuty.additionalValue;
proof = otherDuty.proof;
}
public BigDecimal getValue() {
return value;
}
public void setValue(BigDecimal value) {
this.value = value;
}
public DutyUnit getUnit() {
return unit;
}
public void setUnit(DutyUnit unit) {
this.unit = unit;
}
public BigDecimal getAdditionalValue() {
return additionalValue;
}
public void setAdditionalValue(BigDecimal additionalValue) {
this.additionalValue = additionalValue;
}
public BigDecimal getProof() {
return proof;
}
public void setProof(BigDecimal proof) {
this.proof = proof;
}
@Override
public OtherDuty clone() {
try {
OtherDuty clone = (OtherDuty) super.clone();
clone.setAdditionalValue(additionalValue);
clone.setUnit(unit);
clone.setValue(value);
clone.setProof(proof);
return clone;
} catch (CloneNotSupportedException ex) {
return null;
}
}
@Override
public String toString() {
return new ToStringBuilder(this).append("value", value).append("unit", unit).append("additionalValue", additionalValue).toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof OtherDuty)) {
return false;
}
OtherDuty other = (OtherDuty) obj;
return new EqualsBuilder().append(value, other.value).append(unit, other.unit).append(additionalValue, other.additionalValue).isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(value).append(unit).append(additionalValue).toHashCode();
}
}