Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.76 KB | None | 0 0
  1. package com.obietel.manual.util;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. /**
  7. * map comes from com.google.i18n.phonenumbers.CountryCodeToRegionCodeMap.java
  8. */
  9. public class RegionCodeToIsoCountryNameMap {
  10.  
  11. private static final Map<String, String> usRegionCodeToIsoCountryMap;
  12. private static final Map<String, String> canadaRegionCodeToIsoCountryMap;
  13. private static final Map<String, String> otherNorthAMRegionCodeToIsoCountryMap;
  14. private static final Map<String, String> othersRegionCodeToIsoCountryMap;
  15.  
  16. static{
  17. // TODO - US not finished yet -- Don't use it now -- assume all "1xxxxxx" that (not Canada and not North AM Islands) are US
  18. usRegionCodeToIsoCountryMap = new HashMap<String, String>(384) {{
  19. put("1", "US"); put("1201", "US"); put("1202", "US"); put("1203", "US"); put("1205", "US"); put("1206", "US");
  20. put("1207", "US"); put("1208", "US"); put("1209", "US"); put("1210", "US"); put("1212", "US"); put("1213", "US");
  21. put("1214", "US"); put("1215", "US"); put("1216", "US"); put("1217", "US"); put("1218", "US"); put("1219", "US");
  22. put("1220", "US"); put("1224", "US"); put("1225", "US"); put("1228", "US"); put("1229", "US"); put("1231", "US");
  23. put("1234", "US"); put("1239", "US"); put("1240", "US"); put("1248", "US"); put("1251", "US"); put("1252", "US");
  24. put("1253", "US"); put("1254", "US"); put("1256", "US"); put("1260", "US"); put("1262", "US"); put("1267", "US");
  25. put("1269", "US"); put("1270", "US"); put("1272", "US"); put("1276", "US"); put("1281", "US"); put("1301", "US");
  26. put("1302", "US"); put("1303", "US"); put("1304", "US"); put("1305", "US"); put("1307", "US"); put("1308", "US");
  27. put("1309", "US"); put("1310", "US"); put("1312", "US"); put("1313", "US"); put("1314", "US"); put("1315", "US");
  28. put("1316", "US"); put("1317", "US"); put("1318", "US"); put("1319", "US"); put("1320", "US"); put("1321", "US");
  29. put("1323", "US"); put("1325", "US"); put("1330", "US"); put("1331", "US"); put("1334", "US"); put("1336", "US");
  30. put("1337", "US"); put("1339", "US"); put("1346", "US"); put("1347", "US"); put("1351", "US"); put("1352", "US");
  31. put("1360", "US"); put("1361", "US"); put("1364", "US"); put("1385", "US"); put("1386", "US"); put("1401", "US");
  32. put("1402", "US"); put("1404", "US"); put("1405", "US"); put("1406", "US"); put("1407", "US"); put("1408", "US");
  33. put("1409", "US"); put("1410", "US"); put("1412", "US"); put("1413", "US"); put("1414", "US"); put("1415", "US");
  34. put("1417", "US"); put("1419", "US"); put("1423", "US"); put("1424", "US"); put("1425", "US"); put("1432", "US");
  35. put("1434", "US"); put("1435", "US"); put("1440", "US"); put("1442", "US"); put("1443", "US"); put("1458", "US");
  36. put("1469", "US"); put("1478", "US"); put("1479", "US"); put("1480", "US"); put("1484", "US"); put("1501", "US");
  37. put("1502", "US"); put("1503", "US"); put("1504", "US"); put("1505", "US"); put("1507", "US"); put("1508", "US");
  38. put("1509", "US"); put("1510", "US"); put("1512", "US"); put("1513", "US"); put("1515", "US"); put("1516", "US");
  39. put("1517", "US"); put("1518", "US"); put("1520", "US"); put("1530", "US"); put("1531", "US"); put("1539", "US");
  40. put("1540", "US"); put("1541", "US"); put("1551", "US"); put("1559", "US"); put("1561", "US"); put("1562", "US");
  41. put("1563", "US"); put("1567", "US"); put("1570", "US"); put("1571", "US"); put("1573", "US"); put("1574", "US");
  42. put("1575", "US"); put("1580", "US"); put("1585", "US"); put("1586", "US"); put("1601", "US"); put("1602", "US");
  43.  
  44. // TODO
  45. // ...
  46. }};
  47.  
  48. canadaRegionCodeToIsoCountryMap = new HashMap<String, String>(39) {{
  49. put("1204", "CA"); put("1226", "CA"); put("1236", "CA"); put("1249", "CA"); put("1250", "CA"); put("1289", "CA");
  50. put("1306", "CA"); put("1343", "CA"); put("1365", "CA"); put("1403", "CA"); put("1416", "CA"); put("1418", "CA");
  51. put("1431", "CA"); put("1437", "CA"); put("1438", "CA"); put("1450", "CA"); put("1506", "CA"); put("1514", "CA");
  52. put("1519", "CA"); put("1548", "CA"); put("1579", "CA"); put("1581", "CA"); put("1587", "CA"); put("1600", "CA");
  53. put("1604", "CA"); put("1613", "CA"); put("1639", "CA"); put("1647", "CA"); put("1705", "CA"); put("1709", "CA");
  54. put("1778", "CA"); put("1780", "CA"); put("1782", "CA"); put("1807", "CA"); put("1819", "CA"); put("1825", "CA");
  55. put("1867", "CA"); put("1873", "CA"); put("1902", "CA"); put("1905", "CA");
  56. }};
  57.  
  58. otherNorthAMRegionCodeToIsoCountryMap = new HashMap<String, String>(26) {{
  59. put("1242", "BS"); // Bahamas
  60. put("1246", "BB"); //
  61. put("1264", "AI"); // Anguilla
  62. put("1268", "AG"); //
  63. put("1284", "VG"); //
  64. put("1340", "VI"); // U.S. Virgin Islands
  65. put("1345", "KY"); //
  66. put("1441", "BM"); //
  67. put("1473", "GD"); //
  68. put("1649", "TC"); // Turks And Caicos Islands
  69. put("1664", "MS"); //
  70. put("1670", "MP"); //
  71. put("1671", "GU"); //
  72. put("1684", "AS"); // American Samoa
  73. put("1721", "SX"); //
  74. put("1758", "LC"); // Saint Lucia
  75. put("1767", "DM"); //
  76. put("1784", "VC"); // Saint Vincent And The Grenadines
  77. put("1787", "PR"); // Puerto Rico
  78. put("1809", "DO"); // Dominican Republic
  79. put("1829", "DO"); //
  80. put("1849", "DO"); //
  81. put("1868", "TT"); // Trinidad and Tobago
  82. put("1869", "KN"); //
  83. put("1876", "JM"); //
  84. put("1939", "PR"); // Puerto Rico
  85. }};
  86.  
  87. othersRegionCodeToIsoCountryMap = new HashMap<String, String>(256) {{
  88. put("7", "RU"); // Russia
  89.  
  90. // == 2 digits ==
  91. put("20", "EG"); // Egypt
  92. put("27", "ZA"); // South Africa
  93. put("30", "GR"); // Greece
  94. put("31", "NL"); //
  95. put("32", "BE"); //
  96. put("33", "FR"); //
  97. put("34", "ES"); //
  98. put("36", "HU"); //
  99. put("39", "IT"); // Italy
  100. // TODO - VA (Vatican) is also using "39"
  101. put("40", "RO"); // Romania
  102. put("41", "CH"); //
  103. put("43", "AT"); //
  104. put("44", "GB"); //
  105. put("45", "DK"); //
  106. put("46", "SE"); //
  107. put("47", "NO"); // Norway
  108. // TODO - SJ (Svalbard And Jan Mayen) is also using "47"
  109. put("48", "PL"); //
  110. put("49", "DE"); // Germany
  111. put("51", "PE"); // Peru
  112. put("52", "MX"); //
  113. put("53", "CU"); //
  114. put("54", "AR"); //
  115. put("55", "BR"); // Brazil
  116. put("56", "CL"); //
  117. put("57", "CO"); //
  118. put("58", "VE"); //
  119. put("60", "MY"); // Malaysia
  120. put("61", "AU"); // Australia
  121. // TODO - CC (Cocos Islands) AND CX (Christmas Island) are also using "61"
  122. put("62", "ID"); // Indonesia
  123. put("63", "PH"); //
  124. put("64", "NZ"); //
  125. put("65", "SG"); //
  126. put("66", "TH"); //
  127. put("81", "JP"); //
  128. put("82", "KR"); //
  129. put("84", "VN"); //
  130. put("86", "CN"); //
  131. put("90", "TR"); // Turkey
  132. put("91", "IN"); //
  133. put("92", "PK"); //
  134. put("93", "AF"); // Afghanistan
  135. put("94", "LK"); // Sri Lanka
  136. put("95", "MM"); // Myanmar
  137. put("98", "IR"); // Iran
  138.  
  139. // === 3 digits ===
  140. put("211", "SS"); // South Sudan
  141. put("212", "MA"); // Morocco
  142. // TODO - EH (Western Sahara) is also using "212"
  143. put("213", "DZ"); // Algeria
  144. put("216", "TN"); // Tunisia
  145. put("218", "LY"); // Libya
  146. put("220", "GM"); // Gambia
  147. put("221", "SN"); // Senegal
  148. put("222", "MR"); // Mauritania
  149. put("223", "ML"); //
  150. put("224", "GN"); //
  151. put("225", "CI"); // Côte d'Ivoire
  152. put("226", "BF"); //
  153. put("227", "NE"); //
  154. put("228", "TG"); //
  155. put("229", "BJ"); // Benin
  156. put("230", "MU"); //
  157. put("231", "LR"); //
  158. put("232", "SL"); //
  159. put("233", "GH");
  160. put("234", "NG"); // Nigeria
  161. put("235", "TD");
  162. put("236", "CF");
  163. put("237", "CM");
  164. put("238", "CV"); // Cape Verde
  165. put("239", "ST");
  166. put("240", "GQ");
  167. put("241", "GA");
  168. put("242", "CG");
  169. put("243", "CD"); // The Democratic Republic Of Congo
  170. put("244", "AO"); // Angola
  171. put("245", "GW");
  172. put("246", "IO"); // British Indian Ocean Territory
  173. put("247", "AC");
  174. put("248", "SC");
  175. put("249", "SD");
  176. put("250", "RW");
  177. put("251", "ET"); //
  178. put("252", "SO"); // Somalia
  179. put("253", "DJ");
  180. put("254", "KE");
  181. put("255", "TZ");
  182. put("256", "UG");
  183. put("257", "BI");
  184. put("258", "MZ");
  185. put("260", "ZM");
  186. put("261", "MG"); //
  187. put("262", "RE"); // Reunion
  188. // TODO - YT (Mayotte) is also using "262"
  189. put("263", "ZW");
  190. put("264", "NA");
  191. put("265", "MW");
  192. put("266", "LS");
  193. put("267", "BW");
  194. put("268", "SZ");
  195. put("269", "KM");
  196. put("290", "SH"); // Saint Helena
  197. // TODO - TA (??) is also using "290"
  198. put("291", "ER"); // Eritrea
  199. put("297", "AW"); //
  200. put("298", "FO"); //
  201. put("299", "GL"); // Greenland
  202. put("350", "GI"); //
  203. put("351", "PT"); //
  204. put("352", "LU"); //
  205. put("353", "IE"); //
  206. put("354", "IS"); //
  207. put("355", "AL"); //
  208. put("356", "MT"); //
  209. put("357", "CY"); //
  210. put("358", "FI"); //
  211. // TODO - AX (Åland Islands) is also using "358"
  212. put("359", "BG"); //
  213. put("370", "LT"); // Lithuania
  214. put("371", "LV"); //
  215. put("372", "EE"); // Estonia
  216. put("373", "MD"); //
  217. put("374", "AM"); //
  218. put("375", "BY"); // Belarus
  219. put("376", "AD"); //
  220. put("377", "MC"); //
  221. put("378", "SM"); //
  222. put("379", "VA"); // Vatican
  223. put("380", "UA"); //
  224. put("381", "RS"); //
  225. put("382", "ME"); // Montenegro
  226. put("383", "XK"); // Kosovo
  227. put("385", "HR"); //
  228. put("386", "SI"); //
  229. put("387", "BA"); //
  230. put("388", "EU"); // Eurosat (added on 05/22/18)
  231. put("389", "MK"); //
  232. put("420", "CZ"); //
  233. put("421", "SK"); //
  234. put("423", "LI"); // Liechtenstein
  235. put("500", "FK"); // Falkland Islands
  236. put("501", "BZ"); //
  237. put("502", "GT"); //
  238. put("503", "SV"); //
  239. put("504", "HN"); //
  240. put("505", "NI"); //
  241. put("506", "CR"); //
  242. put("507", "PA"); //
  243. put("508", "PM"); //
  244. put("509", "HT"); //
  245. put("590", "GP"); // Guadeloupe
  246. // TODO - BL (Saint Barthélemy) AND MF (Saint Martin) are also using "590"
  247. put("591", "BO"); // Bolivia
  248. put("592", "GY"); //
  249. put("593", "EC"); //
  250. put("594", "GF"); //
  251. put("595", "PY"); //
  252. put("596", "MQ"); //
  253. put("597", "SR"); // Suriname
  254. put("598", "UY"); //
  255. put("599", "CW"); // Curaçao
  256. // TODO - BQ (Bonaire, Sint Eustatius and Saba) is also using "599"
  257. put("670", "TL"); //
  258. put("672", "NF"); //
  259. put("673", "BN"); //
  260. put("674", "NR"); //
  261. put("675", "PG"); //
  262. put("676", "TO"); //
  263. put("677", "SB"); //
  264. put("678", "VU"); //
  265. put("679", "FJ"); //
  266. put("680", "PW"); // Palau
  267. put("681", "WF"); //
  268. put("682", "CK"); // Cook Islands
  269. put("683", "NU"); //
  270. put("684", "AS"); // Samoa Eastern (added on 05/22/18)
  271. put("685", "WS"); //
  272. put("686", "KI"); //
  273. put("687", "NC"); //
  274. put("688", "TV"); // Tuvalu
  275. put("689", "PF"); //
  276. put("690", "TK"); //
  277. put("691", "FM"); //
  278. put("692", "MH"); //
  279. put("800", "001"); // ??
  280. put("808", "001"); // ??
  281. put("850", "KP"); //
  282. put("852", "HK"); // Hong Kong
  283. put("853", "MO"); // Macao
  284. put("855", "KH"); // Cambodia
  285. put("856", "LA"); // Laos
  286. put("870", "001"); // ??
  287. put("878", "001"); // ??
  288. put("880", "BD"); // Bangladesh
  289. put("881", "001"); // ??
  290. put("882", "001"); // ??
  291. put("883", "001"); // ??
  292. put("886", "TW"); //
  293. put("888", "001"); // ??
  294. put("960", "MV"); // Maldives
  295. put("961", "LB"); // Lebanon
  296. put("962", "JO"); //
  297. put("963", "SY"); //
  298. put("964", "IQ"); // Iraq
  299. put("965", "KW"); //
  300. put("966", "SA"); //
  301. put("967", "YE"); //
  302. put("968", "OM"); //
  303. put("970", "PS"); //
  304. put("971", "AE"); //
  305. put("972", "IL"); //
  306. put("973", "BH"); // Bahrain
  307. put("974", "QA"); //
  308. put("975", "BT"); // Bhutan
  309. put("976", "MN"); // Mongolia
  310. put("977", "NP"); // Nepal
  311. put("979", "001"); // ??
  312. put("991", "ITPCS"); // ITPCS (added on 05/22/18)
  313. put("992", "TJ"); //
  314. put("993", "TM"); // Turkmenistan
  315. put("994", "AZ"); //
  316. put("995", "GE"); // Georgia
  317. put("996", "KG"); //
  318. put("998", "UZ"); // Uzbekistan
  319.  
  320. // ====== 6 DIGITS ======
  321. put("441481", "GG"); // Guernsey
  322. put("441624", "IM"); // Isle Of Man
  323. put("441534", "JE"); // Jersey
  324. }};
  325. }
  326.  
  327. public static boolean isValidCountryCode(String code) {
  328. // return usRegionCodeToIsoCountryMap.containsKey(code)
  329. // || canadaRegionCodeToIsoCountryMap.containsKey(code)
  330. // || otherNorthAMRegionCodeToIsoCountryMap.containsKey(code)
  331. // || othersRegionCodeToIsoCountryMap.containsKey(code);
  332. return code.startsWith("1")
  333. || canadaRegionCodeToIsoCountryMap.containsKey(code)
  334. || otherNorthAMRegionCodeToIsoCountryMap.containsKey(code)
  335. || othersRegionCodeToIsoCountryMap.containsKey(code);
  336. }
  337.  
  338. public static Map<String, String> getUSIsoCountryNameMap() {
  339. return usRegionCodeToIsoCountryMap;
  340. }
  341.  
  342. public static Map<String, String> getCanadaIsoCountryNameMap() {
  343. return canadaRegionCodeToIsoCountryMap;
  344. }
  345.  
  346. public static Map<String, String> getOtherNorthAMIsoCountryNameMap() {
  347. return otherNorthAMRegionCodeToIsoCountryMap;
  348. }
  349.  
  350. public static Map<String, String> getOthersIsoCountryNameMap() {
  351. return othersRegionCodeToIsoCountryMap;
  352. }
  353. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement