Im trying to make the solution appropriate for validator but I have no idea how to achieve it. I tested transformation of string data used in implemented methods and everything seems to be ok.
Please, help.
package com.codegym.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
Reinforce the adapter
ąąąąą
*/
public class Solution {
public static Map<String,String> countries = new HashMap<>();
static {
countries.put("UA","Ukraine");
countries.put("US","United States");
countries.put("FR","France");
}
public static void main(String[] args) {
/*String s = "Peterson, John";
System.out.println(s.substring(s.indexOf(" ") + 1));
System.out.println(s.substring(0, s.indexOf(",")));
StringBuilder s = new StringBuilder();
String phone = "+1(111)222-3333";
s.append("callto://+");
for (int i = 0; i <phone.length() ; i++) {
if ( "1234567890".indexOf(phone.substring(i, i+1)) > -1) {
s.append(phone.substring(i, i+1));
}
}
System.out.println(s.toString());*/
}
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 getCountryCode() {
for (Map.Entry<String, String> e: countries.entrySet()) {
if (e.getValue().equals(this.customer.getCountryName())){
return e.getKey();
}
}
return null;
}
@Override
public String getCompany() {
return countries.get(this.customer.getCompanyName());
}
@Override
public String getContactFirstName() {
return this.contact.getName().substring(this.contact.getName().indexOf(" ") + 1);
}
@Override
public String getContactLastName() {
return this.contact.getName().substring(0, this.contact.getName().indexOf(","));
}
@Override
public String getDialString() {
StringBuilder s = new StringBuilder();
s.append("callto://+");
for (int i = 0; i <this.contact.getPhoneNumber().length() ; i++) {
if ( "1234567890".indexOf(this.contact.getPhoneNumber().substring(i, i+1)) > -1) {
s.append(this.contact.getPhoneNumber().substring(i, i+1));
}
}
return s.toString();
}
}
public static interface RowItem {
String getCountryCode(); // For example: US
String getCompany(); // For example: CodeGym Ltd.
String getContactFirstName(); // For example: John
String getContactLastName(); // For example: Peterson
String getDialString(); // For example: callto://+11112223333
}
public static interface Customer {
String getCompanyName(); // For example: CodeGym Ltd.
String getCountryName(); // For example: United States
}
public static interface Contact {
String getName(); // For example: Peterson, John
String getPhoneNumber(); // For example: +1(111)222-3333, +3(805)0123-4567, +380(50)123-4567, etc.
}
}