Merge branch 'master' of /home/sylvain/IdeaProjects/Persons_Comparator with conflicts.
[Persons_Comparator.git] / src / Main.java
index 221d09c15b67fcdcb2e507412a40b98ec0b26aa6..a6c37f903c9b263f14a5a3cf117d7ce42a192e15 100644 (file)
@@ -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<Person> personArrayList = new ArrayList<>();
+
+       /* ArrayList<Person> 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> 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();
             }
-        });
+        }); */
     }
 }