Class PhoneFormatterImpl
java.lang.Object
ch.tocco.nice2.toolbox.impl.phone.PhoneFormatterImpl
- All Implemented Interfaces:
PhoneFormatter
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionformatE164
(String number, @Nullable String defaultRegion) Tries to format a phone number in E.164 format.formatInternational
(String number, @Nullable String defaultRegion) Tries to format a phone number in (readable) international format.formatNational
(String number, @Nullable String defaultRegion) Tries to format a phone number in national format.
-
Constructor Details
-
PhoneFormatterImpl
public PhoneFormatterImpl()
-
-
Method Details
-
formatE164
Description copied from interface:PhoneFormatter
Tries to format a phone number in E.164 format. If not possible,Optional.empty()
is returned.- Specified by:
formatE164
in interfacePhoneFormatter
- Parameters:
number
- The phone number to format.defaultRegion
- The default region (i.e. "CH" for switzerland).- Returns:
- the formatted number or
Optional.empty()
, if it couldn't be formatted.
-
formatNational
Description copied from interface:PhoneFormatter
Tries to format a phone number in national format. If not possible,Optional.empty()
is returned. If country does not match param defaultRegion, international format is applied.- Specified by:
formatNational
in interfacePhoneFormatter
- Parameters:
number
- The phone number to format.defaultRegion
- The default region (i.e. "CH" for switzerland).- Returns:
- the formatted number or
Optional.empty()
, if it couldn't be formatted.
-
formatInternational
public Optional<String> formatInternational(String number, @Nullable @Nullable String defaultRegion) Description copied from interface:PhoneFormatter
Tries to format a phone number in (readable) international format. If not possible,Optional.empty()
is returned. You most probably want to use this format if it should be printed in any output or UI.- Specified by:
formatInternational
in interfacePhoneFormatter
- Parameters:
number
- The phone number to format.- Returns:
- the formatted number or
Optional.empty()
, if it couldn't be formatted.
-