Index.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::Index
* STEREOTYPE: ValueObject
*/
package org.andromda.jdbcmetadata;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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>All defined indexes for a table.</p>
*/
public class Index
implements Serializable, Comparable<Index>
{
/** The serial version UID of this class. Needed for serialization. */
private static final long serialVersionUID = -776626678036839209L;
// Class attributes
/**
* <p>The name of the index.</p>
*/
protected String name;
/**
* <p>Whether an index is unique.</p>
*/
protected boolean unique;
/**
* boolean setter for primitive attribute, so we can tell if it's initialized
*/
protected boolean setUnique = false;
// Class associationEnds
/**
* <p>The table on which this index exists.</p>
*/
protected Table table;
/**
* <p>The columns belonging to the index.</p>
*/
protected List<IndexColumn> columns;
/** Default Constructor with no properties */
public Index()
{
// Documented empty block - avoid compiler warning - no super constructor
}
/**
* Constructor with all properties
* @param nameIn String
* @param uniqueIn boolean
* @param tableIn Table
* @param columnsIn List<IndexColumn>
*/
public Index(final String nameIn, final boolean uniqueIn, final Table tableIn, final List<IndexColumn> columnsIn)
{
this.name = nameIn;
this.unique = uniqueIn;
this.setUnique = true;
this.table = tableIn;
this.columns = columnsIn;
}
/**
* Copies constructor from other Index
*
* @param otherBean Cannot be <code>null</code>
* @throws NullPointerException if the argument is <code>null</code>
*/
public Index(final Index otherBean)
{
this.name = otherBean.getName();
this.unique = otherBean.isUnique();
this.setUnique = true;
this.table = otherBean.getTable();
this.columns = otherBean.getColumns();
}
/**
* Copies all properties from the argument value object into this value object.
* @param otherBean Cannot be <code>null</code>
*/
public void copy(final Index otherBean)
{
if (null != otherBean)
{
this.setName(otherBean.getName());
this.setUnique(otherBean.isUnique());
this.setUnique = true;
this.setTable(otherBean.getTable());
this.setColumns(otherBean.getColumns());
}
}
/**
* <p>The name of the index.</p>
* Get the name Attribute
* @return name String
*/
public String getName()
{
return this.name;
}
/**
* <p>The name of the index.</p>
* @param value String
*/
public void setName(final String value)
{
this.name = value;
}
/**
* <p>Whether an index is unique.</p>
* Get the unique Attribute
* @return unique boolean
*/
public boolean isUnique()
{
return this.unique;
}
/**
* <p>Whether an index is unique.</p>
* Duplicates isBoolean method, for use as Jaxb2 compatible object
* Get the unique Attribute
* @return unique boolean
*/
@Deprecated
public boolean getUnique()
{
return this.unique;
}
/**
* <p>Whether an index is unique.</p>
* @param value boolean
*/
public void setUnique(final boolean value)
{
this.unique = value;
this.setUnique = true;
}
/**
* Return true if the primitive attribute unique is set, through the setter or constructor
* @return true if the attribute value has been set
*/
public boolean isSetUnique()
{
return this.setUnique;
}
/**
* <p>The table on which this index exists.</p>
* Get the table Association
* @return this.table Table
*/
public Table getTable()
{
return this.table;
}
/**
* Sets the table
* @param value Table
*/
public void setTable(Table value)
{
this.table = value;
}
/**
* <p>The columns belonging to the index.</p>
* Get the columns Association
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the object.
* @return this.columns List<IndexColumn>
*/
public List<IndexColumn> getColumns()
{
if (this.columns == null)
{
this.columns = new ArrayList<IndexColumn>();
}
return this.columns;
}
/**
* Sets the columns
* @param value List<IndexColumn>
*/
public void setColumns(List<IndexColumn> value)
{
this.columns = 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;
}
Index rhs = (Index) object;
return new EqualsBuilder()
.append(this.getName(), rhs.getName())
.append(this.isUnique(), rhs.isUnique())
.append(this.getTable(), rhs.getTable())
.append(this.getColumns(), rhs.getColumns())
.isEquals();
}
/**
* @param object to compare this object against
* @return int if equal
* @see Comparable#compareTo(Object)
*/
public int compareTo(final Index 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.isUnique(), object.isUnique())
.append(this.getTable(), object.getTable())
.append(this.getColumns(), object.getColumns())
.toComparison();
}
/**
* @return int hashCode value
* @see Object#hashCode()
*/
@Override
public int hashCode()
{
return new HashCodeBuilder(1249046965, -82296885)
.append(this.getName())
.append(this.isUnique())
.append(this.getTable())
//Commented out to avoid commons-lang-2.4 recursion StackOverflowError: https://issues.apache.org/jira/browse/LANG-456
//.append(this.getColumns())
.toHashCode();
}
/**
* @return String representation of object
* @see Object#toString()
*/
@Override
public String toString()
{
return new ToStringBuilder(this)
.append("name", this.getName())
.append("unique", this.isUnique())
.append("table", this.getTable())
.append("columns", this.getColumns())
.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 Index that = (Index)thatObject;
return
equal(this.getName(), that.getName())
&& equal(this.isUnique(), that.isUnique())
&& equal(this.getTable(), that.getTable())
&& equal(this.getColumns(), that.getColumns())
;
}
/**
* 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;
}
// Index value-object java merge-point
}