X-Git-Url: https://git.piment-noir.org/?p=Persons_Comparator.git;a=blobdiff_plain;f=src%2FMain.java;h=a6c37f903c9b263f14a5a3cf117d7ce42a192e15;hp=221d09c15b67fcdcb2e507412a40b98ec0b26aa6;hb=5bdd299653b9c3f29a817a555ae6a17eac41b75b;hpb=9b3bfcdd95253a04ed12a676ee29a9d777c1e496 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(); } - }); + }); */ } }