From cb7d442c3316c4b617aed338b89967331cd38ea5 Mon Sep 17 00:00:00 2001 From: EryneKL <97091460+EryneKL@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:59:42 +0200 Subject: [PATCH] =?UTF-8?q?FEAT=20ITEM-269-back-modifier-lordre-de-tri-du-?= =?UTF-8?q?fichier=20=20=20=20=20=20-=20simplification=20du=20code=20de=20?= =?UTF-8?q?la=20m=C3=A9thode=20trierLignesDeCorrespondances()=20dans=20Fic?= =?UTF-8?q?hierPrepare.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../item/core/components/FichierPrepare.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/fr/abes/item/core/components/FichierPrepare.java b/core/src/main/java/fr/abes/item/core/components/FichierPrepare.java index 16e60c74..d152a7d2 100644 --- a/core/src/main/java/fr/abes/item/core/components/FichierPrepare.java +++ b/core/src/main/java/fr/abes/item/core/components/FichierPrepare.java @@ -122,25 +122,16 @@ public void alimenterPpn(String input, String listeEpn, String rcr) { public void trierLignesDeCorrespondances() throws IOException { FileReader fileReader = new FileReader(path.resolve(filename).toString()); BufferedReader reader = new BufferedReader(fileReader); - List correspondanceUnsortList = new ArrayList<>(); - String result = null; - int i = 0; - for (String line = reader.readLine(); line != null; line = reader.readLine()) { - if (i == 0) { // stockage de la ligne d'en-tête - result = line + "\n"; - i++; - } else { - // stockage des lignes de correspondance - correspondanceUnsortList.add(line+"\n"); - } - } + + List correspondanceSortList = new ArrayList<>(); + String header = reader.readLine();//cette ligne enleve le header et le stock + correspondanceSortList.add(header + "\n"); + reader.lines().sorted().forEach(line -> { + correspondanceSortList.add(line+"\n"); + }); reader.close(); fileReader.close(); - // tri des lignes - Collections.sort(correspondanceUnsortList); - // assemblage de l'en-tête avec les lignes pour constituer le résultat final - List correspondanceSortList = new ArrayList<>(correspondanceUnsortList); - result = result + correspondanceSortList.toString().replaceAll(", ","").replaceAll("\\[", "").replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\]", ""); + String result = String.join("", correspondanceSortList); ecrireFichierTrie(result); }