Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. package com.javarush.task.task19.task1905;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. /*
  7. Закрепляем адаптер
  8. */
  9.  
  10. public class Solution
  11. {
  12. public static Map<String, String> countries = new HashMap<String, String> ( );
  13.  
  14. static
  15. {
  16. countries.put ("UA", "Ukraine");
  17. countries.put ("RU", "Russia");
  18. countries.put ("CA", "Canada");
  19. }
  20.  
  21. public static void main(String[] args)
  22. {
  23. }
  24. public static class DataAdapter implements RowItem
  25. {
  26. private Customer customer;
  27. private Contact contact;
  28.  
  29. public DataAdapter(Customer customer, Contact contact)
  30. {
  31. this.customer = customer;
  32. this.contact = contact;
  33. }
  34.  
  35. @Override
  36. public String getCountryCode()
  37. {
  38. String name=customer.getCountryName();
  39. String code=null;
  40. for(Map.Entry<String, String> pair:countries.entrySet ())
  41. {
  42. if(name.equals ( pair.getValue ()))
  43. {
  44. code=pair.getKey ();
  45. break;
  46. }
  47. }
  48. return code;
  49. }
  50. @Override
  51. public String getCompany()
  52. {
  53. return customer.getCompanyName ( );
  54. }
  55. @Override
  56. public String getContactFirstName()
  57. {
  58. return contact.getName().split(", ")[1];
  59. }
  60. @Override
  61. public String getContactLastName()
  62. {
  63. return contact.getName().split(", ")[0];
  64. }
  65. @Override
  66. public String getDialString()
  67. {
  68. return "callto://+"+contact.getPhoneNumber ( ).replaceAll("[^0-9]", "");
  69. }
  70. }
  71. public static interface RowItem
  72. {
  73. String getCountryCode(); //example UA
  74.  
  75. String getCompany(); //example JavaRush Ltd.
  76.  
  77. String getContactFirstName(); //example Ivan
  78.  
  79. String getContactLastName(); //example Ivanov
  80.  
  81. String getDialString(); //example callto://+380501234567
  82. }
  83.  
  84. public static interface Customer
  85. {
  86. String getCompanyName(); //example JavaRush Ltd.
  87.  
  88. String getCountryName(); //example Ukraine
  89. }
  90. public static interface Contact
  91. {
  92. String getName(); //example Ivanov, Ivan
  93.  
  94. String getPhoneNumber(); //example +38(050)123-45-67
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement