Beispiel #1
0
 public static String toPhoneNumberString(PhoneNumber phoneNumber) {
   if (phoneNumber == null) return null;
   StringBuffer buf = new StringBuffer();
   if (phoneNumber.getArea() != null) buf.append("(" + phoneNumber.getArea() + ") ");
   if (phoneNumber.getNumber() != null) {
     buf.append(phoneNumber.getNumber().substring(0, 3) + "-");
     buf.append(phoneNumber.getNumber().substring(3, 7));
     if (phoneNumber.getExtension() != null) buf.append(" " + phoneNumber.getExtension());
   }
   return buf.toString();
 }
Beispiel #2
0
 public static boolean validate(PhoneNumber phoneNumber) {
   if (phoneNumber == null) return false;
   Validator validator = Validator.getValidator();
   validator.notEmpty(phoneNumber.getArea(), "\"Area\" must be specified");
   validator.notNull(phoneNumber.getCountry(), "\"Country\" must be specified");
   validator.notEmpty(phoneNumber.getNumber(), "\"Number\" must be specified");
   validator.notNull(phoneNumber.getType(), "\"Type\" must be specified");
   validator.notNull(
       phoneNumber.getArea().length() != 3,
       "\"Area\" must have length 3: " + phoneNumber.getArea());
   validator.notNull(
       phoneNumber.getNumber().length() != 7,
       "\"Number\" must have length 7: " + phoneNumber.getNumber());
   boolean isValid = validator.isValid();
   return isValid;
 }
Beispiel #3
0
 public static String toString(PhoneNumber phoneNumber) {
   if (phoneNumber == null) return "";
   if (isEmpty(phoneNumber)) return "";
   // String text = phoneNumber.toString();
   String area = phoneNumber.getArea();
   String number = phoneNumber.getNumber();
   String text = "(" + area + ") " + number.substring(0, 3) + "-" + number.substring(3);
   return text;
 }
Beispiel #4
0
 public static boolean isEmpty(PhoneNumber phoneNumber) {
   if (phoneNumber == null) return true;
   boolean status = false;
   status |= StringUtils.isEmpty(phoneNumber.getArea());
   status |= StringUtils.isEmpty(phoneNumber.getNumber());
   status |= phoneNumber.getCountry() != Country.USA;
   status |= phoneNumber.getType() != PhoneLocation.HOME;
   return status;
 }
Beispiel #5
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;
 }