Schedule1Part2B.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.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * Entity representing Schedule 1 Part 2B - Ad Valorem Duties.
 */
@Entity
@Table(name = "schedule1part2b")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Schedule1Part2B")
public class Schedule1Part2B extends TypedDutySchedule implements Serializable {

    private static final long serialVersionUID = 1L;

    @Transient
    private final int PART1_MAX_LENGTH = 3;

    public Schedule1Part2B() {
        super();
        if (getDutyRate() == null) {
            dutyRate = new TypedDutyRate();
        }
        dutyRate.setType(DutyType.AD_VALOREM);
        dutyRate.setPercentage(BigDecimal.ZERO);
    }

    public Schedule1Part2B(TypedDutySchedule typedDutySchedule) {
        super(typedDutySchedule);
    }

    @Override
    public Schedule1Part2B clone() {
        Schedule1Part2B clone = new Schedule1Part2B();
        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 Schedule1Part2B)) {
            return false;
        }
        Schedule1Part2B other = (Schedule1Part2B) 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_ADVALOREM_DUTY;
    }

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

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

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

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

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