Exemplo n.º 1
0
        /**
         * Gets a valid short number for the specified cost category.
         *
         * @param regionCode the region for which an example short number is needed
         * @param cost the cost category of number that is needed
         * @return a valid short number for the specified region and cost category. Returns an empty
         *     string when the metadata does not contain such information, or the cost is UNKNOWN_COST.
         */
        // @VisibleForTesting
        internal String getExampleShortNumberForCost(String regionCode, ShortNumberCost cost)
        {
            PhoneMetadata phoneMetadata = MetadataManager.getShortNumberMetadataForRegion(regionCode);

            if (phoneMetadata == null)
            {
                return("");
            }
            PhoneNumberDesc desc = null;

            switch (cost)
            {
            case ShortNumberCost.TOLL_FREE:
                desc = phoneMetadata.getTollFree();
                break;

            case ShortNumberCost.STANDARD_RATE:
                desc = phoneMetadata.getStandardRate();
                break;

            case ShortNumberCost.PREMIUM_RATE:
                desc = phoneMetadata.getPremiumRate();
                break;

            default:
                // UNKNOWN_COST numbers are computed by the process of elimination from the other cost
                // categories.
                break;
            }
            if (desc != null && desc.HasExampleNumber())
            {
                return(desc.getExampleNumber());
            }
            return("");
        }
Exemplo n.º 2
0
        /**
         * Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify
         * the number is actually in use, which is impossible to tell by just looking at the number
         * itself.
         *
         * @param shortNumber the short number to check as a string
         * @param regionDialingFrom the region from which the number is dialed
         * @return whether the short number matches a valid pattern
         */
        public bool isValidShortNumberForRegion(String shortNumber, String regionDialingFrom)
        {
            PhoneMetadata phoneMetadata =
                MetadataManager.getShortNumberMetadataForRegion(regionDialingFrom);

            if (phoneMetadata == null)
            {
                return(false);
            }
            PhoneNumberDesc generalDesc = phoneMetadata.getGeneralDesc();

            if (!generalDesc.HasNationalNumberPattern() ||
                !phoneUtil.isNumberMatchingDesc(shortNumber, generalDesc))
            {
                return(false);
            }
            PhoneNumberDesc shortNumberDesc = phoneMetadata.getShortCode();

            if (!shortNumberDesc.HasNationalNumberPattern())
            {
                logger.log(Level.WARNING, "No short code national number pattern found for region: " +
                           regionDialingFrom);
                return(false);
            }
            return(phoneUtil.isNumberMatchingDesc(shortNumber, shortNumberDesc));
        }
Exemplo n.º 3
0
 public PhoneMetadata setNoInternationalDialling(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasNoInternationalDialling = true;
     noInternationalDialling_   = value;
     return(this);
 }
Exemplo n.º 4
0
 public PhoneMetadata setSharedCost(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasSharedCost = true;
     sharedCost_   = value;
     return(this);
 }
Exemplo n.º 5
0
 public PhoneMetadata setTollFree(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasTollFree = true;
     tollFree_   = value;
     return(this);
 }
Exemplo n.º 6
0
 public PhoneMetadata setStandardRate(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasStandardRate = true;
     standardRate_   = value;
     return(this);
 }
Exemplo n.º 7
0
 public PhoneMetadata setCarrierSpecific(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasCarrierSpecific = true;
     carrierSpecific_   = value;
     return(this);
 }
Exemplo n.º 8
0
 public PhoneMetadata setVoicemail(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasVoicemail = true;
     voicemail_   = value;
     return(this);
 }
Exemplo n.º 9
0
 public PhoneMetadata setShortCode(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasShortCode = true;
     shortCode_   = value;
     return(this);
 }
Exemplo n.º 10
0
 public PhoneMetadata setUan(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasUan = true;
     uan_   = value;
     return(this);
 }
Exemplo n.º 11
0
 public PhoneMetadata setEmergency(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasEmergency = true;
     emergency_   = value;
     return(this);
 }
Exemplo n.º 12
0
 public PhoneMetadata setMobile(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasMobile = true;
     mobile_   = value;
     return(this);
 }
Exemplo n.º 13
0
 public PhoneMetadata setPager(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasPager = true;
     pager_   = value;
     return(this);
 }
Exemplo n.º 14
0
 public PhoneMetadata setPremiumRate(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasPremiumRate = true;
     premiumRate_   = value;
     return(this);
 }
Exemplo n.º 15
0
 public PhoneMetadata setFixedLine(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasFixedLine = true;
     fixedLine_   = value;
     return(this);
 }
