96 lines
2.1 KiB
Java
96 lines
2.1 KiB
Java
package sudoku;
|
|
|
|
public class Symbole {
|
|
private final String valeur;
|
|
|
|
/**
|
|
* Constructeur permettant de créer un symbole
|
|
* @param symbole
|
|
*/
|
|
public Symbole(String symbole) {
|
|
this.valeur = symbole;
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de créer un symbole de type String
|
|
* @param s
|
|
* @return
|
|
*/
|
|
// Factory methods pour différents types
|
|
public static Symbole of(String s) {
|
|
return new Symbole(s);
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de créer un symbole de type int
|
|
* @param n
|
|
* @return
|
|
*/
|
|
public static Symbole of(int n) {
|
|
return new Symbole(String.valueOf(n));
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de créer un symbole de type char
|
|
* @param c
|
|
* @return
|
|
*/
|
|
public static Symbole of(char c) {
|
|
return new Symbole(String.valueOf(c));
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de vérifier si un symbole est de type int
|
|
* @return
|
|
*/
|
|
public boolean isInt() {
|
|
try {
|
|
Integer.parseInt(valeur);
|
|
return true;
|
|
} catch (NumberFormatException e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de vérifier si un symbole est de type letter (char)
|
|
* @return
|
|
*/
|
|
public boolean isLetter() {
|
|
return valeur.length() == 1 && Character.isLetter(valeur.charAt(0));
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de vérifier si un symbole est de type string
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String toString() {
|
|
return valeur;
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de retourner un booléen si 2 objets sont identiques
|
|
* @param obj
|
|
* @return
|
|
*/
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj)
|
|
return true;
|
|
|
|
if (obj == null || getClass() != obj.getClass())
|
|
return false;
|
|
Symbole symbole = (Symbole) obj;
|
|
return valeur.equals(symbole.valeur);
|
|
}
|
|
|
|
/**
|
|
* Méthode permettant de retourner le hash code
|
|
* @return
|
|
*/
|
|
public int getHashCode() {
|
|
return valeur.hashCode();
|
|
}
|
|
}
|