Advertisement
jaVer404

level19.lesson03.task05(half_done & not_tested)

Feb 17th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. package com.javarush.test.level19.lesson03.task05;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. /* Закрепляем адаптер
  7. Адаптировать Customer и Contact к RowItem.
  8. Классом-адаптером является DataAdapter.
  9. Инициализируйте countries перед началом выполнения программы.
  10.  
  11. Соответствие кода страны и названия:
  12. UA Ukraine
  13. RU Russia
  14. CA Canada
  15. */
  16.  
  17. public class Solution {
  18.     private static Map<String,String> countries = new HashMap<String,String>();
  19.     static
  20.     {
  21.         countries.put("UA", "Ukraine");
  22.         countries.put("RU", "Russia");
  23.         countries.put("CA", "Canada");
  24.     }
  25.  
  26.     public static class DataAdapter implements RowItem{
  27.         private Customer customer;
  28.         private Contact contact;
  29.  
  30.         public DataAdapter(Customer customer, Contact contact)
  31.         {
  32.             this.customer = customer;
  33.             this.contact = contact;
  34.         }
  35.  
  36.         @Override
  37.         public String getCountryCode()
  38.         {
  39.             String counryName = customer.getCountryName();
  40.             String countryCode=null;
  41.             for (Map.Entry<String,String> entry : countries.entrySet())
  42.             {
  43.                 countryCode=entry.getKey();
  44.             }
  45.             return countryCode;
  46.         }
  47.  
  48.         @Override
  49.         public String getCompany()
  50.         {
  51.             return customer.getCompanyName();
  52.         }
  53.  
  54.         @Override
  55.         public String getContactFirstName()
  56.         {
  57.             return (contact.getName()).substring((contact.getName()).indexOf(", "));
  58.         }
  59.  
  60.         @Override
  61.         public String getContactLastName()
  62.         {
  63.             return null;
  64.         }
  65.  
  66.         @Override
  67.         public String getDialString()
  68.         {
  69.             return null;
  70.         }
  71.     }
  72.  
  73.     public static interface RowItem {
  74.         String getCountryCode();        //example UA
  75.         String getCompany();            //example JavaRush Ltd.
  76.         String getContactFirstName();   //example Ivan
  77.         String getContactLastName();    //example Ivanov
  78.         String getDialString();         //example callto://+380501234567
  79.     }
  80.  
  81.     public static interface Customer {
  82.         String getCompanyName();        //example JavaRush Ltd.
  83.         String getCountryName();        //example Ukraine
  84.     }
  85.  
  86.     public static interface Contact {
  87.         String getName();               //example Ivanov, Ivan
  88.         String getPhoneNumber();        //example +38(050)123-45-67
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement