Schedule2Part2.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 javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

/**
 * Entity representing Schedule 2 Part 2 - Countervailing Duty.
 */
@Entity
@Table(name = "schedule2part2")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Schedule2Part2")
public class Schedule2Part2 extends TypedPlaceDutySchedule implements Serializable {

    private static final long serialVersionUID = 1L;

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

    public Schedule2Part2(TypedPlaceDutySchedule typedPlaceDutySchedule) {
        super(typedPlaceDutySchedule);
    }

    @Override
    public Schedule2Part2 clone() {
        Schedule2Part2 clone = new Schedule2Part2();
        clone.setOriginatingPlace(getOriginatingPlace());
        clone.setTariffHeading(getTariffHeading() != null ? getTariffHeading().clone() : null);
        clone.setValid(isValid());
        clone.setDutyRate(dutyRate != null ? dutyRate.clone() : null);
        return clone;
    }

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

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

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

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