Exemplo n.º 16
0
 public PhoneMetadata setGeneralDesc(PhoneNumberDesc value)
 {
     if (value == null)
     {
         throw new NullReferenceException();
     }
     hasGeneralDesc = true;
     generalDesc_   = value;
     return(this);
 }
Exemplo n.º 17
0
        /**
         * Check whether a short number is a possible number when dialled from a region, given the number
         * in the form of a string, and the region where the number is dialed from. This provides a more
         * lenient check than {@link #isValidShortNumberForRegion}.
         *
         * @param shortNumber the short number to check as a string
         * @param regionDialingFrom the region from which the number is dialed
         * @return whether the number is a possible short number
         */
        public bool isPossibleShortNumberForRegion(String shortNumber, String regionDialingFrom)
        {
            PhoneMetadata phoneMetadata =
                MetadataManager.getShortNumberMetadataForRegion(regionDialingFrom);

            if (phoneMetadata == null)
            {
                return(false);
            }
            PhoneNumberDesc generalDesc = phoneMetadata.getGeneralDesc();

            return(phoneUtil.isNumberPossibleForDesc(shortNumber, generalDesc));
        }
Exemplo n.º 18
0
        /**
         * Gets a valid short number for the specified region.
         *
         * @param regionCode the region for which an example short number is needed
         * @return a valid short number for the specified region. Returns an empty string when the
         *     metadata does not contain such information.
         */
        // @VisibleForTesting
        internal String getExampleShortNumber(String regionCode)
        {
            PhoneMetadata phoneMetadata = MetadataManager.getShortNumberMetadataForRegion(regionCode);

            if (phoneMetadata == null)
            {
                return("");
            }
            PhoneNumberDesc desc = phoneMetadata.getShortCode();

            if (desc.HasExampleNumber())
            {
                return(desc.getExampleNumber());
            }
            return("");
        }
Exemplo n.º 19
0
 public PhoneNumberDesc mergeFrom(PhoneNumberDesc other)
 {
     if (other.HasNationalNumberPattern())
     {
         setNationalNumberPattern(other.getNationalNumberPattern());
     }
     if (other.HasPossibleNumberPattern())
     {
         setPossibleNumberPattern(other.getPossibleNumberPattern());
     }
     if (other.HasExampleNumber())
     {
         setExampleNumber(other.getExampleNumber());
     }
     return(this);
 }
Exemplo n.º 20
0
//
        public void readExternal(BinaryReader objectInput)
        {
            bool hasDesc = objectInput.readBoolean();

            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setGeneralDesc(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setFixedLine(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setMobile(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setTollFree(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setPremiumRate(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setSharedCost(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setPersonalNumber(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setVoip(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setPager(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setUan(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setEmergency(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setVoicemail(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setShortCode(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setStandardRate(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setCarrierSpecific(desc);
            }
            hasDesc = objectInput.readBoolean();
            if (hasDesc)
            {
                PhoneNumberDesc desc = new PhoneNumberDesc();
                desc.readExternal(objectInput);
                setNoInternationalDialling(desc);
            }

            setId(objectInput.readUTF());
            setCountryCode(objectInput.readInt());
            setInternationalPrefix(objectInput.readUTF());

            bool hasString = objectInput.readBoolean();

            if (hasString)
            {
                setPreferredInternationalPrefix(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setNationalPrefix(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setPreferredExtnPrefix(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setNationalPrefixForParsing(objectInput.readUTF());
            }

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setNationalPrefixTransformRule(objectInput.readUTF());
            }

            setSameMobileAndFixedLinePattern(objectInput.readBoolean());

            int nationalFormatSize = objectInput.readInt();

            for (int i = 0; i < nationalFormatSize; i++)
            {
                NumberFormat numFormat = new NumberFormat();
                numFormat.readExternal(objectInput);
                numberFormat_.Add(numFormat);
            }

            int intlNumberFormatSize = objectInput.readInt();

            for (int i = 0; i < intlNumberFormatSize; i++)
            {
                NumberFormat numFormat = new NumberFormat();
                numFormat.readExternal(objectInput);
                intlNumberFormat_.Add(numFormat);
            }

            setMainCountryForCode(objectInput.readBoolean());

            hasString = objectInput.readBoolean();
            if (hasString)
            {
                setLeadingDigits(objectInput.readUTF());
            }

            setLeadingZeroPossible(objectInput.readBoolean());

            setMobileNumberPortableRegion(objectInput.readBoolean());
        }
Exemplo n.º 21
0
 public bool exactlySameAs(PhoneNumberDesc other)
 {
     return(nationalNumberPattern_.Equals(other.nationalNumberPattern_) &&
            possibleNumberPattern_.Equals(other.possibleNumberPattern_) &&
            exampleNumber_.Equals(other.exampleNumber_));
 }