Skip to content

Commit 9bd90fc

Browse files
committed
🔨 Validation des tests
1 parent 9d89b10 commit 9bd90fc

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

caumunes.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9408,7 +9408,6 @@
94089408
11358,ST MARTIN LYS,11500
94099409
30322,SOUDORGUES,30460
94109410
54013,AMENONCOURT,54450
9411-
Code_commune_INSEE;Nom_commune;Code_postal;Ligne_5;Libellé_d_acheminement;coordonnees_gps,,0
94129411
11306,QUIRBAJOU,11500
94139412
14753,VILLERS CANIVET,14420
94149413
68139,HIRTZBACH,68118

src/main/java/fr/france/Caumune.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ public int getCodePostal() {
6060
* @see Departement
6161
*/
6262
public Departement getDepartement() {
63-
int code = codePostal / 1000;
64-
if (code != 20)
65-
return Departement.rechercherParCode(code);
63+
if (codePostal / 1000 != 20)
64+
return Departement.rechercherParCode(codePostal);
6665
else
6766
return Departement.rechercherParCode(codeINSEE.substring(0, 2));
6867
}

src/main/java/fr/france/Departement.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ public enum Departement {
447447
* Département de Saint-Martin
448448
*/
449449
SAINT_MARTIN(978, StatutDepartement.COM, "Saint-Martin", "Marigot", Region.DEPARTEMENT_NON_RATTACHE_A_UNE_REGION), //
450+
/**
451+
* Département de Monaco
452+
*/
453+
MONACO(98, StatutDepartement.MONACO, "Monaco", "Monaco", Region.DEPARTEMENT_NON_RATTACHE_A_UNE_REGION), //
450454
/**
451455
* Département de Terres australes et antarctiques françaises
452456
*/
@@ -520,7 +524,9 @@ public static Departement rechercherParNom(String nom) {
520524
* @see Departement
521525
*/
522526
public static Departement rechercherParCode(int code) {
523-
if (code >= 1000)
527+
if (code >= 97000 && code != 98000)
528+
code /= 100;
529+
else if (code >= 1000)
524530
code /= 1000;
525531
return OutilsDepartement.rechercherParCode(code);
526532
}

src/main/java/fr/france/StatutDepartement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ public enum StatutDepartement {
2929
/**
3030
* Territoires d'outre-mer
3131
*/
32-
TOM
32+
TOM, MONACO
3333
}

src/main/java/fr/france/outils/OutilsDepartement.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import java.util.ArrayList;
44
import java.util.Arrays;
55
import java.util.Collection;
6+
import java.util.EnumMap;
7+
import java.util.List;
68
import java.util.Map;
79
import java.util.stream.Collectors;
810
import java.util.stream.Stream;
911

12+
import fr.france.Caumune;
1013
import fr.france.Departement;
1114
import fr.france.Region;
15+
import fr.france.RepertoireCaumune;
1216
import fr.france.StatutDepartement;
1317

1418
/**
@@ -28,11 +32,9 @@ private OutilsDepartement() {
2832
throw new IllegalStateException("Class utilitaire");
2933
}
3034

31-
private static final Stream<Departement> STREAM = Arrays.asList(Departement.values()).stream();
32-
private static final Map<Integer, Departement> REPERTOIRE_CODE = OutilsRepertoireGenerique
33-
.genererMap(STREAM.map(Departement::getCode).collect(Collectors.toList()), Departement.class);
34-
private static final RepertoireGenerique<Departement> REPERTOIRE_DEPARTEMENT = new RepertoireGenerique<>(
35-
Departement.class);
35+
private static final Map<Integer, Departement> REPERTOIRE_CODE = initialiserRepertoireCode();
36+
private static final RepertoireGenerique<Departement> REPERTOIRE_NOM = new RepertoireGenerique<>(Departement.class);
37+
private static final Map<Departement, List<Caumune>> REPERTOIRE_CAUMUNE = initialiserRepertoireCaumune();
3638

3739
public static Departement[] filtrerDepartementsParRegion(Region region) {
3840
Collection<Departement> result = new ArrayList<>();
@@ -51,10 +53,30 @@ public static Departement[] filtrerDepartementsParStatut(StatutDepartement statu
5153
}
5254

5355
public static Departement rechercherParNom(String nom) {
54-
return REPERTOIRE_DEPARTEMENT.rechercherParNom(nom);
56+
return REPERTOIRE_NOM.rechercherParNom(nom);
5557
}
5658

5759
public static Departement rechercherParCode(int code) {
5860
return REPERTOIRE_CODE.get(code);
5961
}
62+
63+
public static List<Caumune> getCaumunes(Departement departement){
64+
return REPERTOIRE_CAUMUNE.get(departement);
65+
}
66+
67+
private static EnumMap<Departement, List<Caumune>> initialiserRepertoireCaumune() {
68+
EnumMap<Departement, List<Caumune>> result = new EnumMap<>(Departement.class);
69+
for (Caumune caumune : RepertoireCaumune.getCaumunes()) {
70+
Departement departement = caumune.getDepartement();
71+
List<Caumune> caumunes = result.computeIfAbsent(departement, k -> new ArrayList<>());
72+
caumunes.add(caumune);
73+
}
74+
return result;
75+
}
76+
77+
private static Map<Integer, Departement> initialiserRepertoireCode() {
78+
return OutilsRepertoireGenerique.genererMap(
79+
Arrays.asList(Departement.values()).stream().map(Departement::getCode).collect(Collectors.toList()),
80+
Departement.class);
81+
}
6082
}

0 commit comments

Comments
 (0)