Валидатор ругаеться на "Метод getCountryCode() должен вернуть страну из countries, по значению getCountryName() объекта customer."
Либо же каким образом сделать перебор и проверку значений в этом методе.
package com.javarush.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
Закрепляем адаптер
*/
public class Solution {
public static Map<String, String> countries = new HashMap<>();
static {
countries.put("UA", "Ukraine");
countries.put("RU", "Russia");
countries.put("CA", "Canada");
}
public static void main(String[] args) {
}
public static class DataAdapter implements RowItem{
private Customer customer;
private Contact contact;
public DataAdapter(Customer customer, Contact contact) {
this.contact = contact;
this.customer = customer;
}
@Override
public String getCountryCode() {
for (Map.Entry<String, String> entry : countries.entrySet()) {
if (customer.getCountryName().equals(entry.getValue())) return entry.getKey();
if (customer.getCountryName().equals(entry.getValue())) return entry.getKey();
else return entry.getKey();
}
return "";
}
@Override
public String getCompany() {
return customer.getCompanyName();
}
@Override
public String getContactFirstName() {
String name[] = contact.getName().split(" ");
return name[1];
}
@Override
public String getContactLastName() {
String name[] = contact.getName().split(",");
return name[0];
}
@Override
public String getDialString() {
String ansver = contact.getPhoneNumber();
String s= "\\W";
String my = ansver.replaceAll(s,"");
return my;
}
}
public static interface RowItem {
String getCountryCode(); //example UA
String getCompany(); //example JavaRush Ltd.
String getContactFirstName(); //example Ivan
String getContactLastName(); //example Ivanov
String getDialString(); //example callto://+380501234567
}
public static interface Customer {
String getCompanyName(); //example JavaRush Ltd.
String getCountryName(); //example Ukraine
}
public static interface Contact {
String getName(); //example Ivanov, Ivan
String getPhoneNumber(); //example +38(050)123-45-67 or +3(805)0123-4567 or +380(50)123-4567 or ...
}
}