Пример #1
0
 public static PhoneNumber clone(PhoneNumber phoneNumber) {
   if (phoneNumber == null) return null;
   PhoneNumber clone = create();
   clone.setId(ObjectUtil.clone(phoneNumber.getId()));
   clone.setArea(ObjectUtil.clone(phoneNumber.getArea()));
   clone.setNumber(ObjectUtil.clone(phoneNumber.getNumber()));
   clone.setExtension(ObjectUtil.clone(phoneNumber.getExtension()));
   clone.setCountry(phoneNumber.getCountry());
   clone.setType(phoneNumber.getType());
   clone.setValue(ObjectUtil.clone(phoneNumber.getValue()));
   return clone;
 }
Пример #2
0
 public static PhoneNumber toPhoneNumber(String text) {
   if (text == null || text.length() == 0) return null;
   text = text.replaceAll("\\(", "");
   text = text.replaceAll("\\)", "");
   text = text.replaceAll("-", "");
   text = text.replaceAll("x", "");
   text = text.replaceAll(" ", "");
   text = text.replaceAll("[a-z]", "");
   text = text.replaceAll("[A-Z]", "");
   if (text.length() < 10) {
     throw new RuntimeException("Unexpected value for PhoneNumber: " + text);
   }
   PhoneNumber phoneNumber = new PhoneNumber();
   // TODO externalize this:
   phoneNumber.setCountry(Country.USA);
   if (text.length() >= 3) phoneNumber.setArea(text.substring(0, 3));
   if (text.length() >= 10) phoneNumber.setNumber(text.substring(3, 10));
   else if (text.length() >= 3) phoneNumber.setNumber(text.substring(3));
   if (text.length() > 10) phoneNumber.setExtension(text.substring(10));
   return phoneNumber;
 }