@Status(stage=DEVELOPMENT, unitTests=COMPLETE) @Wish(value="Be able to specify a mask character as a literal") @Wish(value="Be able to specify multiple mask characters with a number prefix like:5#-5# instead of:#####-#####") public final class Mask extends Object
Mask character | Description |
---|---|
# | A digit from 0 to 9 |
A | Alphabetic character |
L | Alphabetic character, converted to lower case |
U | Alphabetic character, converted to upper case |
N | Alphanumeric character |
? | Any character |
Mask.fromUnmaskedValue("#### UU", "3931LA");
. This will return "3931 LA".Mask.fromMaskedValue("#### UU", "3931 la");
. This will return "3931LA".ZipCodeOfCountry
class handles this problem by
supporting different masks that are used in turn.Modifier and Type | Method and Description |
---|---|
static String |
fromMaskedValue(String mask,
String maskedValue)
Converts the supplied maskedValue to a value that does not contain mask characters.
|
static String |
fromUnmaskedValue(String mask,
String unmaskedValue)
Converts the supplied unmaskedValue to a value that contains mask characters.
|
public static String fromMaskedValue(String mask, String maskedValue)
mask
- The mask.maskedValue
- The masked value (the value possibly containing mask characters) to unmask.NullPointerException
- When either the supplied mask or maskedValue is null.IllegalArgumentException
- When the supplied mask is empty or when the supplied maskedValue is longer than the
supplied mask.public static String fromUnmaskedValue(String mask, String unmaskedValue)
mask
- The mask.unmaskedValue
- The unmasked value.NullPointerException
- When either the supplied mask or the supplied unmaskedValue is null.IllegalArgumentException
- When the supplied mask is empty or when the unmaskedValue is shorter than may be
expected from the mask.Copyright © 2008–2018. All rights reserved.