Exemplo n.º 1
0
        public static bool verify(this PhoneNumberUtil.Leniency leniency, PhoneNumber number, String candidate, PhoneNumberUtil util)
        {
            switch (leniency)
            {
            case PhoneNumberUtil.Leniency.POSSIBLE:
                return(util.isPossibleNumber(number));

            case PhoneNumberUtil.Leniency.VALID:
            {
                if (!util.isValidNumber(number) ||
                    !PhoneNumberMatcher.containsOnlyValidXChars(number, candidate, util))
                {
                    return(false);
                }
                return(PhoneNumberMatcher.isNationalPrefixPresentIfRequired(number, util));
            }

            case PhoneNumberUtil.Leniency.STRICT_GROUPING:
            {
                if (!util.isValidNumber(number) ||
                    !PhoneNumberMatcher.containsOnlyValidXChars(number, candidate, util) ||
                    PhoneNumberMatcher.containsMoreThanOneSlashInNationalNumber(number, candidate) ||
                    !PhoneNumberMatcher.isNationalPrefixPresentIfRequired(number, util))
                {
                    return(false);
                }
                return(PhoneNumberMatcher.checkNumberGroupingIsValid(number, candidate, util, new StrictGroupingChecker()));
            }

            default:     //case PhoneNumberUtil.Leniency.EXACT_GROUPING:
            {
                if (!util.isValidNumber(number) ||
                    !PhoneNumberMatcher.containsOnlyValidXChars(number, candidate, util) ||
                    PhoneNumberMatcher.containsMoreThanOneSlashInNationalNumber(number, candidate) ||
                    !PhoneNumberMatcher.isNationalPrefixPresentIfRequired(number, util))
                {
                    return(false);
                }
                return(PhoneNumberMatcher.checkNumberGroupingIsValid(number, candidate, util, new ExactGroupingChecker()));
            }
            }
        }