// @VisibleForTesting
        static void SetRelevantDescPatterns(PhoneMetadata.Builder metadata, XElement element,
                                            bool isShortNumberMetadata)
        {
            var generalDescBuilder = ProcessPhoneNumberDescElement(null, element,
                                                                   GENERAL_DESC);

            // Calculate the possible lengths for the general description. This will be based on the
            // possible lengths of the child elements.
            SetPossibleLengthsGeneralDesc(
                generalDescBuilder, metadata.Id, element, isShortNumberMetadata);
            metadata.SetGeneralDesc(generalDescBuilder);

            var generalDesc = metadata.GeneralDesc;

            if (!isShortNumberMetadata)
            {
                // Set fields used by regular length phone numbers.
                metadata.SetFixedLine(ProcessPhoneNumberDescElement(generalDesc, element, FIXED_LINE));
                metadata.SetMobile(ProcessPhoneNumberDescElement(generalDesc, element, MOBILE));
                metadata.SetSharedCost(ProcessPhoneNumberDescElement(generalDesc, element, SHARED_COST));
                metadata.SetVoip(ProcessPhoneNumberDescElement(generalDesc, element, VOIP));
                metadata.SetPersonalNumber(ProcessPhoneNumberDescElement(generalDesc, element,
                                                                         PERSONAL_NUMBER));
                metadata.SetPager(ProcessPhoneNumberDescElement(generalDesc, element, PAGER));
                metadata.SetUan(ProcessPhoneNumberDescElement(generalDesc, element, UAN));
                metadata.SetVoicemail(ProcessPhoneNumberDescElement(generalDesc, element, VOICEMAIL));
                metadata.SetNoInternationalDialling(ProcessPhoneNumberDescElement(generalDesc, element,
                                                                                  NO_INTERNATIONAL_DIALLING));
                var mobileAndFixedAreSame = metadata.Mobile.NationalNumberPattern
                                            .Equals(metadata.FixedLine.NationalNumberPattern);
                if (metadata.SameMobileAndFixedLinePattern != mobileAndFixedAreSame)
                {
                    // Set this if it is not the same as the default.
                    metadata.SetSameMobileAndFixedLinePattern(mobileAndFixedAreSame);
                }
                metadata.SetTollFree(ProcessPhoneNumberDescElement(generalDesc, element, TOLL_FREE));
                metadata.SetPremiumRate(ProcessPhoneNumberDescElement(generalDesc, element, PREMIUM_RATE));
            }
            else
            {
                // Set fields used by short numbers.
                metadata.SetStandardRate(ProcessPhoneNumberDescElement(generalDesc, element, STANDARD_RATE));
                metadata.SetShortCode(ProcessPhoneNumberDescElement(generalDesc, element, SHORT_CODE));
                metadata.SetCarrierSpecific(ProcessPhoneNumberDescElement(generalDesc, element,
                                                                          CARRIER_SPECIFIC));
                metadata.SetEmergency(ProcessPhoneNumberDescElement(generalDesc, element, EMERGENCY));
                metadata.SetTollFree(ProcessPhoneNumberDescElement(generalDesc, element, TOLL_FREE));
                metadata.SetPremiumRate(ProcessPhoneNumberDescElement(generalDesc, element, PREMIUM_RATE));
                metadata.SetSmsServices(ProcessPhoneNumberDescElement(generalDesc, element, SMS_SERVICES));
            }
        }
        // @VisibleForTesting
        public static void LoadGeneralDesc(PhoneMetadata.Builder metadata, XElement element)
        {
            var generalDescBuilder = ProcessPhoneNumberDescElement(null, element, GENERAL_DESC);

            SetPossibleLengthsGeneralDesc(generalDescBuilder, metadata.Id, element, false);
            var generalDesc = generalDescBuilder.Build();

            metadata.SetFixedLine(ProcessPhoneNumberDescElement(generalDesc, element, FIXED_LINE));
            metadata.SetMobile(ProcessPhoneNumberDescElement(generalDesc, element, MOBILE));
            metadata.SetTollFree(ProcessPhoneNumberDescElement(generalDesc, element, TOLL_FREE));
            metadata.SetPremiumRate(ProcessPhoneNumberDescElement(generalDesc, element, PREMIUM_RATE));
            metadata.SetSharedCost(ProcessPhoneNumberDescElement(generalDesc, element, SHARED_COST));
            metadata.SetVoip(ProcessPhoneNumberDescElement(generalDesc, element, VOIP));
            metadata.SetPersonalNumber(ProcessPhoneNumberDescElement(generalDesc, element, PERSONAL_NUMBER));
            metadata.SetPager(ProcessPhoneNumberDescElement(generalDesc, element, PAGER));
            metadata.SetUan(ProcessPhoneNumberDescElement(generalDesc, element, UAN));
            metadata.SetVoicemail(ProcessPhoneNumberDescElement(generalDesc, element, VOICEMAIL));
            metadata.SetEmergency(ProcessPhoneNumberDescElement(generalDesc, element, EMERGENCY));
            metadata.SetNoInternationalDialling(ProcessPhoneNumberDescElement(generalDesc, element, NO_INTERNATIONAL_DIALLING));
            metadata.SetSameMobileAndFixedLinePattern(
                metadata.Mobile.NationalNumberPattern.Equals(
                    metadata.FixedLine.NationalNumberPattern));
        }
        // @VisibleForTesting
        public static void LoadGeneralDesc(PhoneMetadata.Builder metadata, XElement element, bool liteBuild)
        {
            var generalDesc = ProcessPhoneNumberDescElement(null, element, GENERAL_DESC, liteBuild);

            metadata.SetGeneralDesc(generalDesc);

            metadata.SetFixedLine(ProcessPhoneNumberDescElement(generalDesc, element, FIXED_LINE, liteBuild));
            metadata.SetMobile(ProcessPhoneNumberDescElement(generalDesc, element, MOBILE, liteBuild));
            metadata.SetTollFree(ProcessPhoneNumberDescElement(generalDesc, element, TOLL_FREE, liteBuild));
            metadata.SetPremiumRate(ProcessPhoneNumberDescElement(generalDesc, element, PREMIUM_RATE, liteBuild));
            metadata.SetSharedCost(ProcessPhoneNumberDescElement(generalDesc, element, SHARED_COST, liteBuild));
            metadata.SetVoip(ProcessPhoneNumberDescElement(generalDesc, element, VOIP, liteBuild));
            metadata.SetPersonalNumber(ProcessPhoneNumberDescElement(generalDesc, element,
                                                                     PERSONAL_NUMBER, liteBuild));
            metadata.SetPager(ProcessPhoneNumberDescElement(generalDesc, element, PAGER, liteBuild));
            metadata.SetUan(ProcessPhoneNumberDescElement(generalDesc, element, UAN, liteBuild));
            metadata.SetVoicemail(ProcessPhoneNumberDescElement(generalDesc, element, VOICEMAIL, liteBuild));
            metadata.SetEmergency(ProcessPhoneNumberDescElement(generalDesc, element, EMERGENCY, liteBuild));
            metadata.SetNoInternationalDialling(ProcessPhoneNumberDescElement(generalDesc, element,
                                                                              NO_INTERNATIONAL_DIALLING, liteBuild));
            metadata.SetSameMobileAndFixedLinePattern(
                metadata.Mobile.NationalNumberPattern.Equals(
                    metadata.FixedLine.NationalNumberPattern));
        }
