Java Q&A
by Mark Seaman

Listing One
// Copyright (c) 2000, Mark J. Seaman
/** Maintains information about a column of a database table. It is designed  
*  to be stored in a hashtable and passed to the DBUtils class methods
*  @author  Mark Seaman ($Author: mark $)
*  @version $Revision: 1.3 $
*/

public final class ColumnInfo {
  /** the column name */
  private String name;

  /** the datatype of the column from the sql.Types package */
  private int datatype;

  /** the maximum length of this column, currently not used */
  private int length;

  /** uses the column name to provide a hash value for this
  * column.  This allows the column info to be retrieved
  * from a Hastable using either the name or the columnInfo object.  
  */
  public int hashCode() { return name.hashCode();}

  /** equals method required for this object to be retreived from a 
  * <code>java.util.Hashtable</code>. It makes a <code>ColumnInfo</code> 
  * object equal to a <code>String</code> containing the name of the column. 
  * This assumes no DBMS implementation allows two columns of the same name 
  * in the same table. This class is declared <code>final</code> because 
  * this method will not work on decendants of this class 
  */
  public boolean equals (Object o) {

    if (o == null) {
      return false;
    } else if (o instanceof ColumnInfo) {
      //are the names the same?
      return this.name.equals(((ColumnInfo)o).getName());
    }
    else if (o instanceof String) {
      //is this name the same as the String value
      return this.name.equals((String)o);
    } else {
      //all others defer to Object equals
    return super.equals(o);
    }
  } //equals()

  /** sets the column name */
  public void setName (String name) { this.name = name; }
  /** sets the datatype */
  public void setDataType (int datatype) {this.datatype = datatype; }
  /** sets the length of the column */  
  public void setLength ( int length ) { this.length = length; }

  /** returns the column name */
  public String getName () { return name; }
  /** returns the column type */
  public int getDataType () { return datatype; }
  /** returns the column length */
  public int getLength() { return length; }

} //ColumnInfo





1


