AbstractDutyRate.java
package com.tradecloud.domain.duties;
import com.tradecloud.common.base.PersistenceBase;
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.XmlElement;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* Base class that holds all the common data for duty rates. Duty rates with
* more specific requirements can subclass this class for convenience.
*/
@MappedSuperclass
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractDutyRate extends PersistenceBase implements Serializable {
private static final long serialVersionUID = 1L;
/**
* The item quantity will be multiplied by the value entered in this field.
*/
@XmlAttribute
@Column(precision = 19, scale = 5)
private BigDecimal value;
/**
* A duty that will be applied on additional parts of the product.
*/
@Embedded
@AttributeOverrides({@AttributeOverride(name = "value", column = @Column(name = "duty1value")),
@AttributeOverride(name = "unit", column = @Column(name = "duty1unit")),
@AttributeOverride(name = "proof", column = @Column(name = "duty1proof")),
@AttributeOverride(name = "additionalValue", column = @Column(name = "duty1additionalvalue"))})
@XmlElement(name = "OtherDuty1")
private OtherDuty otherDuty1;
/**
* A duty that will be applied on additional parts of the product.
*/
@Embedded
@AttributeOverrides({@AttributeOverride(name = "value", column = @Column(name = "duty2value")),
@AttributeOverride(name = "unit", column = @Column(name = "duty2unit")),
@AttributeOverride(name = "proof", column = @Column(name = "duty2proof")),
@AttributeOverride(name = "additionalValue", column = @Column(name = "duty2additionalvalue"))})
@XmlElement(name = "OtherDuty2")
private OtherDuty otherDuty2;
/**
* A duty that will be applied on additional parts of the product.
*/
@Embedded
@AttributeOverrides({@AttributeOverride(name = "value", column = @Column(name = "duty3value")),
@AttributeOverride(name = "unit", column = @Column(name = "duty3unit")),
@AttributeOverride(name = "proof", column = @Column(name = "duty3proof")),
@AttributeOverride(name = "additionalValue", column = @Column(name = "duty3additionalvalue"))})
@XmlElement(name = "OtherDuty3")
private OtherDuty otherDuty3;
public AbstractDutyRate() {
}
public AbstractDutyRate(AbstractDutyRate abstractDutyRate) {
value = abstractDutyRate.value;
otherDuty1 = new OtherDuty(abstractDutyRate.getOtherDuty1());
otherDuty2 = new OtherDuty(abstractDutyRate.getOtherDuty2());
otherDuty3 = new OtherDuty(abstractDutyRate.getOtherDuty3());
}
public BigDecimal getValue() {
return value;
}
public void setValue(BigDecimal value) {
this.value = value;
}
public OtherDuty getOtherDuty1() {
if (otherDuty1 == null) {
otherDuty1 = new OtherDuty();
}
return otherDuty1;
}
public void setOtherDuty1(OtherDuty otherDuty1) {
this.otherDuty1 = otherDuty1;
}
public OtherDuty getOtherDuty2() {
if (otherDuty2 == null) {
otherDuty2 = new OtherDuty();
}
return otherDuty2;
}
public void setOtherDuty2(OtherDuty otherDuty2) {
this.otherDuty2 = otherDuty2;
}
public OtherDuty getOtherDuty3() {
if (otherDuty3 == null) {
otherDuty3 = new OtherDuty();
}
return otherDuty3;
}
public void setOtherDuty3(OtherDuty otherDuty3) {
this.otherDuty3 = otherDuty3;
}
public BigDecimal getPercentage() {
return null;
}
public void setPercentage(BigDecimal percentage) {
}
@Override
public AbstractDutyRate clone() {
AbstractDutyRate clone = (AbstractDutyRate) super.clone();
clone.setValue(value);
clone.setOtherDuty1(otherDuty1 != null ? otherDuty1.clone() : null);
clone.setOtherDuty2(otherDuty2 != null ? otherDuty2.clone() : null);
clone.setOtherDuty3(otherDuty3 != null ? otherDuty3.clone() : null);
return clone;
}
@Override
public String toString() {
return new ToStringBuilder(this).append("value", value).append("otherDuty1", otherDuty1).append("otherDuty2", otherDuty2)
.append("otherDuty3", otherDuty3).toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof AbstractDutyRate)) {
return false;
}
AbstractDutyRate other = (AbstractDutyRate) obj;
return new EqualsBuilder()
.append(value, other.value)
.append(otherDuty1, other.otherDuty1)
.append(otherDuty2, other.otherDuty2)
.append(otherDuty3, other.otherDuty3)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(value)
.append(otherDuty1)
.append(otherDuty2)
.append(otherDuty3)
.toHashCode();
}
}