-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");
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();
}
- });
+ }); */
}
}
-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<String, ArrayList<Country>> {
+ private List<Country> country;
- public Region() {
+ public void setCountry(List<Country> 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<Country> getCountry() {
+ return country;
}
}