Пример #1
0
  private Countries(List<Country> countries, Context context) {
    this.countries = countries;
    this.appContext = context.getApplicationContext();

    for (Country country : countries) {
      isoCountriesMap.put(country.getIsoCode().toLowerCase(Locale.US), country);
    }

    updateDisplayCountyNamesIfNeeded();
  }
Пример #2
0
  private void updateDisplayCountyNamesIfNeeded() {
    String newLanguage = appContext.getResources().getConfiguration().locale.getLanguage();
    if (TextUtils.equals(newLanguage, language)) {
      return;
    }

    language = newLanguage;
    displayCountryNames.clear();
    for (Country country : countries) {
      String name = new Locale(language, country.getIsoCode()).getDisplayCountry();
      displayCountryNames.put(country.getIsoCode(), name);
    }

    Collections.sort(countries, countryComparator);
  }
  public static void main(String[] args) throws Exception {
    try {
      DBSession dbs = new DBSession("PURIDIOM");
      CountryRetrieveById test = new CountryRetrieveById();
      Map incomingRequest = new HashMap();

      incomingRequest.put("dbsession", dbs);
      incomingRequest.put("organizationId", "PURIDIOM");
      incomingRequest.put("userId", "SYSADM");

      System.out.println("Database Status: " + dbs.getStatus());

      Country country = (Country) test.executeTask(incomingRequest);

      System.out.println("Country: " + country.toString());
      System.out.println("CountryRetrieveByIdTest COMPLETE");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #4
0
  public static void list() {
    Collection<Country> countries = Country.findActiveCountries();

    Collection<CountryDTO> countriesDto = new ArrayList<CountryDTO>();
    for (Country country : countries) {
      countriesDto.add(new CountryDTO(country));
    }

    ApiResponse response = new ApiResponse();
    response.setStatus(Http.StatusCode.OK);
    response.setTotal(String.valueOf(countries.size()));
    response.put("countries", countriesDto);
    renderJSON(response.json);
  }
Пример #5
0
 public String getDisplayCountryName(Country country) {
   updateDisplayCountyNamesIfNeeded();
   return displayCountryNames.get(country.getIsoCode());
 }
Пример #6
0
 @Override
 public int compare(Country country1, Country country2) {
   String lhsName = displayCountryNames.get(country1.getIsoCode());
   String rhsName = displayCountryNames.get(country2.getIsoCode());
   return lhsName.compareTo(rhsName);
 }
Пример #7
0
 private static int getCountryResId(Context context, Country country) {
   return getMipmapResId(context, country.getIsoCode().toLowerCase(Locale.ENGLISH) + "_flag");
 }
Пример #8
0
  @Test
  public void testPermutations() {
    //        Permutations perm = new Permutations();
    //        List<Character> inputList = new ArrayList<Character>();
    //        inputList.add('v');
    //        inputList.add('a');
    //        inputList.add('e');
    //        inputList.add('y');
    //        perm.printPermutations(inputList);

    try {
      Integer iObj = Integer.parseInt("9999");
    } catch (NumberFormatException nfe) {

    }

    Country indiaCountry = new Country(1, "India");
    Country indiaCountry2 = new Country(1, "India");
    Country chinaCountry = new Country(3, "USA");
    Country nepalCountry = new Country(4, "Russia");
    Country bhutanCountry = new Country(2, "Japan");

    List<Country> listOfCountries = new ArrayList<Country>();
    listOfCountries.add(indiaCountry);
    listOfCountries.add(indiaCountry2);
    listOfCountries.add(chinaCountry);
    listOfCountries.add(nepalCountry);
    listOfCountries.add(bhutanCountry);

    System.out.println("Before Sort by id : ");
    for (int i = 0; i < listOfCountries.size(); i++) {
      Country country = (Country) listOfCountries.get(i);
      System.out.println(
          "Country Id: "
              + country.getCountryId()
              + "||"
              + "Country name: "
              + country.getCountryName());
    }

    Set<Country> countrySet =
        new TreeSet<>(
            (country1, country2) ->
                (country1.getCountryId() < country2.getCountryId())
                    ? -1
                    : ((country1.getCountryId() > country2.getCountryId()) ? 1 : 0));
    countrySet.addAll(listOfCountries);
    List<Country> sortedCountries = new ArrayList<>(countrySet);
    for (int i = 0; i < sortedCountries.size(); i++) {
      Country country = (Country) sortedCountries.get(i);
      System.out.println(
          "Country Id: "
              + country.getCountryId()
              + "|| "
              + "Country name: "
              + country.getCountryName());
    }

    Collections.sort(
        listOfCountries,
        (country1, country2) ->
            (country1.getCountryId() < country2.getCountryId())
                ? -1
                : (country1.getCountryId() > country2.getCountryId()) ? 1 : 0);

    System.out.println("After Sort by id: ");
    for (int i = 0; i < listOfCountries.size(); i++) {
      Country country = (Country) listOfCountries.get(i);
      System.out.println(
          "Country Id: "
              + country.getCountryId()
              + "|| "
              + "Country name: "
              + country.getCountryName());
    }

    // Sort by countryName
    Collections.sort(
        listOfCountries,
        new Comparator<Country>() {

          @Override
          public int compare(Country o1, Country o2) {
            return o1.getCountryName().compareTo(o2.getCountryName());
          }
        });

    System.out.println("After Sort by name: ");
    for (int i = 0; i < listOfCountries.size(); i++) {
      Country country = (Country) listOfCountries.get(i);
      System.out.println(
          "Country Id: "
              + country.getCountryId()
              + "|| "
              + "Country name: "
              + country.getCountryName());
    }
  }