com.mizar.usaddress
Class USPhoneNumber

java.lang.Object
  extended by com.mizar.usaddress.USPhoneNumber

public class USPhoneNumber
extends java.lang.Object

class that represents a phone number


Constructor Summary
USPhoneNumber()
          default constructor
USPhoneNumber(java.lang.String number)
          constructs the phone number with the provided value.
 
Method Summary
static java.lang.String formatPhoneNumber(java.lang.String sourceNumber)
          Format a string to a US standard phone number.
 java.lang.String getDigits()
          get the digits for the phone number
 java.lang.String getPhoneNumber()
          get the phone number formatted for display
 void setDigits(java.lang.String digits)
          set the digits for the phone number
 void setPhoneNumber(java.lang.String number)
          set the phone number regardless of format
static java.lang.String unformatPhoneNumber(java.lang.String formattedPhoneNumber)
          The method strips all non-numeric characters from the formattedPhoneNumber
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

USPhoneNumber

public USPhoneNumber()
default constructor


USPhoneNumber

public USPhoneNumber(java.lang.String number)
constructs the phone number with the provided value.

Parameters:
number - the phone number
Method Detail

getPhoneNumber

public java.lang.String getPhoneNumber()
get the phone number formatted for display

Returns:
the formatted phone number

setPhoneNumber

public void setPhoneNumber(java.lang.String number)
set the phone number regardless of format

Parameters:
number - the phone number in any format

getDigits

public java.lang.String getDigits()
get the digits for the phone number

Returns:
digits for the phone number

setDigits

public void setDigits(java.lang.String digits)
set the digits for the phone number

Parameters:
digits - digits that make up the phone number

formatPhoneNumber

public static java.lang.String formatPhoneNumber(java.lang.String sourceNumber)
Format a string to a US standard phone number. Any non-numeric characters are first removed and then the remaining numeric characters are formatted as follows depending on how many non-numeric characters are found.
  1. 999-9999
  2. (999) 999-999
  3. +1 (999) 999-999

Parameters:
justDigits - a string that will be stripped of any non-numeric characters prior to formatting.
Returns:
a formatted phone number

unformatPhoneNumber

public static java.lang.String unformatPhoneNumber(java.lang.String formattedPhoneNumber)
The method strips all non-numeric characters from the formattedPhoneNumber

Parameters:
formattedPhoneNumber - a phone number with formatting
Returns:
a string of just the numeric characters from the input formattedPhoneNumber