From: Sylvain Papa Date: Thu, 17 Jan 2019 15:05:48 +0000 (+0100) Subject: Work on Region, RegionView, countries.csv, Country X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f56708fa0a19755ac5ec0313d9ee9c45a9aef0ce;p=Persons_Comparator.git Work on Region, RegionView, countries.csv, Country --- diff --git a/data/countries.csv b/data/countries.csv index 2e32534..628fc98 100644 --- a/data/countries.csv +++ b/data/countries.csv @@ -1,4 +1,3 @@ -"name","tld","cca2","ccn3","cca3","cioc","independent","status","currency","callingCode","capital","altSpellings","region","subregion","languages","translations","latlng","demonym","landlocked","borders","area","flag" "Aruba,Aruba,Aruba,Aruba,Aruba,Aruba",".aw","AW","533","ABW","ARU","","officially-assigned","AWG","297","Oranjestad","AW","Americas","Caribbean","Dutch,Papiamento","Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,アルバ,アルバ,Aruba,Aruba,Aruba,Aruba,Аруба,Аруба,Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,Aruba,阿鲁巴,阿鲁巴,Aruba,Aruba,اروبا,اروبا,아루바,아루바","12.5,-69.96666666","Aruban","","","180","🇦🇼" "Afghanistan,Islamic Republic of Afghanistan,جمهوری اسلامی افغانستان,افغانستان,د افغانستان اسلامي جمهوریت,افغانستان,Owganystan Yslam Respublikasy,Owganystan",".af","AF","004","AFG","AFG","1","officially-assigned","AFN","93","Kabul","AF,Afġānistān","Asia","Southern Asia","Dari,Pashto,Turkmen","Afghánská islámská republika,Afghánistán,Gweriniaeth Islamaidd Affganistan,Affganistan,Islamische Republik Afghanistan,Afghanistan,République islamique d'Afghanistan,Afghanistan,Islamska Republika Afganistan,Afganistan,Repubblica islamica dell'Afghanistan,Afghanistan,アフガニスタン·イスラム共和国,アフガニスタン,Islamitische Republiek Afghanistan,Afghanistan,República Islâmica do Afeganistão,Afeganistão,Исламская Республика Афганистан,Афганистан,Afgánsky islamský štát,Afganistan,República Islámica de Afganistán,Afganistán,Afganistanin islamilainen tasavalta,Afganistan,Afganistani Islamivabariik,Afganistan,阿富汗伊斯兰共和国,阿富汗,Islamska Republika Afganistanu,Afganistan,اسلامی جمہوریہ افغانستان,افغانستان,아프가니스탄 이슬람 공화국,아프가니스탄","33,65","Afghan","1","IRN,PAK,TKM,UZB,TJK,CHN","652230","🇦🇫" "Angola,Republic of Angola,República de Angola,Angola",".ao","AO","024","AGO","ANG","1","officially-assigned","AOA","244","Luanda","AO,República de Angola,ʁɛpublika de an'ɡɔla","Africa","Middle Africa","Portuguese","Angolská republika,Angola,Gweriniaeth Angola,Angola,Republik Angola,Angola,République d'Angola,Angola,Republika Angola,Angola,Repubblica dell'Angola,Angola,アンゴラ共和国,アンゴラ,Republiek Angola,Angola,República de Angola,Angola,Республика Ангола,Ангола,Angolská republika,Angola,República de Angola,Angola,Angolan tasavalta,Angola,Angola Vabariik,Angola,安哥拉共和国,安哥拉,Republika Angoli,Angola,جمہوریہ انگولہ,انگولہ,앙골라 공화국,앙골라","-12.5,18.5","Angolan","","COG,COD,ZMB,NAM","1246700","🇦🇴" @@ -46,8 +45,7 @@ "China,People's Republic of China,中华人民共和国,中国",".cn,.中国,.中國,.公司,.网络","CN","156","CHN","CHN","1","officially-assigned","CNY","86","Beijing","CN,Zhōngguó,Zhongguo,Zhonghua,People's Republic of China,中华人民共和国,Zhōnghuá Rénmín Gònghéguó","Asia","Eastern Asia","Chinese","Čínská lidová republika,Čína,Gweriniaeth Pobl Tsieina,Tsieina,Volksrepublik China,China,République populaire de Chine,Chine,Narodna Republika Kina,Kina,Repubblica popolare cinese,Cina,中華人民共和国,中国,Volksrepubliek China,China,República Popular da China,China,Народная Республика Китай,Китай,Čínska ľudová republika,Čína,República Popular de China,China,Kiinan kansantasavalta,Kiina,Hiina Rahvavabariik,Hiina,Chińska Republika Ludowa,Chiny,عوامی جمہوریہ چین,چین,중화인민공화국,중국","35,105","Chinese","","AFG,BTN,MMR,HKG,IND,KAZ,NPL,PRK,KGZ,LAO,MAC,MNG,PAK,RUS,TJK,VNM","9706961","🇨🇳" "Ivory Coast,Republic of Côte d'Ivoire,République de Côte d'Ivoire,Côte d'Ivoire",".ci","CI","384","CIV","CIV","1","officially-assigned","XOF","225","Yamoussoukro","CI,Côte d'Ivoire,Ivory Coast,Republic of Côte d'Ivoire,République de Côte d'Ivoire","Africa","Western Africa","French","Republika Pobřeží slonoviny,Pobřeží slonoviny,Republik Côte d'Ivoire,Elfenbeinküste,République de Côte d' Ivoire,Côte d'Ivoire,Republika Côte d'Ivoire,Obala Bjelokosti,Repubblica della Costa d'Avorio,Costa d'Avorio,コートジボワール共和国,コートジボワール,Republiek Ivoorkust,Ivoorkust,República da Côte d'Ivoire,Costa do Marfim,Республика Кот-д'Ивуаре,Кот-д’Ивуар,Republika Pobrežie Slonoviny,Pobržie Slonoviny,República de Côte d'Ivoire,Costa de Marfil,Norsunluurannikon tasavalta,Norsunluurannikko,Côte d’Ivoire’i Vabariik,Elevandiluurannik,科特迪瓦共和国,科特迪瓦,Republika WybrzeŻa Kości Słoniowej,WybrzeŻe Kości Słoniowej,جمہوریہ کوت دیواغ,آئیوری کوسٹ,코트디부아르 공화국,코트디부아르","8,-5","Ivorian","","BFA,GHA,GIN,LBR,MLI","322463","🇨🇮" "Cameroon,Republic of Cameroon,Republic of Cameroon,Cameroon,République du Cameroun,Cameroun",".cm","CM","120","CMR","CMR","1","officially-assigned","XAF","237","Yaoundé","CM,Republic of Cameroon,République du Cameroun","Africa","Middle Africa","English,French","Kamerunská republika,Kamerun,Gweriniaeth Camerŵn,Camerŵn,Republik Kamerun,Kamerun,République du Cameroun,Cameroun,Republika Kamerun,Kamerun,Repubblica del Camerun,Camerun,カメルーン共和国,カメルーン,Republiek Kameroen,Kameroen,República dos Camarões,Camarões,Республика Камерун,Камерун,Kamerunská republika,Kamerun,República de Camerún,Camerún,Kamerunin tasavalta,Kamerun,Kameruni Vabariik,Kamerun,喀麦隆共和国,喀麦隆,Republika WybrzeŻa Kości Słoniowej,WybrzeŻe Kości Słoniowej,جمہوریہ کیمرون,کیمرون,카메룬 공화국,카메룬","6,12","Cameroonian","","CAF,TCD,COG,GNQ,GAB,NGA","475442","🇨🇲" -"DR Congo,Democratic Republic of the Congo,République démocratique du Congo,RD Congo,Repubilika ya Kongo Demokratiki,Repubilika ya Kongo Demokratiki,Republiki ya Kongó Demokratiki,Republiki ya Kongó Demokratiki,Ditunga dia Kongu wa Mungalaata,Ditunga dia Kongu wa Mungalaata,Jamhuri ya Kidemokrasia ya Kongo,Jamhuri ya Kidemokrasia ya Kongo",".cd","CD","180","COD","COD","1","officially-assigned","CDF","243","Kinshasa","CD,DR Congo,Congo-Kinshasa,Congo, the Democratic Republic of the,DRC","Africa","Middle Africa","French,Kikongo,Lingala,Tshiluba,Swahili","Demokratická republika Kongo,DR Kongo,Gweriniaeth Ddemocrataidd Congo,Gweriniaeth Ddemocrataidd Congo,Demokratische Republik Kongo,Kongo (Dem. Rep.),République démocratique du Congo,Congo (Rép. dém.),Demokratska Republika Kongo,Kongo, Demokratska Republika,Repubblica Democratica del Congo,Congo (Rep. Dem.),コンゴ民主共和国,コンゴ民主共和国,Democratische Republiek Congo,Congo (DRC),República Democrática do Congo,República Democrática do Congo,Демократическая Республика Конго,Демократическая Республика Конго,Konžská demokratická republika,Kongo,República Democrática del Congo,Congo (Rep. Dem.),Kongon demokraattinen tasavalta,Kongon demokraattinen tasavalta,Kongo Demokraatlik Vabariik,Kongo DV,刚果民主共和国,民主刚果,Demokratyczna Republika Konga,Demokratyczna Republika Konga,جمہوری جمہوریہ کانگو, -کانگو,콩고 민주 공화국,콩고 민주 공화국","0,25","Congolese","","AGO,BDI,CAF,COG,RWA,SSD,TZA,UGA,ZMB","2344858","🇨🇩" +"DR Congo,Democratic Republic of the Congo,République démocratique du Congo,RD Congo,Repubilika ya Kongo Demokratiki,Repubilika ya Kongo Demokratiki,Republiki ya Kongó Demokratiki,Republiki ya Kongó Demokratiki,Ditunga dia Kongu wa Mungalaata,Ditunga dia Kongu wa Mungalaata,Jamhuri ya Kidemokrasia ya Kongo,Jamhuri ya Kidemokrasia ya Kongo",".cd","CD","180","COD","COD","1","officially-assigned","CDF","243","Kinshasa","CD,DR Congo,Congo-Kinshasa,Congo, the Democratic Republic of the,DRC","Africa","Middle Africa","French,Kikongo,Lingala,Tshiluba,Swahili","Demokratická republika Kongo,DR Kongo,Gweriniaeth Ddemocrataidd Congo,Gweriniaeth Ddemocrataidd Congo,Demokratische Republik Kongo,Kongo (Dem. Rep.),République démocratique du Congo,Congo (Rép. dém.),Demokratska Republika Kongo,Kongo, Demokratska Republika,Repubblica Democratica del Congo,Congo (Rep. Dem.),コンゴ民主共和国,コンゴ民主共和国,Democratische Republiek Congo,Congo (DRC),República Democrática do Congo,República Democrática do Congo,Демократическая Республика Конго,Демократическая Республика Конго,Konžská demokratická republika,Kongo,República Democrática del Congo,Congo (Rep. Dem.),Kongon demokraattinen tasavalta,Kongon demokraattinen tasavalta,Kongo Demokraatlik Vabariik,Kongo DV,刚果民主共和国,民主刚果,Demokratyczna Republika Konga,Demokratyczna Republika Konga,جمہوری جمہوریہ کانگو,کانگو,콩고 민주 공화국,콩고 민주 공화국","0,25","Congolese","","AGO,BDI,CAF,COG,RWA,SSD,TZA,UGA,ZMB","2344858","🇨🇩" "Republic of the Congo,Republic of the Congo,République du Congo,République du Congo,Repubilika ya Kongo,Repubilika ya Kongo,Republíki ya Kongó,Republíki ya Kongó",".cg","CG","178","COG","CGO","1","officially-assigned","XAF","242","Brazzaville","CG,Congo,Congo-Brazzaville","Africa","Middle Africa","French,Kikongo,Lingala","Konžská republika,Kongo,Gweriniaeth y Congo,Gweriniaeth y Congo,Republik Kongo,Kongo,République du Congo,Congo,Republika Kongo,Kongo,Repubblica del Congo,Congo,コンゴ共和国,コンゴ共和国,Republiek Congo,Congo,República do Congo,Congo,Республика Конго,Республика Конго,Konžská republika,Kongo,República del Congo,Congo,Kongon tasavalta,Kongo-Brazzaville,Kongo Vabariik,Kongo Vabariik,刚果共和国,刚果,Republika Konga,Kongo,جمہوریہ کانگو,جمہوریہ کانگو,콩고,콩고","-1,15","Congolese","","AGO,CMR,CAF,COD,GAB","342000","🇨🇬" "Cook Islands,Cook Islands,Cook Islands,Cook Islands,Kūki 'Āirani,Kūki 'Āirani",".ck","CK","184","COK","COK","","officially-assigned","NZD,CKD","682","Avarua","CK,Kūki 'Āirani","Oceania","Polynesia","English,Cook Islands Māori","Cookovy ostrovy,Cookovy ostrovy,Ynysoedd Cook,Ynysoedd Cook,Cookinseln,Cookinseln,Îles Cook,Îles Cook,Cook Islands,Cookovo Otočje,Isole Cook,Isole Cook,クック諸島,クック諸島,Cook eilanden,Cookeilanden,Ilhas Cook,Ilhas Cook,острова Кука,Острова Кука,Cookove ostrovy,Cookove ostrovy,Islas Cook,Islas Cook,Cookinsaaret,Cookinsaaret,Cooki saared,Cooki saared,库克群岛,库克群岛,Wyspy Cooka,Wyspy Cooka,جزائر کک,جزائر کک,쿡 제도,쿡 제도","-21.23333333,-159.76666666","Cook Islander","","","236","🇨🇰" "Colombia,Republic of Colombia,República de Colombia,Colombia",".co","CO","170","COL","COL","1","officially-assigned","COP","57","Bogotá","CO,Republic of Colombia,República de Colombia","Americas","South America","Spanish","Kolumbijská republika,Kolumbie,Gweriniaeth Colombia,Colombia,Republik Kolumbien,Kolumbien,République de Colombie,Colombie,Republika Kolumbija,Kolumbija,Repubblica di Colombia,Colombia,コロンビア共和国,コロンビア,Republiek Colombia,Colombia,República da Colômbia,Colômbia,Республика Колумбия,Колумбия,Kolumbijská republika,Kolumbia,República de Colombia,Colombia,Kolumbian tasavalta,Kolumbia,Colombia Vabariik,Colombia,哥伦比亚共和国,哥伦比亚,Republika Kolumbii,Kolumbia,جمہوریہ کولمبیا,کولمبیا,콜롬비아 공화국,콜롬비아","4,-72","Colombian","","BRA,ECU,PAN,PER,VEN","1141748","🇨🇴" diff --git a/src/Country.java b/src/Country.java index 08c4da2..8b71108 100644 --- a/src/Country.java +++ b/src/Country.java @@ -1,247 +1,40 @@ -import java.util.ArrayList; - public class Country { private String name; - ArrayList topLevelDomain = new ArrayList(); - private String alpha2Code; - private String alpha3Code; - ArrayList callingCodes = new ArrayList(); - private String capital; - ArrayList altSpellings = new ArrayList(); private String region; - private String subregion; - private float population; - ArrayList latlng = new ArrayList(); - private String demonym; - private float area; - private float gini; - ArrayList timezones = new ArrayList(); - ArrayList borders = new ArrayList(); - private String nativeName; - private String numericCode; - ArrayList currencies = new ArrayList(); - ArrayList languages = new ArrayList(); - Translations TranslationsObject; - private String flag; - ArrayList regionalBlocs = new ArrayList(); - private String cioc; - - public class Translations { - private String de; - private String es; - private String fr; - private String ja; - private String it; - private String br; - private String pt; - private String nl; - private String hr; - - - // Getter Methods - - public String getDe() { - return de; - } - - public String getEs() { - return es; - } - - public String getFr() { - return fr; - } - - public String getJa() { - return ja; - } - - public String getIt() { - return it; - } - - public String getBr() { - return br; - } - - public String getPt() { - return pt; - } - - public String getNl() { - return nl; - } - - public String getHr() { - return hr; - } - - - - // Setter Methods - - public void setDe(String de) { - this.de = de; - } - - public void setEs(String es) { - this.es = es; - } - - public void setFr(String fr) { - this.fr = fr; - } - - public void setJa(String ja) { - this.ja = ja; - } + private double lat; + private double lng; - public void setIt(String it) { - this.it = it; - } - public void setBr(String br) { - this.br = br; - } - - public void setPt(String pt) { - this.pt = pt; - } - - public void setNl(String nl) { - this.nl = nl; - } - - public void setHr(String hr) { - this.hr = hr; - } - - - } - - - // Getter Methods - - public String getName() { - return name; - } - - public String getAlpha2Code() { - return alpha2Code; - } - - public String getAlpha3Code() { - return alpha3Code; - } - - public String getCapital() { - return capital; + public Country(String name, String region, double lat, double lng) { + setName(name); + setRegion(region); + setLat(lat); + setLng(lng); } - public String getRegion() { - return region; - } - - public String getSubregion() { - return subregion; - } - - public float getPopulation() { - return population; - } - - public String getDemonym() { - return demonym; - } - - public float getArea() { - return area; - } - - public float getGini() { - return gini; - } - - public String getNativeName() { - return nativeName; - } - - public String getNumericCode() { - return numericCode; - } - - public Translations getTranslations() { - return TranslationsObject; - } - - public String getFlag() { - return flag; - } - - public String getCioc() { - return cioc; - } - - // Setter Methods - public void setName(String name) { this.name = name; } - public void setAlpha2Code(String alpha2Code) { - this.alpha2Code = alpha2Code; - } - - public void setAlpha3Code(String alpha3Code) { - this.alpha3Code = alpha3Code; - } - - public void setCapital(String capital) { - this.capital = capital; - } - public void setRegion(String region) { this.region = region; } - public void setSubregion(String subregion) { - this.subregion = subregion; - } - - public void setPopulation(float population) { - this.population = population; - } - - public void setDemonym(String demonym) { - this.demonym = demonym; - } - - public void setArea(float area) { - this.area = area; + public void setLat(double lat) { + this.lat = lat; } - public void setGini(float gini) { - this.gini = gini; + public void setLng(double lng) { + this.lng = lng; } - public void setNativeName(String nativeName) { - this.nativeName = nativeName; - } - - public void setNumericCode(String numericCode) { - this.numericCode = numericCode; - } - - public void setTranslations(Translations translationsObject) { - this.TranslationsObject = translationsObject; - } - - public void setFlag(String flag) { - this.flag = flag; - } - - public void setCioc(String cioc) { - this.cioc = cioc; + @Override + public String toString() { + return "Country{" + + "name='" + name + '\'' + + ", region='" + region + '\'' + + ", lat=" + lat + + ", lng=" + lng + + '}'; } } - diff --git a/src/Main.java b/src/Main.java index 17cf896..194ff31 100644 --- a/src/Main.java +++ b/src/Main.java @@ -75,6 +75,9 @@ public class Main { Person emptyPerson = new Person(); PersonView emptyPersonView = new PersonView(emptyPerson, personArrayList); + Region r = new Region(); + r.getCsvFile(); + //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. diff --git a/src/Region.java b/src/Region.java index 1deb36d..b20d0cb 100644 --- a/src/Region.java +++ b/src/Region.java @@ -1,15 +1,64 @@ +import java.io.File; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; -import java.util.TreeMap; +import java.util.Scanner; -public class Region extends TreeMap> { - private List country; +public class Region { - public void setCountry(List origins) { - this.country = country; + private String csvFile = "data/countries.csv"; + private ArrayList countryArrayListEurope = new ArrayList<>(); + private ArrayList countryArrayListAfrica = new ArrayList<>(); + private ArrayList countryArrayListAmericas = new ArrayList<>(); + private ArrayList countryArrayListAsia = new ArrayList<>(); + private ArrayList countryArrayListOceania = new ArrayList<>(); + + + public Region() { } - public List getCountry() { - return country; + public void getCsvFile() { + CSVUtils csvUtils = new CSVUtils(); + Scanner scanner = null; + try { + scanner = new Scanner(new File(csvFile)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + while (scanner.hasNext()) { + + List line = csvUtils.parseLine(scanner.nextLine()); + + String c3 = line.get(0); + String[] splitArray = c3.split(","); + String c2 = line.get(16); + String[] splitArray2 = c2.split(","); + + if (line.get(12).equals("Europe")) { + Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + countryArrayListEurope.add(c); + } else if (line.get(12).equals("Africa")) { + Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + countryArrayListAfrica.add(c); + } else if (line.get(12).equals("Americas")) { + Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + countryArrayListAmericas.add(c); + } else if (line.get(12).equals("Asia")) { + Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + countryArrayListAsia.add(c); + } else if (line.get(12).equals("Oceania")) { + Country c = new Country(splitArray[1], line.get(12), Double.parseDouble(splitArray2[0]), Double.parseDouble(splitArray2[1])); + countryArrayListOceania.add(c); + } + + + } + scanner.close(); + /*Utils.displayArrayList(countryArrayListOceania); + Utils.displayArrayList(countryArrayListAfrica); + Utils.displayArrayList(countryArrayListAmericas); + Utils.displayArrayList(countryArrayListAsia); + Utils.displayArrayList(countryArrayListEurope);*/ } -} + +} \ No newline at end of file diff --git a/src/RegionView.java b/src/RegionView.java index 0f2f8cc..1a28f5a 100644 --- a/src/RegionView.java +++ b/src/RegionView.java @@ -1,2 +1,17 @@ -public class RegionView { +import javax.swing.*; + +public class RegionView extends JPanel { + private Region regionObj; + private JLabel label; + + RegionView(Region regionObj) { + setRegionObj(regionObj); + this.label = new JLabel(); + this.label.setText("Region"); + } + + public void setRegionObj(Region regionObj) { + this.regionObj = regionObj; + + } }