1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/*
* Créé le 27 oct. 2008
*
* TODO Pour changer le modèle de ce fichier généré, allez à :
* Fenêtre - Préférences - Java - Style de code - Modèles de code
*/
package exemple2;
/**
* @author 493898
*
* TODO Pour changer le modèle de ce commentaire de type généré, allez à :
* Fenêtre - Préférences - Java - Style de code - Modèles de code
*/
public class Personne {
private int id_Per;
private String nom;
private String prenom;
private String dateNaissance;
private int attribut1;
private String attribut2;
private boolean visible; // Attribut non-représentatif et donc ignoré
/**
* @return Renvoie personne.
*/
public Personne() {
}
/**
* @return Renvoie dateNaissance.
*/
public String getDateNaissance() {
return dateNaissance;
}
/**
* @param dateNaissance
* dateNaissance à définir.
*/
public void setDateNaissance(String dateNaissance) {
this.dateNaissance = dateNaissance;
}
/**
* @return Renvoie id_Per.
*/
public int getId_Per() {
return id_Per;
}
/**
* @param id_Per
* id_Per à définir.
*/
public void setId_Per(int id_Per) {
this.id_Per = id_Per;
}
/**
* @return Renvoie nom.
*/
public String getNom() {
return nom;
}
/**
* @param nom
* nom à définir.
*/
public void setNom(String nom) {
this.nom = nom;
}
/**
* @return Renvoie prenom.
*/
public String getPrenom() {
return prenom;
}
/**
* @param prenom
* prenom à définir.
*/
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public boolean equals(Object obj) {
// Vérification de l'égalité des références
if (obj == this) {
return true;
}
// Vérification du type du paramètre
if (obj instanceof Personne) {
// Vérification des valeurs des attributs
Personne other = (Personne) obj;
// Pour les attributs de type primitif
// on compare directement les valeurs :
if (this.attribut1 != other.attribut1) {
return false; // les attributs sont différents
}
// Pour les attributs de type objets
// on compare dans un premier temps les références
if (this.attribut2 != other.attribut2) {
// Si les références ne sont pas identiques
// on doit en plus utiliser equals()
if (this.attribut2 == null
|| !this.attribut2.equals(other.attribut2)) {
return false; // les attributs sont différents
}
}
// Si on arrive ici c'est que tous les attributs sont égaux :
return true;
}
return false;
}
} |
Partager