11package fr .france ;
22
33import java .io .FileNotFoundException ;
4- import java .io .InputStream ;
5- import java .io .InputStreamReader ;
64import java .io .Reader ;
75import java .util .ArrayList ;
86import java .util .Collections ;
97import java .util .HashMap ;
108import java .util .List ;
119import java .util .Map ;
1210
13- import com .opencsv .bean .CsvToBeanBuilder ;
14-
1511import org .apache .commons .logging .Log ;
1612import org .apache .commons .logging .LogFactory ;
1713
14+ import fr .france .outils .OutilsRepertoireCommune ;
1815import fr .france .outils .OutilsString ;
1916
2017/**
@@ -47,13 +44,10 @@ private RepertoireCommune() {
4744 private static List <Commune > initCommunes () {
4845 List <Commune > result = null ;
4946 try {
50- InputStream resource = RepertoireCommune .class .getClassLoader ().getResourceAsStream ("communes.csv" );
51- if (resource == null )
52- throw new FileNotFoundException ();
53- Reader reader = new InputStreamReader (resource );
54- result = new CsvToBeanBuilder <Commune >(reader ).withType (Commune .class ).build ().parse ();
47+ Reader reader = OutilsRepertoireCommune .getRessource ("communes.csv" );
48+ result = OutilsRepertoireCommune .convertirCsvEnCommune (reader );
5549 } catch (IllegalStateException | FileNotFoundException e ) {
56- log .error ("Le fichier contenant les communes n'a pas été trouvé" , e );
50+ log .error (e . getMessage () , e );
5751 }
5852 return result ;
5953 }
@@ -63,21 +57,13 @@ private static List<Commune> initCommunes() {
6357 private static final Map <String , Commune > REPERTOIRE_NOM_ET_CODE_POSTAL ;
6458
6559 static {
66- Map <Integer , List <Commune >> codePostaux = new HashMap <>();
67- Map <String , List <Commune >> noms = new HashMap <>();
68- Map <String , Commune > nomEtCodePostal = new HashMap <>();
69- for (Commune Commune : COMMUNES ) {
70- nomEtCodePostal .put (OutilsString .formater (Commune .getNom ()) + Commune .getCodePostal (), Commune );
71- List <Commune > villesNom = noms .computeIfAbsent (OutilsString .formater (Commune .getNom ()),
72- k -> new ArrayList <>());
73- List <Commune > villesCodePostal = codePostaux .computeIfAbsent (Commune .getCodePostal (),
74- k -> new ArrayList <>());
75- villesNom .add (Commune );
76- villesCodePostal .add (Commune );
77- }
78- REPERTOIRE_CODE_POSTAL = Collections .unmodifiableMap (codePostaux );
79- REPERTOIRE_NOM = Collections .unmodifiableMap (noms );
80- REPERTOIRE_NOM_ET_CODE_POSTAL = Collections .unmodifiableMap (nomEtCodePostal );
60+ Map <Integer , List <Commune >> repCodePostaux = new HashMap <>();
61+ Map <String , List <Commune >> repNoms = new HashMap <>();
62+ Map <String , Commune > repNomEtCodePostal = new HashMap <>();
63+ OutilsRepertoireCommune .initialiserRepertoires (repCodePostaux , repNoms , repNomEtCodePostal , COMMUNES );
64+ REPERTOIRE_CODE_POSTAL = Collections .unmodifiableMap (repCodePostaux );
65+ REPERTOIRE_NOM = Collections .unmodifiableMap (repNoms );
66+ REPERTOIRE_NOM_ET_CODE_POSTAL = Collections .unmodifiableMap (repNomEtCodePostal );
8167 }
8268
8369 /**
0 commit comments