From: Sylvain Papa Date: Mon, 14 Jan 2019 15:07:00 +0000 (+0100) Subject: Merge branch 'master' of /home/sylvain/IdeaProjects/Persons_Comparator with conflicts. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5bdd299653b9c3f29a817a555ae6a17eac41b75b;p=Persons_Comparator.git Merge branch 'master' of /home/sylvain/IdeaProjects/Persons_Comparator with conflicts. --- diff --git a/src/Country.java b/src/Country.java index 0dffb2c..08c4da2 100644 --- a/src/Country.java +++ b/src/Country.java @@ -36,7 +36,7 @@ public class Country { private String pt; private String nl; private String hr; - private String fa; + // Getter Methods @@ -76,9 +76,7 @@ public class Country { return hr; } - public String getFa() { - return fa; - } + // Setter Methods @@ -118,9 +116,7 @@ public class Country { this.hr = hr; } - public void setFa(String fa) { - this.fa = fa; - } + } diff --git a/src/Main.java b/src/Main.java index 221d09c..a6c37f9 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,11 +1,24 @@ -import java.util.ArrayList; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonIOException; +import com.google.gson.JsonSyntaxException; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.MalformedJsonException; + +import java.io.IOException; +import java.io.StringReader; +import java.util.List; + +import static com.google.gson.internal.Streams.parse; public class Main { public static void main(String[] args) { - String programName = "Person Comparator"; + /* String programName = "Person Comparator"; */ - ArrayList personArrayList = new ArrayList<>(); + + /* ArrayList personArrayList = new ArrayList<>(); Person person1 = new Person("Alan", "United States of America", 180, 95, "black"); personArrayList.add(person1); Person person2 = new Person("Brice", "France", 190, 82, "brown"); @@ -76,14 +89,50 @@ public class Main { Person emptyPerson = new Person(); emptyPerson.setPersonArrayList(personArrayList); PersonView emptyPersonView = new PersonView(emptyPerson); + */ + + + Gson gson = new Gson(); + String continent = "coutryTry.json"; + + //JsonReader reader = new JsonReader(new StringReader(rep)); + + + + JsonElement jsonelement; + try { + String reader; + reader = "{/home/sylvain/IdeaProjects/Persons_Comparator/data/coutryTry.json}"; + + JsonReader jsonreader; + jsonreader = new JsonReader(new StringReader(reader)); + jsonelement = parse(jsonreader); + jsonreader.setLenient(true); + if (!jsonelement.isJsonNull() && jsonreader.peek() != JsonToken.END_DOCUMENT) { + throw new JsonSyntaxException("Did not consume the entire document."); + } + Region region = gson.fromJson(reader,Region.class); + List country = region.getCountry(); + System.out.println(country); + } catch (MalformedJsonException malformedjsonexception) { + throw new JsonSyntaxException(malformedjsonexception); + } catch (IOException ioexception) { + throw new JsonIOException(ioexception); + } catch (NumberFormatException numberformatexception) { + throw new JsonSyntaxException(numberformatexception); + } + + + //File path = new File(rep+continent); + //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. - javax.swing.SwingUtilities.invokeLater(new Runnable() { + /* javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { MainWindowsView mainWindows = new MainWindowsView(programName, emptyPersonView); mainWindows.showGUI(); } - }); + }); */ } } diff --git a/src/Origin.java b/src/Origin.java index 7d3e855..efce11a 100644 --- a/src/Origin.java +++ b/src/Origin.java @@ -13,6 +13,7 @@ public class Origin implements Comparable { {"Australia"} /* Oceania */ }; + Origin() { } diff --git a/src/Region.java b/src/Region.java index 927cffa..1deb36d 100644 --- a/src/Region.java +++ b/src/Region.java @@ -1,38 +1,15 @@ -import com.google.gson.Gson; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.List; import java.util.TreeMap; public class Region extends TreeMap> { + private List country; - public Region() { + public void setCountry(List origins) { + this.country = country; } - @SuppressWarnings("SpellCheckingInspection") - public void lectureOrigine(String continent, String pays) { - Gson gson = new Gson(); - Region r = new Region(); - String contenu = ""; - try { - InputStream flux = new FileInputStream(continent + ".json"); - InputStreamReader lecture = new InputStreamReader(flux); - BufferedReader buff = new BufferedReader(lecture); - String ligne; - while ((ligne = buff.readLine()) != null) { - contenu += ligne; - } - buff.close(); - } catch (Exception e) { - System.out.println(e.toString()); - } - System.out.println("les information du pays" + pays + " du fichier est : " + contenu); - // maintenant je veux deserialiser - Origin coords3 = gson.fromJson(contenu, Origin.class); - //Coordonnees co = gson.fromJson(json,Coordonnees.class); - System.out.println("Resultat = " + coords3); + public List getCountry() { + return country; } }