-
public class AsYouTypeFormatterA formatter which formats phone numbers as they are entered.
An AsYouTypeFormatter can be created by invoking getAsYouTypeFormatter. After that, digits can be added by invoking inputDigit on the formatter instance, and the partially formatted phone number will be returned each time a digit is added. clear can be invoked before formatting a new number.
See the unittests for more details on how the formatter is to be used.
-
-
Method Summary
Modifier and Type Method Description voidclear()Clears the internal state of the formatter, so it can be reused. StringinputDigit(char nextChar)Formats a phone number on-the-fly as each digit is entered. StringinputDigitAndRememberPosition(char nextChar)Same as inputDigit, but remembers the position where {@code nextChar}is inserted, sothat it can be retrieved later by using getRememberedPosition.intgetRememberedPosition()Returns the current position in the partially formatted phone number of the character which waspreviously passed in as the parameter of inputDigitAndRememberPosition. -
-
Method Detail
-
clear
void clear()
Clears the internal state of the formatter, so it can be reused.
-
inputDigit
String inputDigit(char nextChar)
Formats a phone number on-the-fly as each digit is entered.
- Parameters:
nextChar- the most recently entered digit of a phone number.
-
inputDigitAndRememberPosition
String inputDigitAndRememberPosition(char nextChar)
Same as inputDigit, but remembers the position where
{@code nextChar}is inserted, sothat it can be retrieved later by using getRememberedPosition. The rememberedposition will be automatically adjusted if additional formatting characters are laterinserted/removed in front of{@code nextChar}.
-
getRememberedPosition
int getRememberedPosition()
Returns the current position in the partially formatted phone number of the character which waspreviously passed in as the parameter of inputDigitAndRememberPosition.
-
-
-
-