package normeDeCodage.modele.objet;

public class ObjectInutile {
	/*
	 * les propri�t�s sont toujours private
	 */
	private String unMot;
	private int unChiffre;
	
	/**
	 * le constructeur initialise toujours TOUTES les propri�t�
	 * @param unMot
	 * @param unChiffre
	 */
	public ObjectInutile(String unMot, int unChiffre) {
		this.unMot = unMot;
		this.unChiffre = unChiffre;
	}
	
	/*
	 * pour rem�dier au constructeur multiple,
	 * utilis� les static factory
	 * ils on l'avantage d'�tre nomm� de fa�on significative en rapport
	 * avec la fa�on dont l'objet sera initialis�
	 * ils peuvent �galement d�clencher des exeptions au besoin
	 * ils renforcent l'usage des interfaces (dans ce cas mettre le constructeur statique au besoin)
	 * ils sont parfait pour les singletons
	 */
	
	/*
	 * static factory
	 */
	
	/**
	 * static factory
	 * version sans chiffre
	 * @param unMot as String
	 * @return ObjectInutile
	 */
	public static ObjectInutile sansChiffre(String unMot){
		return new ObjectInutile(unMot, 0);
	}
	
	/**
	 * static factory
	 * version sans mots
	 * @param unChiffre as int
	 * @return ObjectInutile
	 */
	public static ObjectInutile sansMots(int unChiffre){
		return new ObjectInutile("", unChiffre);
	}
	
	/**
	 * static factory
	 * version avec George et le chiffre 14
	 * @return ObjectInutile
	 */
	public static ObjectInutile George14(){
		return new ObjectInutile("George",14);
	}
	
	/**
	 * les singletons seront "early initialised"
	 * � d�finir comme suit
	 */
	private static ObjectInutile singleton = new ObjectInutile("singleton", 1);
	public static ObjectInutile instance(){
		return singleton;
	}

	/*
	 * les getters sont obligatoire pour chaque propri�t�
	 * */
	/**
	 * getter
	 * @return un mot as String
	 */
	public String getUnMot() {
		return unMot;
	}

	/**
	 * getter
	 * @return un chiffre as int
	 */
	public int getUnChiffre() {
		return unChiffre;
	}
	
	/*
	 * les setters sont optionnels
	 * toujours s�par� des getter
	 * a mettre au besoin
	 */
	/**
	 * setter
	 * @param unMot as string
	 */
	public void setUnMot(String unMot) {
		this.unMot = unMot;
	}
	
	/**
	 * setter
	 * @param unChiffre as int
	 */
	public void setUnChiffre(int unChiffre) {
		this.unChiffre = unChiffre;
	}
	
	/*
	 * methode object
	 * important , m�thode objet par d�fault
	 * � faire TOUT LE TEMPS
	 */
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 * si pas r�crite, elle retournera le nom de la classe + '@' + hashcode()
	 */
	public String toString(){
		return "un objet inutile avec un mot ( " + unMot +    //tenter de ne pas d�passer 
				" ) et un chiffre ( " + unChiffre + " )";	  //80 colonnes pour le code
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object o){
		if (o instanceof ObjectInutile)
			return this.unChiffre == ((ObjectInutile)o).unChiffre &&
			       this.unMot == ((ObjectInutile)o).unMot;
		return false;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 * si on ne le code pas,
	 * stocker cet objet dans une hashmap
	 * transformera l'arbre binaire en linked list
	 */
	public int hashCode(){
		int hash = 7;
		hash = hash * 13 + unMot.hashCode();
		hash = hash * 13 + unChiffre;
		return hash;
	}
}
