Class PhoneFormatterImpl

java.lang.Object
ch.tocco.nice2.toolbox.impl.phone.PhoneFormatterImpl
All Implemented Interfaces:
PhoneFormatter

@Component public class PhoneFormatterImpl extends Object implements PhoneFormatter
  • Constructor Details

    • PhoneFormatterImpl

      public PhoneFormatterImpl()
  • Method Details

    • formatE164

      public Optional<String> formatE164(String number, @Nullable @Nullable String defaultRegion)
      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 interface PhoneFormatter
      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

      public Optional<String> formatNational(String number, @Nullable @Nullable String defaultRegion)
      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 interface PhoneFormatter
      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 interface PhoneFormatter
      Parameters:
      number - The phone number to format.
      Returns:
      the formatted number or Optional.empty(), if it couldn't be formatted.