Skip to content

Commit f61b1df

Browse files
committed
♻ Refactorisation Professeur
1 parent 050fc08 commit f61b1df

File tree

4 files changed

+143
-31
lines changed

4 files changed

+143
-31
lines changed

src/main/java/fr/umontp/edt/Professeur.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package fr.umontp.edt;
22

3-
import java.text.Normalizer;
4-
import java.util.Locale;
5-
import java.util.regex.Pattern;
3+
import fr.umontp.edt.outils.OutilsProfesseur;
64

75
/**
86
* <b>Professeur est la classe représentant un professeur au sein de l'emploi du
@@ -19,6 +17,7 @@
1917
* </p>
2018
*
2119
* @see RepertoireProfesseur
20+
* @see OutilsProfesseur
2221
*
2322
* @author MathieuSoysal
2423
* @version 1.0.1
@@ -38,32 +37,7 @@ public class Professeur {
3837
String[] infosProf = nomPrenom.split(" ");
3938
nom = infosProf[0];
4039
prenom = infosProf[1];
41-
denomination = formater(nom, prenom);
42-
}
43-
44-
/**
45-
* @param nomPrenom
46-
*
47-
* @return la variable {@code nomPrenom} formaté.
48-
*
49-
* @see String#toUpperCase(Locale)
50-
* @see Professeur#supprimerAccent(String)
51-
*
52-
* @since 1.0.1
53-
*/
54-
static String formater(String nomPrenom) {
55-
nomPrenom = supprimerAccent(nomPrenom);
56-
return nomPrenom.toUpperCase(Locale.FRANCE).replaceAll("[^A-Z ]", " ");
57-
}
58-
59-
static String formater(String nom, String prenom) {
60-
return formater(nom + " " + prenom);
61-
}
62-
63-
private static String supprimerAccent(String str) {
64-
String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);
65-
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
66-
return pattern.matcher(nfdNormalizedString).replaceAll("");
40+
denomination = OutilsProfesseur.formater(nom, prenom);
6741
}
6842

6943
/**

src/main/java/fr/umontp/edt/RepertoireProfesseur.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.regex.Matcher;
77
import java.util.regex.Pattern;
88

9+
import fr.umontp.edt.outils.OutilsProfesseur;
10+
911
/**
1012
* <b>RepertoireProfesseur est la classe qui repertorie tous les professeurs de
1113
* l'emploi du temps.</b>
@@ -43,7 +45,7 @@ static Professeur[] getProfesseurDepuisDescriptionEtAjouterSiNonPresent(String d
4345
Matcher m = Pattern.compile(regex).matcher(description);
4446
final List<Professeur> matches = new ArrayList<>();
4547
while (m.find()) {
46-
String nomPrenomProf = Professeur.formater(m.group(0));
48+
String nomPrenomProf = OutilsProfesseur.formater(m.group(0));
4749
matches.add(repertoire.computeIfAbsent(nomPrenomProf, k -> new Professeur(nomPrenomProf)));
4850
}
4951
return matches.toArray(new Professeur[matches.size()]);
@@ -61,7 +63,7 @@ static Professeur[] getProfesseurDepuisDescriptionEtAjouterSiNonPresent(String d
6163
* @see java.util.HashMap#get(java.lang.Object)
6264
*/
6365
public static Professeur get(String nom, String prenom) {
64-
return repertoire.get(Professeur.formater(nom, prenom));
66+
return repertoire.get(OutilsProfesseur.formater(nom, prenom));
6567
}
6668

