Метод getCountryCode() должен вернуть страну из countries, по значению getCountryName() объекта customer.
проверял в мейне все выводит правильно.
Поиск страны у меня с 91-99 строку.
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<String,String>();
static{
countries.put("UA","Ukraine");
countries.put("RU","Russia");
countries.put("CA","Canada");
}
public static void main(String[] args) {
// String w=null;
// for (String entry:countries.values()){
// if (entry.equals("Ukraine")){
// w=entry;
// }
//
// }System.out.println(w);
//
// Contact contact=new Contact() {
// @Override
// public String getName() {
// return "Ivanov, Ivan";
// }
//
// @Override
// public String getPhoneNumber() {
// return "+38(050)123-45-67 or +3(805)0123-4567 or +380(50)123-4567 or ...";
// }
// };
// Customer customer=new Customer() {
//
// @Override
// public String getCompanyName() {
// return "JavaRush Ltd.";
// }
//
// @Override
// public String getCountryName() {
//
// return "Ukraine";
// }
//};
}
public static class DataAdapter implements RowItem{
private Customer customer;
private Contact contact;
public DataAdapter(Customer customer, Contact contact) {
this.customer=customer;
this.contact=contact;
}
@Override
public String getDialString() {
String[]q=this.contact.getPhoneNumber().split("\\s");
String ad = null;
for (int i=0;i<q.length;i++){
if (q[i].equals("+" + "(3|8)\\d{2}" + "(" + "\\d{3}" + ")" + "-" + "\\d{2}" + "-" + "\\d{2}")) {
ad = q[i];
} else break;
}return "callto:"+ad;
}
@Override
public String getContactLastName() {
String[]qw=this.contact.getName().split(", ",2);
return qw[0];
}
@Override
public String getContactFirstName() {
String[]as=this.contact.getName().split(", ",2);
return as[1];
}
@Override
public String getCompany() {
return this.customer.getCompanyName();
}
@Override
public String getCountryCode() {
String w=null;
for (String entry:countries.values()){
if (entry.equals(this.customer.getCountryName())){
w=entry;
}
}
return w;
}
}
public static interface RowItem {
String getCountryCode(); //For example: UA
String getCompany(); //For example: JavaRush Ltd.
String getContactFirstName(); //For example: Ivan
String getContactLastName(); //For example: Ivanov
String getDialString(); //For example: callto://+380501234567
}
public static interface Customer {
String getCompanyName(); //For example: JavaRush Ltd.
String getCountryName(); //For example: Ukraine
}
public static interface Contact {
String getName(); //For example: Ivanov, Ivan
String getPhoneNumber(); //For example: +38(050)123-45-67 or +3(805)0123-4567 or +380(50)123-4567 or ...
}
}