package com.alexrnl.commons.database.structure;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.alexrnl.commons.utils.object.AutoCompare;
import com.alexrnl.commons.utils.object.AutoHashCode;
import com.alexrnl.commons.utils.object.Field;

/**
 * Class representing a column in a entity.<br />
 * It is defined by a name and a type. The columns should be load once and for all to avoid
 * unnecessary duplicates.<br />
 * Instances of this class are immutable.
 * @author Alex
 */
public class Column implements Serializable {
	/** Logger */
	private static Logger		lg					= Logger.getLogger(Column.class.getName());
	
	/** Serial Version UID */
	private static final long	serialVersionUID	= 7764202331118428284L;
	
	/** The Java type associated to the column */
	private final Class<?>		type;
	/** The name (identifier) of the column in the data base */
	private final String		name;
	/** <code>true</code> if the column is an index of the table */
	private final boolean		isID;
	
	/**
	 * Constructor #1.<br />
	 * @param type
	 *            the type of the column.
	 * @param name
	 *            the name of the column.
	 * @param isID
	 *            <code>true</code> if the column is an index.
	 */
	public Column (final Class<?> type, final String name, final boolean isID) {
		this.type = type;
		this.name = name;
		this.isID = isID;
		if (lg.isLoggable(Level.FINE)) {
			lg.fine("New " + this.getClass().getCanonicalName() + ": " + this.name + ", type: "
					+ this.type.getName() + (this.isID ? " index" : ""));
		}
	}
	
	/**
	 * Constructor #2.<br />
	 * Build a column which is not an index of the table.
	 * @param type
	 *            the type of the column.
	 * @param name
	 *            the name of the column.
	 */
	public Column (final Class<?> type, final String name) {
		this(type, name, false);
	}
	
	/**
	 * Return the type.
	 * @return the type
	 */
	@Field
	public Class<?> getType () {
		return type;
	}
	
	/**
	 * Return the name.
	 * @return the name.
	 */
	@Field
	public String getName () {
		return name;
	}
	
	/**
	 * Return the isID.
	 * @return <code>true</code> if the column is an index of the table.
	 */
	@Field
	public boolean isID () {
		return isID;
	}
	
	@Override
	public String toString () {
		return "name: " + name + ", type: " + type.getSimpleName() + ", is id: " + isID;
	}
	
	@Override
	public int hashCode () {
		return AutoHashCode.getInstance().hashCode(this);
	}
	
	@Override
	public boolean equals (final Object obj) {
		if (!(obj instanceof Column)) {
			return false;
		}
		return AutoCompare.getInstance().compare(this, (Column) obj);
	}
	
}

@@ -74,73 +74,8 @@
 ble;
-%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;
 %0A%0Aim
@@ -518,100 +518,8 @@
 e %7B%0A
-%09/** Logger */%0A%09private static Logger%09%09lg%09%09%09%09%09= Logger.getLogger(Column.class.getName());%0A%09%0A
 %09/**
@@ -1216,16 +1216,16 @@
 = name;%0A
+
 %09%09this.i
@@ -1240,193 +1240,8 @@
 ID;%0A
-%09%09if (lg.isLoggable(Level.FINE)) %7B%0A%09%09%09lg.fine(%22New %22 + this.getClass().getCanonicalName() + %22: %22 + this.name + %22, type: %22%0A%09%09%09%09%09+ this.type.getName() + (this.isID ? %22 index%22 : %22%22));%0A%09%09%7D%0A
 %09%7D%0A%09

Remove logger from Column class