6769
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package fr.umontp.edt.outils;
2+
3+
import java.text.Normalizer;
4+
import java.util.Locale;
5+
import java.util.regex.Pattern;
6+
7+
import fr.umontp.edt.Professeur;
8+
9+
/**
10+
* <b>ProfesseurOutils est la classe utilitaire pour le fonctionnement interne
11+
* de la class {@link Professeur}.</b>
12+
*
13+
* @see Professeur
14+
*
15+
* @author MathieuSoysal
16+
* @version 1.0.0
17+
*/
18+
public class OutilsProfesseur {
19+
private OutilsProfesseur() {
20+
throw new IllegalStateException("Class utilitaire");
21+
}
22+
23+
/**
24+
* @param str {@code String} auquel l'on doit enlever l'accentuation
25+
*
26+
* @return {@code String} sans accentuation.
27+
*
28+
* @see Normalizer
29+
*
30+
* @since 1.0.0
31+
*/
32+
public static String supprimerAccentuation(String str) {
33+
String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);
34+
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
35+
return pattern.matcher(nfdNormalizedString).replaceAll("");
36+
}
37+
38+
/**
39+
* Concatène les deux variables {@code nom} et {@code prenom}, et renvoie une
40+
* variable formaté pour la class {@link Professeur}.
41+
*
42+
* @param nom
43+
* @param prenom
44+
*
45+
* @return {@code String} formaté pour la class {@link Professeur}.
46+
*
47+
* @see String#toUpperCase(Locale)
48+
* @see supprimerAccent
49+
*
50+
* @since 1.0.0
51+
*/
52+
public static String formater(String nom, String prenom) {
53+
return OutilsProfesseur.formater(nom + " " + prenom);
54+
}
55+
56+
/**
57+
* @param nomPrenom
58+
*
59+
* @return la variable {@code nomPrenom} formaté pour la class
60+
* {@link Professeur}.
61+
*
62+
* @see String#toUpperCase(Locale)
63+
* @see supprimerAccent
64+
*
65+
* @since 1.0.0
66+
*/
67+
public static String formater(String nomPrenom) {
68+
nomPrenom = supprimerAccentuation(nomPrenom);
69+
return nomPrenom.toUpperCase(Locale.FRANCE).replaceAll("[^A-Z ]", " ");
70+
}
71+
72+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package fr.umontp.edt.outils;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.stream.Stream;
6+
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
11+
class OutilsProfesseurTest {
12+
13+
@ParameterizedTest(name = "la chaine de caractères {0} une fois son accentuation supprimé doit être égale à {1}")
14+
@MethodSource("genererArgumentsPourtest_supprimerAccentuation")
15+
void test_supprimerAccentuation(String input, String excepted) {
16+
assertEquals(excepted, OutilsProfesseur.supprimerAccentuation(input));
17+
}
18+
19+
private static Stream<Arguments> genererArgumentsPourtest_supprimerAccentuation() {
20+
return Stream.of(//
21+
Arguments.of("É", "E"), //
22+
Arguments.of("1234567890", "1234567890"), //
23+
Arguments.of("ô", "o"), //
24+
Arguments.of("à", "a"), //
25+
Arguments.of("è", "e"), //
26+
Arguments.of("ç", "c"), //
27+
Arguments.of("'", "'"), //
28+
Arguments.of("-", "-"), //
29+
Arguments.of(" ", " "), //
30+
Arguments.of("é", "e"));
31+
}
32+
33+
@ParameterizedTest(name = "la chaine de caractères {0} une fois formaté doit être égale à {1}")
34+
@MethodSource("genererArgumentsPourtest_formater_1parametre")
35+
void test_formater_1parametre(String input, String excepted) {
36+
assertEquals(excepted, OutilsProfesseur.formater(input));
37+
}
38+
39+
private static Stream<Arguments> genererArgumentsPourtest_formater_1parametre() {
40+
return Stream.of(//
41+
Arguments.of("", ""), //
42+
Arguments.of("test", "TEST"), //
43+
Arguments.of("TeEsT", "TEEST"), //
44+
Arguments.of("Téèçà", "TEECA"), //
45+
Arguments.of("ÉÈÇÀ", "EECA"), //
46+
Arguments.of("test t@°0245est", "TEST T EST"));
47+
}
48+
49+
@ParameterizedTest(name = "la chiane de caractères {0} une fois formaté doit être égale à {1}")
50+
@MethodSource("genererArgumentsPourtest_formater_2parametres")
51+
void test_formater_2parametres(String input1, String input2, String excepted) {
52+
assertEquals(excepted, OutilsProfesseur.formater(input1, input2));
53+
}
54+
55+
private static Stream<Arguments> genererArgumentsPourtest_formater_2parametres() {
56+
return Stream.of(//
57+
Arguments.of("", "", " "), //
58+
Arguments.of("test", "TEST", "TEST TEST"), //
59+
Arguments.of("TeEsT", "TeEsT", "TEEST TEEST"), //
60+
Arguments.of("Téèçà", "Téèçà", "TEECA TEECA"), //
61+
Arguments.of("ÉÈÇÀ", "ÉÈÇÀ", "EECA EECA"), //
62+
Arguments.of("te93~('st", "t@°0245est", "TE ST T EST"));
63+
}
64+
}

0 commit comments

Comments
 (0)