Ejemplo n.º 1
0
        internal static bool allNumberGroupsAreExactlyPresent(PhoneNumberUtil util,
                                                              PhoneNumber number,
                                                              StringBuilder normalizedCandidate,
                                                              String[] formattedNumberGroups)
        {
            String[] candidateGroups =
                PhoneNumberUtil.NON_DIGITS_PATTERN.Split(normalizedCandidate.ToString());
            // Set this to the last group, skipping it if the number has an extension.
            int candidateNumberGroupIndex =
                number.HasExtension() ? candidateGroups.Length - 2 : candidateGroups.Length - 1;

            // First we check if the national significant number is formatted as a block.
            // We use contains and not equals, since the national significant number may be present with
            // a prefix such as a national number prefix, or the country code itself.
            if (candidateGroups.Length == 1 ||
                candidateGroups[candidateNumberGroupIndex].Contains(
                    util.getNationalSignificantNumber(number)))
            {
                return(true);
            }
            // Starting from the end, go through in reverse, excluding the first group, and check the
            // candidate and number groups are the same.
            for (int formattedNumberGroupIndex = (formattedNumberGroups.Length - 1);
                 formattedNumberGroupIndex > 0 && candidateNumberGroupIndex >= 0;
                 formattedNumberGroupIndex--, candidateNumberGroupIndex--)
            {
                if (!candidateGroups[candidateNumberGroupIndex].Equals(
                        formattedNumberGroups[formattedNumberGroupIndex]))
                {
                    return(false);
                }
            }
            // Now check the first group. There may be a national prefix at the start, so we only check
            // that the candidate group ends with the formatted number group.
            return(candidateNumberGroupIndex >= 0 &&
                   candidateGroups[candidateNumberGroupIndex].EndsWith(formattedNumberGroups[0]));
        }
Ejemplo n.º 2
0
 public PhoneNumber mergeFrom(PhoneNumber other)
 {
     if (other.HasCountryCode())
     {
         setCountryCode(other.getCountryCode());
     }
     if (other.HasNationalNumber())
     {
         setNationalNumber(other.getNationalNumber());
     }
     if (other.HasExtension())
     {
         setExtension(other.getExtension());
     }
     if (other.HasItalianLeadingZero())
     {
         setItalianLeadingZero(other.isItalianLeadingZero());
     }
     if (other.HasNumberOfLeadingZeros())
     {
         setNumberOfLeadingZeros(other.getNumberOfLeadingZeros());
     }
     if (other.HasRawInput())
     {
         setRawInput(other.getRawInput());
     }
     if (other.HasCountryCodeSource())
     {
         setCountryCodeSource(other.getCountryCodeSource());
     }
     if (other.HasPreferredDomesticCarrierCode())
     {
         setPreferredDomesticCarrierCode(other.getPreferredDomesticCarrierCode());
     }
     return(this);
 }