//that I may be delivered from those who are disobedient in Judea, and that my service which I have for Jerusalem may be acceptable to the saints (Romans 15:31)
package com.javarush.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
ÐакÑеплÑем адапÑеÑ
*/
public class Solution {
public static Map 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.customer = customer;
this.contact = contact;
}
@Override
public String getCompany()
{
return customer.getCompanyName();
}
@Override
public String getContactFirstName()
{
return contact.getName().split(", ")[1];
}
@Override
public String getContactLastName()
{
return contact.getName().split(", ")[0];
}
@Override
public String getCountryCode()
{
String s = "";
for (Map.Entry pair : countries.entrySet()){
if (pair.getValue().equals(customer.getCountryName())) s = pair.getKey();
}
return s;
}
@Override
public String getDialString()
{
String phone = "callto://" + contact.getPhoneNumber().replaceAll("[()-]","");
return phone;
}
}
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
}
}
/*
ÐакÑеплÑем адапÑеÑ
ÐдапÑиÑоваÑÑ Customer и Contact к RowItem.
ÐлаÑÑом-адапÑеÑом ÑвлÑеÑÑÑ DataAdapter.
ÐниÑиализиÑÑйÑе countries пеÑед наÑалом вÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð¿ÑогÑаммÑ. СооÑвеÑÑÑвие кода ÑÑÑÐ°Ð½Ñ Ð¸ названиÑ:
UA Ukraine
RU Russia
CA Canada
ТÑебованиÑ:
1.âÐлаÑÑ Solution должен ÑодеÑжаÑÑ public static поле countries Ñипа Map.
2.âÐ ÑÑаÑиÑеÑком блоке клаÑÑа Solution иниÑиализиÑÑй поле countries ÑеÑÑовÑми даннÑми ÑоглаÑно заданиÑ.
3.âÐлаÑÑ Solution должен ÑодеÑжаÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ RowItem.
4.âÐлаÑÑ Solution должен ÑодеÑжаÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ Contact.
5.âÐлаÑÑ Solution должен ÑодеÑжаÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ Customer.
6.âÐлаÑÑ DataAdapter должен ÑеализовÑваÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ RowItem.
7.âÐлаÑÑ DataAdapter должен ÑодеÑжаÑÑ Ð´Ð²Ð° пÑиваÑнÑÑ
полÑ: customer Ñипа Customer и contact Contact.
8.âÐлаÑÑ DataAdapter должен ÑодеÑжаÑÑ ÐºÐ¾Ð½ÑÑÑÑкÑÐ¾Ñ Ñ Ð¿Ð°ÑамеÑÑами (Customer customer, Contact contact), коÑоÑÑй иниÑиализиÑÑÐµÑ Ð¿Ð¾Ð»Ñ contact и customer.
9.âРклаÑÑе DataAdapter ÑеализÑй меÑÐ¾Ð´Ñ Ð¸Ð½ÑеÑÑейÑа RowItem иÑполÑзÑÑ Ð¿Ð¾Ð´Ñказки в виде комменÑаÑиев в инÑеÑÑейÑаÑ
.
package com.javarush.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
*
ÐакÑеплÑем адапÑеÑ
*
public class Solution {
public static Map countries = new HashMap();
public static void main(String[] args) {
}
public static class DataAdapter {
public DataAdapter(Customer customer, Contact contact) {
}
}
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
}
}
*/