рекомендации от ментора
Метод getContactFirstName() должен вернуть строку состоящую из имени (смотри примеры). Фамилию и имя нужно взять из метода getName() объекта сontact.
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>();
//2. В статическом блоке класса Solution инициализируй поле countries тестовыми данными согласно заданию.
//Инициализируйте countries перед началом выполнения программы. Соответствие кода страны и названия:
//UA Ukraine
//RU Russia
//CA Canada
static {
countries.put("UA","Ukraine");
countries.put("RU","Russia");
countries.put("CA","Canada");
}
public static void main(String[] args) {
}
//6. Класс DataAdapter должен реализовывать интерфейс RowItem.
public static class DataAdapter implements RowItem {
//7. Класс DataAdapter должен содержать два приватных поля: customer типа Customer и contact Contact.
private Customer customer;
private Contact contact;
//8. Класс DataAdapter должен содержать конструктор с параметрами (Customer customer, Contact contact), который инициализирует поля contact и customer.
public DataAdapter(Customer customer, Contact contact) {
this.customer = customer;
this.contact = contact;
}
//9. В классе DataAdapter реализуй методы интерфейса RowItem используя подсказки в виде комментариев в интерфейсах.
@Override
public String getCountryCode() {
return countries.entrySet().stream()
.filter(entry -> entry.getValue().equals(customer.getCountryName()))
.findFirst()
.get()
.getKey();
}
@Override
public String getCompany() {
return customer.getCompanyName();
}
@Override
public String getContactFirstName() {
int iIndex = contact.getName().indexOf(",");
return (iIndex < 0 ? null : contact.getName().substring(iIndex+1).trim());
}
@Override
public String getContactLastName() {
int iIndex = contact.getName().indexOf(",");
return (iIndex < 0 ? contact.getName() : contact.getName().substring(0,iIndex).trim());
}
@Override
public String getDialString() {
return ("callto://"+contact.getPhoneNumber().replaceAll("[()\\-]",""));
}
}
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 ...
}
}