Exemplo n.º 4
0
        /**
         * Clears certain fields in {@code metadata} as defined by the {@code MetadataFilter} instance.
         * Note that this changes the mutable {@code metadata} object, and is not thread-safe. If this
         * method does not return successfully, do not assume {@code metadata} has not changed.
         *
         * @param metadata  The {@code PhoneMetadata} object to be filtered
         */
        internal void FilterMetadata(PhoneMetadata.Builder metadata)
        {
            // TODO: Consider clearing if the filtered PhoneNumberDesc is empty.
            if (metadata.HasFixedLine)
            {
                metadata.SetFixedLine(GetFiltered("fixedLine", metadata.FixedLine));
            }
            if (metadata.HasMobile)
            {
                metadata.SetMobile(GetFiltered("mobile", metadata.Mobile));
            }
            if (metadata.HasTollFree)
            {
                metadata.SetTollFree(GetFiltered("tollFree", metadata.TollFree));
            }
            if (metadata.HasPremiumRate)
            {
                metadata.SetPremiumRate(GetFiltered("premiumRate", metadata.PremiumRate));
            }
            if (metadata.HasSharedCost)
            {
                metadata.SetSharedCost(GetFiltered("sharedCost", metadata.SharedCost));
            }
            if (metadata.HasPersonalNumber)
            {
                metadata.SetPersonalNumber(GetFiltered("personalNumber", metadata.PersonalNumber));
            }
            if (metadata.HasVoip)
            {
                metadata.SetVoip(GetFiltered("voip", metadata.Voip));
            }
            if (metadata.HasPager)
            {
                metadata.SetPager(GetFiltered("pager", metadata.Pager));
            }
            if (metadata.HasUan)
            {
                metadata.SetUan(GetFiltered("uan", metadata.Uan));
            }
            if (metadata.HasEmergency)
            {
                metadata.SetEmergency(GetFiltered("emergency", metadata.Emergency));
            }
            if (metadata.HasVoicemail)
            {
                metadata.SetVoicemail(GetFiltered("voicemail", metadata.Voicemail));
            }
            if (metadata.HasShortCode)
            {
                metadata.SetShortCode(GetFiltered("shortCode", metadata.ShortCode));
            }
            if (metadata.HasStandardRate)
            {
                metadata.SetStandardRate(GetFiltered("standardRate", metadata.StandardRate));
            }
            if (metadata.HasCarrierSpecific)
            {
                metadata.SetCarrierSpecific(GetFiltered("carrierSpecific", metadata.CarrierSpecific));
            }
            if (metadata.HasSmsServices)
            {
                metadata.SetSmsServices(GetFiltered("smsServices", metadata.SmsServices));
            }
            if (metadata.HasNoInternationalDialling)
            {
                metadata.SetNoInternationalDialling(GetFiltered("noInternationalDialling",
                                                                metadata.NoInternationalDialling));
            }

            if (ShouldDrop("preferredInternationalPrefix"))
            {
                metadata.ClearPreferredInternationalPrefix();
            }
            if (ShouldDrop("nationalPrefix"))
            {
                metadata.ClearNationalPrefix();
            }
            if (ShouldDrop("preferredExtnPrefix"))
            {
                metadata.ClearPreferredExtnPrefix();
            }
            if (ShouldDrop("nationalPrefixTransformRule"))
            {
                metadata.ClearNationalPrefixTransformRule();
            }
            if (ShouldDrop("sameMobileAndFixedLinePattern"))
            {
                metadata.ClearSameMobileAndFixedLinePattern();
            }
            if (ShouldDrop("mainCountryForCode"))
            {
                metadata.ClearMainCountryForCode();
            }
            if (ShouldDrop("leadingZeroPossible"))
            {
                metadata.ClearLeadingZeroPossible();
            }
            if (ShouldDrop("mobileNumberPortableRegion"))
            {
                metadata.ClearMobileNumberPortableRegion();
            }
        }