DriverData.java

// license-header java merge-point
//
/**
 * @author Generated by ValueObject.vsl in andromda-java-cartridge on 08/18/2014 15:29:46-0400 Do not modify by hand!
 *
 * TEMPLATE:     ValueObject.vsl in andromda-java-cartridge.
 * MODEL CLASS:  org::andromda::samples::carrental::customers::DriverData
 * STEREOTYPE:   ValueObject
 */
package org.andromda.samples.carrental.customers;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
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;

/**
 * <p>
 * Value object for a Driver.
 * </p>
 */
public class DriverData
    implements Serializable, Comparable<DriverData>
{
    /** The serial version UID of this class. Needed for serialization. */
    private static final long serialVersionUID = 8057693344490547918L;

    // Class attributes
    /**
     * <p>
     * TODO: Model Documentation for name
     * </p>
     */
    protected String name;
    /**
     * <p>
     * TODO: Model Documentation for surname
     * </p>
     */
    protected String surname;
    /**
     * <p>
     * TODO: Model Documentation for birthDate
     * </p>
     */
    protected Date birthDate;
    /**
     * <p>
     * TODO: Model Documentation for licenseNo
     * </p>
     */
    protected String licenseNo;
    /**
     * <p>
     * TODO: Model Documentation for licenseIssuedBy
     * </p>
     */
    protected String licenseIssuedBy;

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

    /**
     * Constructor with all properties
     * @param nameIn String
     * @param surnameIn String
     * @param birthDateIn Date
     * @param licenseNoIn String
     * @param licenseIssuedByIn String
     */
    public DriverData(final String nameIn, final String surnameIn, final Date birthDateIn, final String licenseNoIn, final String licenseIssuedByIn)
    {
        this.name = nameIn;
        this.surname = surnameIn;
        this.birthDate = birthDateIn;
        this.licenseNo = licenseNoIn;
        this.licenseIssuedBy = licenseIssuedByIn;
    }

    /**
     * Copies constructor from other DriverData
     *
     * @param otherBean Cannot be <code>null</code>
     * @throws NullPointerException if the argument is <code>null</code>
     */
    public DriverData(final DriverData otherBean)
    {
        this.name = otherBean.getName();
        this.surname = otherBean.getSurname();
        this.birthDate = otherBean.getBirthDate();
        this.licenseNo = otherBean.getLicenseNo();
        this.licenseIssuedBy = otherBean.getLicenseIssuedBy();
    }

    /**
     * Copies all properties from the argument value object into this value object.
     * @param otherBean Cannot be <code>null</code>
     */
    public void copy(final DriverData otherBean)
    {
        if (null != otherBean)
        {
            this.setName(otherBean.getName());
            this.setSurname(otherBean.getSurname());
            this.setBirthDate(otherBean.getBirthDate());
            this.setLicenseNo(otherBean.getLicenseNo());
            this.setLicenseIssuedBy(otherBean.getLicenseIssuedBy());
        }
    }

    /**
     * <p>
     * TODO: Model Documentation for name
     * </p>
     * Get the name Attribute
     * @return name String
     */
    public String getName()
    {
        return this.name;
    }

    /**
     * <p>
     * TODO: Model Documentation for name
     * </p>
     * @param value String
     */
    public void setName(final String value)
    {
        this.name = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for surname
     * </p>
     * Get the surname Attribute
     * @return surname String
     */
    public String getSurname()
    {
        return this.surname;
    }

    /**
     * <p>
     * TODO: Model Documentation for surname
     * </p>
     * @param value String
     */
    public void setSurname(final String value)
    {
        this.surname = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for birthDate
     * </p>
     * Get the birthDate Attribute
     * @return birthDate Date
     */
    public Date getBirthDate()
    {
        return this.birthDate;
    }

    /**
     * <p>
     * TODO: Model Documentation for birthDate
     * </p>
     * @param value Date
     */
    public void setBirthDate(final Date value)
    {
        this.birthDate = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for licenseNo
     * </p>
     * Get the licenseNo Attribute
     * @return licenseNo String
     */
    public String getLicenseNo()
    {
        return this.licenseNo;
    }

    /**
     * <p>
     * TODO: Model Documentation for licenseNo
     * </p>
     * @param value String
     */
    public void setLicenseNo(final String value)
    {
        this.licenseNo = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for licenseIssuedBy
     * </p>
     * Get the licenseIssuedBy Attribute
     * @return licenseIssuedBy String
     */
    public String getLicenseIssuedBy()
    {
        return this.licenseIssuedBy;
    }

    /**
     * <p>
     * TODO: Model Documentation for licenseIssuedBy
     * </p>
     * @param value String
     */
    public void setLicenseIssuedBy(final String value)
    {
        this.licenseIssuedBy = 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;
        }
        DriverData rhs = (DriverData) object;
        return new EqualsBuilder()
            .append(this.getName(), rhs.getName())
            .append(this.getSurname(), rhs.getSurname())
            .append(this.getBirthDate(), rhs.getBirthDate())
            .append(this.getLicenseNo(), rhs.getLicenseNo())
            .append(this.getLicenseIssuedBy(), rhs.getLicenseIssuedBy())
            .isEquals();
    }

    /**
     * @param object to compare this object against
     * @return int if equal
     * @see Comparable#compareTo(Object)
     */
    public int compareTo(final DriverData object)
    {
        if (object==null)
        {
            return -1;
        }
        // Check if the same object instance
        if (object==this)
        {
            return 0;
        }
        return new CompareToBuilder()
            .append(this.getName(), object.getName())
            .append(this.getSurname(), object.getSurname())
            .append(this.getBirthDate(), object.getBirthDate())
            .append(this.getLicenseNo(), object.getLicenseNo())
            .append(this.getLicenseIssuedBy(), object.getLicenseIssuedBy())
            .toComparison();
    }

    /**
     * @return int hashCode value
     * @see Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        return new HashCodeBuilder(1249046965, -82296885)
            .append(this.getName())
            .append(this.getSurname())
            .append(this.getBirthDate())
            .append(this.getLicenseNo())
            .append(this.getLicenseIssuedBy())
            .toHashCode();
    }

    /**
     * @return String representation of object
     * @see Object#toString()
     */
    @Override
    public String toString()
    {
        return new ToStringBuilder(this)
            .append("name", this.getName())
            .append("surname", this.getSurname())
            .append("birthDate", this.getBirthDate())
            .append("licenseNo", this.getLicenseNo())
            .append("licenseIssuedBy", this.getLicenseIssuedBy())
            .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 DriverData that = (DriverData)thatObject;
        return
            equal(this.getName(), that.getName())
            && equal(this.getSurname(), that.getSurname())
            && equal(this.getBirthDate(), that.getBirthDate())
            && equal(this.getLicenseNo(), that.getLicenseNo())
            && equal(this.getLicenseIssuedBy(), that.getLicenseIssuedBy())
        ;
    }

    /**
     * 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;
    }

    // DriverData value-object java merge-point
}