Schedule2Part1.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 = "schedule2part1")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Schedule2Part1")
public class Schedule2Part1 extends TypedPlaceDutySchedule implements Serializable {

    private static final long serialVersionUID = 1L;

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

    public Schedule2Part1() {
        super();
        if (getDutyRate() == null) {
            dutyRate = new TypedDutyRate();
        }
        dutyRate.setType(DutyType.ANTI_DUMPING);
    }

    public Schedule2Part1(Schedule2Part1 schedule2Part1) {
        super(schedule2Part1);
        calculationMethod = schedule2Part1.calculationMethod;
    }

    public DutyCalculationMethod getCalculationMethod() {
        return calculationMethod;
    }

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

    @Override
    public Schedule2Part1 clone() {
        Schedule2Part1 clone = new Schedule2Part1();
        clone.setCalculationMethod(calculationMethod);
        clone.setOriginatingPlace(getOriginatingPlace());
        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 Schedule2Part1)) {
            return false;
        }
        Schedule2Part1 other = (Schedule2Part1) 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_ANTI_DUMPING_DUTY;
    }

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