From cc6dd53394f4d35a20b41bba3693a1c94991f97d Mon Sep 17 00:00:00 2001 From: "pro.boooooo" Date: Thu, 5 Jan 2023 18:34:55 +0100 Subject: [PATCH] $ --- build/Graphics/GraphicFile.class | Bin 1448 -> 1943 bytes build/Graphics/Traitable.class | Bin 2602 -> 4137 bytes src/Graphics/GraphicFile.java | 4 + src/Graphics/Traitable.java | 136 ++++++++++++++++--------------- toFormat.json | 2 +- 5 files changed, 74 insertions(+), 68 deletions(-) diff --git a/build/Graphics/GraphicFile.class b/build/Graphics/GraphicFile.class index b78811e117ed2945b3fb83421ff9ff489c85a0da..98d876b42a9a5bb7eebdb47215fdd8cb36eb03f2 100644 GIT binary patch delta 923 zcmY+D%WuBww}gqNJ`@JSfEI- zWm9>9kPusDmNO$F(FHl@fWU#kEcZ8nkCY__Rqi%l09n{Iy7{BG00KoqvxB-qx-c6KzfmYq@9rP&?9*;W*L zYnd?ZG)Endaa_@SpjZsb zLCKvT^MYJ)y4++j8e`1i1Sd7898Pma(KhSeax?DjATwO@r$^np#f88j&bY$_XC2OQ zUeP)%G&z5&oS7)Oe&9~#y{PAc!$mGRT;_`AsxiNQM*7$)P4ZM;Y z6ieX~wcEHs;s5t4r7G5(cX!+i6fMcr=#OTB1{EuQ0u(X-D~F=#7=lEN(1lJ;-?wRbx?IqOYD3Nd3Q67NffgJyT{cevwV{`EhJY(gc{iF0n=TPQ_| zVplT!V5|v`m~G)bLx&y4O{*AvgmU=MNU4ReYCKoB!n`@!(1Gj3IBSwfsz#eBB>HeIFd z8Es=y-c+SyiOyQ(Ur{kBQleeVw_0?vtd!U;XeZ6$>TcPkS7KV6I#3YlWGlZq-(sXNjG!2@BmQg;EUdE#COAV!IZ^95lM7>w2z?O~X W3Aib`{k2UD5m7=eF~(pm+5Z`}AhZqu delta 473 zcmW-d%}*0S7{-6Iv^%if(q&t0Rcx_Pq_k2k(kck@p+eE3@^vLmAVCr=!otdt_Z|3=!H+eoLE@GR%|6Kh5>TEgmaifQu4ERC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U(+-1^Q&$vvvJnQisrHphsY3skJc}X*^xcc{R=2tai?x`;Gz4pwUGidHQ7ZW+U zOqggH>>%sY$v&S)>C&9?d6^kS=5#REd9qU82rFTAd3~)=C}?JVUg1?mtNGDs?a;jD zbDGzE=6J*BO{={{=rhlPnNF@Z`<$VyP&oyfvp$O~nSH62p=Fm9pSM}{d51M=HdzTb zmX;Sb`%YEDOESPCoSRYmgP zRQH4;y;-i7cHXRO#`M?iH?@>+?j^OktBXSh`!iZ&uRZ zsq?1OD+TScC4|8YLJf+CV(VeCg(cDJ#Fyg{k^9Xxuc!Zj_*zJbY$VBU8YHrrCiaSS zEU7jURDp!#!X@*EH-07?MC|&Sfgl^v(3rbUZd=QLMN>XjBkE^AO{lH=zvmMXjj{Uk z7Rk~Ue(4)@rYRzQTUxlB=L2c%@*y>8?qDI!u*Y2S51gH%hiL-YQC|4(6~gX2@YhOm{Ftu>vOM%s*a;kw1ti3~SI7(U zcVs~bgFWAp4Du0ev$y4KJ9}3g_c`@^K`Yn9+s9*4OV${lgsq*jiFS allVariables = fileTraited.getVariableMap(); + for (String key : allVariables.keySet()) { + System.out.println("Clé : " + key + " , Valeur : " + allVariables.get(key)); + } + jsonReader.close(); } catch (IOException e) { System.out.println("[!] Fichier " + url.getFile() + " n'existe pas"); diff --git a/src/Graphics/Traitable.java b/src/Graphics/Traitable.java index 76c9aeb..04466f8 100644 --- a/src/Graphics/Traitable.java +++ b/src/Graphics/Traitable.java @@ -38,6 +38,8 @@ public class Traitable { allJson.append(c); } + allJson = this.ajustementVirguleEnd(allJson.toString()); + while (i < allJson.length()) { if (allJson.charAt(i) == '"') { while (allJson.charAt(i) != ',') { @@ -45,7 +47,38 @@ public class Traitable { i++; } - // System.out.println(this.getNomOfRecord(tmp)); + Object value = new Object(); + String name = this.getNomOfRecord(tmp); + String[] typeOfVariable = this.getValueOfRecord(tmp.toString()); + + switch (typeOfVariable[0]) { + case "int": { + value = Integer.valueOf(typeOfVariable[1]); + break; + } + + case "string": { + value = String.valueOf(typeOfVariable[1]); + break; + } + + case "boolean": { + value = Boolean.valueOf(typeOfVariable[1]); + break; + } + + case "float": { + value = Double.valueOf(typeOfVariable[1]); + break; + } + + default: { + value = null; + break; + } + } + + this.content.put(name, value); tmp.setLength(0); } @@ -53,7 +86,6 @@ public class Traitable { } } catch (StringIndexOutOfBoundsException ignore) { } - } catch (IOException e) { System.out.println("[!] Probleme lors de la lecture du fichier"); } @@ -76,80 +108,50 @@ public class Traitable { return null; } - // TODO: a finir (Bilal) - private Object getValueOfRecord(StringBuilder sb) { - // int i; - // int counter; - // StringBuilder value = new StringBuilder(); - // String type = ""; + /** + * Pour recuperer le type et la valeur d'une variable JSON + * + * @param jsonLine La ligne json a evaluer + * @return Un tableau { [0] = type, [1] = valeur } + */ + private String[] getValueOfRecord(String jsonLine) { + String[] parts = jsonLine.split(":"); + String value = parts[1]; - // /** - // * Tableau - // */ - // if (sb.indexOf("[") != -1) { - // type = "tableau"; - // } + if (value.charAt(0) == ' ') { + value = value.substring(1); + } - // /** - // * Chaine de characteres - // */ - // for (i = 0, counter = 0; i <= sb.length() - 1; i++) { - // if (sb.charAt(i) == '"') { - // counter++; - // } - // } + if (value.contains("\"")) { + return new String[] { "string", value }; + } else if (value.contains("{")) { + return new String[] { "objet", value }; + } else if (value.contains("[")) { + return new String[] { "tableau", value }; + } else if (value.contains("true") || value.contains("false")) { + return new String[] { "boolean", value }; + } else if (value.contains(".")) { + return new String[] { "float", value }; + } else { + return new String[] { "int", value }; + } + } - // if (counter < 2 && sb.indexOf(".") != -1) { - // type = "float"; - // } + private StringBuilder ajustementVirguleEnd(String str) { + int longueur = str.length(); + char avantDernierCaractere = str.charAt(longueur - 2); + String nouvelleChaine = str.substring(0, longueur - 2) + avantDernierCaractere + "," + + str.substring(longueur - 1); - // /* - // * Objet - // */ - // if (sb.indexOf("{") != -1) { - // type = "objet"; - // } - - // /* - // * Integer - // */ - // for (i = 0, counter = 0; i <= sb.length() - 1; i++) { - // if (sb.charAt(i) == '"') { - // counter++; - // } - // } - - // if (counter < 2) { - // type = "int"; - // } - - // /** - // * Flottant - // */ - // for (i = 0, counter = 0; i <= sb.length() - 1; i++) { - // if (sb.charAt(i) == '"') { - // counter++; - // } - // } - - // if (counter < 2 && sb.indexOf(".") != -1) { - // type = "float"; - // } - - return null; + return new StringBuilder(nouvelleChaine); } /** - * Ajouter le jeu de cle valeur dans la liste + * Recuperer le jeu de cles valeurs dans GrahicFile * - * @param name Nom de la variable - * @param value Contenue de la variable + * @see Graphics.GraphicFile + * @return Le jeu de cles valeurs */ - private void addToList(String name, Object value) { - System.out.println("[+] => " + name + ": " + value); - this.content.put(name, value); - } - public HashMap getVariableMap() { return this.content; } diff --git a/toFormat.json b/toFormat.json index 25ad443..08cd72f 100644 --- a/toFormat.json +++ b/toFormat.json @@ -1 +1 @@ -{"prenom":"Bilal", "age": 19,} \ No newline at end of file +{"prenom":"Bilal", "age": 19, "nationalite": "Franco-Algerienne", "enVie": true, "poid": 1.7} \ No newline at end of file