What can be wrong with the contructor?
Probably the last condition is not met due to the country code.
package pl.codegym.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
Wzmocnij adapter
*/
public class Solution {
public static Map<String, String> countries = new HashMap<>();
static {
countries.put("UA","Ukraina");
countries.put("US","Stany Zjednoczone");
countries.put("FR","Francja");
}
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.customer = customer;
this.contact = contact;
}
String[] contactNames = contact.getName().split(", ");
@Override
public String getCountryCode() {
for (Map.Entry<String, String> para : countries.entrySet()) {
if (para.getValue().equals(customer.getCountryName())) {
return para.getKey();
}
}
return null;
}
@Override
public String getCompany() {
return customer.getCompanyName();
}
@Override
public String getContactFirstName() {
return contactNames[1];
}
@Override
public String getContactLastName() {
return contactNames[0];
}
@Override
public String getDialString() {
String dialString = "callto://+";
char[] dialCharArray = contact.getPhoneNumber().toCharArray();
for (char d : dialCharArray) {
if (d == '0' || d == '1' || d == '2' || d == '3' || d == '4' ||
d == '5' || d == '6' || d == '7' || d == '8' || d == '9') {
dialString += d;
}
}
return dialString;
}
}
public static interface RowItem {
String getCountryCode(); // Na przykład: US
String getCompany(); // Na przykład: CodeGym Ltd.
String getContactFirstName(); // Na przykład: John
String getContactLastName(); // Na przykład: Peterson
String getDialString(); // Na przykład: callto://+11112223333
}
public static interface Customer {
String getCompanyName(); // Na przykład: CodeGym Ltd.
String getCountryName(); // Na przykład: Stany Zjednoczone
}
public static interface Contact {
String getName(); // Na przykład: Peterson, John
String getPhoneNumber(); // Na przykład: +1(111)222-3333, +3(805)0123-4567, +380(50)123-4567, etc.
}
}