replaceAll() private method

private replaceAll ( global par0, global par1 ) : global::java.lang.String
par0 global
par1 global
return global::java.lang.String
Ejemplo n.º 1
0
        // Gets a formatting template which can be used to efficiently format a partial number where
        // digits are added one by one.
        private String getFormattingTemplate(String numberPattern, String numberFormat)
        {
            // Creates a phone number consisting only of the digit 9 that matches the
            // numberPattern by applying the pattern to the longestPhoneNumber string.
            String  longestPhoneNumber = "999999999999999";
            Matcher m = regexCache.getPatternForRegex(numberPattern).matcher(longestPhoneNumber);

            m.find(); // this will always succeed
            String aPhoneNumber = m.group();

            // No formatting template can be created if the number of digits entered so far is longer than
            // the maximum the current formatting rule can accommodate.
            if (aPhoneNumber.length() < nationalNumber.length())
            {
                return("");
            }
            // Formats the number according to numberFormat
            String template = aPhoneNumber.replaceAll(numberPattern, numberFormat);

            // Replaces each digit with character DIGIT_PLACEHOLDER
            template = template.replaceAll("9", DIGIT_PLACEHOLDER);
            return(template);
        }