Package proseccoCoding.TLN.model
Class APIHandler
java.lang.Object
proseccoCoding.TLN.model.APIHandler
This class allows to interact with the TrustedListAPI and retrieve data from it.
This class contains two methods for the API calls and others static methods
used to mold the data and create Objects with the required specifications.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static org.json.JSONArray
JSONArray that contains JSONObjects with all the information about each countryprivate static org.json.JSONArray
JSONArray that contains JSONObjects with the country names and codes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Initializer method for variable countriesData.static void
Initializer method for variable countriesNames.Private method that reads from local file the service types data and return an HashMap containing entries with service type codes as keys and service type names as values.Static method that returns an HashMap containing entries with country codes as keys and Country objects as values.Static method that returns an ArrayList of Strings containing the names of the EU countriesstatic Country
retriveCountryData
(String countryCode) Static method that parses countryData and extracts the data to create a Country objectStatic method that parses countryData and extracts all service types from all countries
-
Field Details
-
countriesNames
private static org.json.JSONArray countriesNamesJSONArray that contains JSONObjects with the country names and codes -
countriesData
private static org.json.JSONArray countriesDataJSONArray that contains JSONObjects with all the information about each country
-
-
Constructor Details
-
APIHandler
public APIHandler()
-
-
Method Details
-
initCountriesNames
Initializer method for variable countriesNames. It initializes countriesNames with countries codes and full names- Throws:
Exception
-
initCountriesData
public static void initCountriesData()Initializer method for variable countriesData. It initializes countriesData with all the information about each country -
retrieveCountriesNames
Static method that returns an ArrayList of Strings containing the names of the EU countries- Returns:
- ArrayList with all the names of the countries
-
retrieveCountries
Static method that returns an HashMap containing entries with country codes as keys and Country objects as values.- Returns:
- HashMap containing entries with country codes as keys and Country objects (without complete data) as values
-
readFromFile
Private method that reads from local file the service types data and return an HashMap containing entries with service type codes as keys and service type names as values.- Returns:
- HashMap containing entries with service type codes as keys and service type names as values
-
retriveServiceTypes
Static method that parses countryData and extracts all service types from all countries- Returns:
- ArrayList of Pair<String, String> composed of a service type code as first value and a service type full name as second value
-
retriveCountryData
Static method that parses countryData and extracts the data to create a Country object- Parameters:
countryCode
- The code that identifies each country- Returns:
- the Country object just created
- Throws:
IllegalArgumentException
- in case of null parameter
-