Guest User

Untitled

a guest
Dec 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. private static final Set<Integer> PHONENUMBER_ONEDIGITCOUNTRYCODES = new Set<Integer>
  2. {
  3. 1, 7
  4. };
  5. private static final Set<Integer> PHONENUMBER_THREEDIGITCOUNTRYCODES = new Set<Integer>
  6. {
  7. 35, 37, 38, 42, 99, 21, 22, 23, 24, 25, 26, 29, 35, 37, 38, 42, 50, 59, 67, 68, 69, 85, 88, 96, 97, 9
  8. };
  9.  
  10.  
  11. global virtual class PhoneNumber implements xa.xType.xTypeInfo
  12. {
  13.  
  14. public Integer countryCode { get; set; }
  15. public Integer areaCode { get; set; }
  16. public Long localNumber { get; set; }
  17.  
  18.  
  19. global PhoneNumber(String rawPhoneNumber)
  20. {
  21. if (rawPhoneNumber != null && rawPhoneNumber.length() > 0)
  22. {
  23. String str = rawPhoneNumber.replaceAll('([+-])', '').replaceAll(' ', '')
  24. .replaceAll('\(', '')
  25. .replaceAll('\)', '');
  26. if (str.length() == 11)
  27. {
  28. if (PHONENUMBER_ONEDIGITCOUNTRYCODES.contains(Integer.valueOf(str.substring(0, 1))))
  29. {
  30.  
  31. this(Integer.valueOf(str.substring(0, 1)),
  32. Integer.valueOf(str.substring(1, 4)),
  33. Integer.valueOf(str.substring(4)));
  34. }
  35. else if (PHONENUMBER_THREEDIGITCOUNTRYCODES.contains(Integer.valueOf(str.substring(0, 2))))
  36. {
  37.  
  38. this(Integer.valueOf(str.substring(0, 3))
  39. , Integer.valueOf(str.substring(3, 6))
  40. , Integer.valueOf(str.substring(6)));
  41. }
  42. else
  43. {
  44.  
  45. this(Integer.valueOf(str.substring(0, 2))
  46. , Integer.valueOf(str.substring(2, 4))
  47. , Integer.valueOf(str.substring(4)));
  48. }
  49. }
  50. else
  51. {
  52. localNumber = Long.valueOf(str);
  53. }
  54. }
  55. }
  56.  
  57. global PhoneNumber(Integer country, Integer area, Integer zone)
  58. {
  59. System.debug(country + ' ' + area + ' ' + zone);
  60. this.countryCode = country;
  61. this.areaCode = area;
  62. this.localNumber = zone;
  63. }
  64.  
  65. global override String toString()
  66. {
  67. return ((countryCode != null) ? '+' + String.valueOf(countryCode) : '')
  68. + ((areaCode != null) ? '(' + String.valueOf(areaCode) + ')' : '')
  69. + ((localNumber != null) ? String.valueOf(localNumber) : '');
  70. }
  71. }
Add Comment
Please, Sign In to add comment