FKColumn.java

// license-header java merge-point
//
/**
 * @author Generated on 09/21/2012 13:39:17-0400 Do not modify by hand!
 *
 * TEMPLATE:     ValueObject.vsl in andromda-java-cartridge.
 * MODEL CLASS:  JDBCMetadataModel::org.andromda.jdbcmetadata::FKColumn
 * STEREOTYPE:   ValueObject
 */
package org.andromda.jdbcmetadata;

import java.io.Serializable;
import java.util.Arrays;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * TODO: Model Documentation for FKColumn
 */
public class FKColumn
    implements Serializable, Comparable<FKColumn>
{
    /** The serial version UID of this class. Needed for serialization. */
    private static final long serialVersionUID = 8849207302152866982L;

    // Class attributes
    /**
     * <p>The order of the column within the FK. Probably unnecessary because the Sequence column
     * values are an ordered List.</p>
     */
    protected int seqNum;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setSeqNum = false;

    // Class associationEnds
    /**
     * <p>The column in the FK on the table which refers to a PK column in another table.</p>
     */
    protected Column fkColumn;

    /**
     * <p>The FK object containing pkname, fkname etc.</p>
     */
    protected ForeignKey foreignKey;

    /**
     * <p>The column in the FK on another table which refers to a FK column in the referenced 
     * table.</p>
     */
    protected Column fkRefColumn;

    /** Default Constructor with no properties */
    public FKColumn()
    {
        // Documented empty block - avoid compiler warning - no super constructor
    }

    /**
     * Constructor with all properties
     * @param seqNumIn int
     * @param fkColumnIn Column
     * @param foreignKeyIn ForeignKey
     * @param fkRefColumnIn Column
     */
    public FKColumn(final int seqNumIn, final Column fkColumnIn, final ForeignKey foreignKeyIn, final Column fkRefColumnIn)
    {
        this.seqNum = seqNumIn;
        this.setSeqNum = true;
        this.fkColumn = fkColumnIn;
        this.foreignKey = foreignKeyIn;
        this.fkRefColumn = fkRefColumnIn;
    }

    /**
     * Copies constructor from other FKColumn
     *
     * @param otherBean Cannot be <code>null</code>
     * @throws NullPointerException if the argument is <code>null</code>
     */
    public FKColumn(final FKColumn otherBean)
    {
        this.seqNum = otherBean.getSeqNum();
        this.setSeqNum = true;
        this.fkColumn = otherBean.getFkColumn();
        this.foreignKey = otherBean.getForeignKey();
        this.fkRefColumn = otherBean.getFkRefColumn();
    }

    /**
     * Copies all properties from the argument value object into this value object.
     * @param otherBean Cannot be <code>null</code>
     */
    public void copy(final FKColumn otherBean)
    {
        if (null != otherBean)
        {
            this.setSeqNum(otherBean.getSeqNum());
            this.setSeqNum = true;
            this.setFkColumn(otherBean.getFkColumn());
            this.setForeignKey(otherBean.getForeignKey());
            this.setFkRefColumn(otherBean.getFkRefColumn());
        }
    }

    /**
     * <p>The order of the column within the FK. Probably unnecessary because the Sequence column
     * values are an ordered List.</p>
     * Get the seqNum Attribute
     * @return seqNum int
     */
    public int getSeqNum()
    {
        return this.seqNum;
    }

    /**
     * <p>The order of the column within the FK. Probably unnecessary because the Sequence column
     * values are an ordered List.</p>
     * @param value int
     */
    public void setSeqNum(final int value)
    {
        this.seqNum = value;
        this.setSeqNum = true;
    }

    /**
     * Return true if the primitive attribute seqNum is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetSeqNum()
    {
        return this.setSeqNum;
    }

    /**
     * <p>The column in the FK on the table which refers to a PK column in another table.</p>
     * Get the fkColumn Association
     * @return this.fkColumn Column
     */
    public Column getFkColumn()
    {
        return this.fkColumn;
    }

    /**
     * Sets the fkColumn
     * @param value Column
     */
    public void setFkColumn(Column value)
    {
        this.fkColumn = value;
    }

    /**
     * <p>The FK object containing pkname, fkname etc.</p>
     * Get the foreignKey Association
     * @return this.foreignKey ForeignKey
     */
    public ForeignKey getForeignKey()
    {
        return this.foreignKey;
    }

    /**
     * Sets the foreignKey
     * @param value ForeignKey
     */
    public void setForeignKey(ForeignKey value)
    {
        this.foreignKey = value;
    }

    /**
     * <p>The column in the FK on another table which refers to a FK column in the referenced 
     * table.</p>
     * Get the fkRefColumn Association
     * @return this.fkRefColumn Column
     */
    public Column getFkRefColumn()
    {
        return this.fkRefColumn;
    }

    /**
     * Sets the fkRefColumn
     * @param value Column
     */
    public void setFkRefColumn(Column value)
    {
        this.fkRefColumn = value;
    }

    /**
     * @param object to compare this object against
     * @return boolean if equal
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(final Object object)
    {
        if (object==null || object.getClass() != this.getClass())
        {
             return false;
        }
        // Check if the same object instance
        if (object==this)
        {
            return true;
        }
        FKColumn rhs = (FKColumn) object;
        return new EqualsBuilder()
            .append(this.getSeqNum(), rhs.getSeqNum())
            .append(this.getFkColumn(), rhs.getFkColumn())
            .append(this.getForeignKey(), rhs.getForeignKey())
            .append(this.getFkRefColumn(), rhs.getFkRefColumn())
            .isEquals();
    }

    /**
     * @param object to compare this object against
     * @return int if equal
     * @see Comparable#compareTo(Object)
     */
    public int compareTo(final FKColumn object)
    {
        if (object==null)
        {
            return -1;
        }
        // Check if the same object instance
        if (object==this)
        {
            return 0;
        }
        return new CompareToBuilder()
            .append(this.getSeqNum(), object.getSeqNum())
            .append(this.getFkColumn(), object.getFkColumn())
            .append(this.getForeignKey(), object.getForeignKey())
            .append(this.getFkRefColumn(), object.getFkRefColumn())
            .toComparison();
    }

    /**
     * @return int hashCode value
     * @see Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        return new HashCodeBuilder(1249046965, -82296885)
            .append(this.getSeqNum())
            .append(this.getFkColumn())
            .append(this.getForeignKey())
            .append(this.getFkRefColumn())
            .toHashCode();
    }

    /**
     * @return String representation of object
     * @see Object#toString()
     */
    @Override
    public String toString()
    {
        return new ToStringBuilder(this)
            .append("seqNum", this.getSeqNum())
            .append("fkColumn", this.getFkColumn())
            .append("foreignKey", this.getForeignKey())
            .append("fkRefColumn", this.getFkRefColumn())
            .toString();
    }

    /**
     * Compares the properties of this instance to the properties of the argument. This method will return
     * {@code false} as soon as it detects that the argument is {@code null} or not of the same type as
     * (or a sub-type of) this instance's type.
     *
     * <p/>For array, collection or map properties the comparison will be done one level deep, in other words:
     * the elements will be compared using the {@code equals()} operation.
     *
     * <p/>Note that two properties will be considered equal when both values are {@code null}.
     *
     * @param thatObject the object containing the properties to compare against this instance
     * @return this method will return {@code true} in case the argument has the same type as this class, or is a
     *      sub-type of this class and all properties as found on this class have equal values when queried on that
     *      argument instance; in all other cases this method will return {@code false}
     */
    public boolean equalProperties(final Object thatObject)
    {
        if (thatObject == null || !this.getClass().isAssignableFrom(thatObject.getClass()))
        {
            return false;
        }

        final FKColumn that = (FKColumn)thatObject;

        return
            equal(this.getSeqNum(), that.getSeqNum())
            && equal(this.getFkColumn(), that.getFkColumn())
            && equal(this.getForeignKey(), that.getForeignKey())
            && equal(this.getFkRefColumn(), that.getFkRefColumn())
        ;
    }

    /**
     * This is a convenient helper method which is able to detect whether or not two values are equal. Two values
     * are equal when they are both {@code null}, are arrays of the same length with equal elements or are
     * equal objects (this includes {@link java.util.Collection} and {@link java.util.Map} instances).
     *
     * <p/>Note that for array, collection or map instances the comparison runs one level deep.
     *
     * @param first the first object to compare, may be {@code null}
     * @param second the second object to compare, may be {@code null}
     * @return this method will return {@code true} in case both objects are equal as explained above;
     *      in all other cases this method will return {@code false}
     */
    protected static boolean equal(final Object first, final Object second)
    {
        final boolean equal;

        if (first == null)
        {
            equal = (second == null);
        }
        else if (first.getClass().isArray() && (second != null) && second.getClass().isArray())
        {
            equal = Arrays.equals((Object[])first, (Object[])second);
        }
        else // note that the following also covers java.util.Collection and java.util.Map
        {
            equal = first.equals(second);
        }

        return equal;
    }

    // FKColumn value-object java merge-point
}