Schedule1Part7.java

package com.tradecloud.domain.duties;

import com.tradecloud.domain.costing.clean.CostLineNames;
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;

/**
 * Entity representing Schedule 2 Part 1 - Anti-Dumping.
 */
@Entity
@Table(name = "schedule1part7")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Schedule1Part7")
public class Schedule1Part7 extends TypedDutySchedule implements Serializable, Cloneable {

    private static final long serialVersionUID = 1L;

    @Transient
    public final int PART1_MAX_LENGTH = 3;

    /**
     * The method that will be used to calculate the "Other Duty" values.
     */
    @Enumerated(value = EnumType.STRING)
    @XmlAttribute
    private DutyCalculationMethod calculationMethod;

    public Schedule1Part7() {
        super();
        if (getDutyRate() == null) {
            dutyRate = new TypedDutyRate();
            dutyRate.setOtherDuty1(new OtherDuty());
            dutyRate.setOtherDuty2(new OtherDuty());
            dutyRate.setOtherDuty3(new OtherDuty());
        }
        dutyRate.setType(DutyType.ENVIRONMENTAL);
    }

    public Schedule1Part7(Schedule1Part7 schedule1Part7) {
        super(schedule1Part7);
        calculationMethod = schedule1Part7.calculationMethod;
    }

    public DutyCalculationMethod getCalculationMethod() {
        return calculationMethod;
    }

    public void setCalculationMethod(DutyCalculationMethod calculationMethod) {
        this.calculationMethod = calculationMethod;
    }

    @Override
    public Schedule1Part7 clone() {
        Schedule1Part7 clone = new Schedule1Part7();
        clone.setCalculationMethod(calculationMethod);
        clone.setTariffHeading(getTariffHeading() != null ? getTariffHeading().clone() : null);
        clone.setValid(isValid());
        clone.setDutyRate(dutyRate != null ? dutyRate.clone() : null);
        return clone;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).append("calculationMethod", calculationMethod).toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Schedule1Part7)) {
            return false;
        }
        Schedule1Part7 other = (Schedule1Part7) obj;
        return new EqualsBuilder().appendSuper(super.equals(obj)).append(calculationMethod, other.calculationMethod).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().appendSuper(super.hashCode()).append(calculationMethod).toHashCode();
    }

    @Override
    public String getCostlineCode() {
        return CostLineNames.CUSTOMS_SUGAR_TAX;
    }

    @Override
    protected boolean getDoCheckProof() {
        return false;
    }

    @Override
    protected int getPart1MaxLength() {
        return PART1_MAX_LENGTH;
    }

    @Override
    protected boolean getDoCheckPercentage() {
        return false;
    }

    @Override
    protected boolean getDoCheckValue() {
        return true;
    }

    @Override
    public String getType() {
        return "S1P7";
    }
}