Package org.cyclos.utils
Class MaskHelper
- java.lang.Object
-
- org.cyclos.utils.MaskHelper
-
public class MaskHelper extends Object
Helper class for masks
-
-
Field Summary
Fields Modifier and Type Field Description static StringMASK_VARIABLES
-
Constructor Summary
Constructors Constructor Description MaskHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringapplyAndValidateMask(String mask, String value)Applies the mask validating the given value is a valid masked/unmasked value.static StringapplyMask(String mask, String value)Applies the given mask from the given valuestatic intcountPlaceholders(String mask)Returns the number of placeholders in the given maskstatic StringgenerateMaskedValue(String mask)Generates a random masked value according to the maskstatic StringgenerateValue(String mask)Generates a random (unmasked) value according to the maskstatic StringgenerateValue(String mask, boolean withMask)Generates a random value masked or unmasked according to the given flagstatic List<Character>getAlphabeticVariables()static List<Character>getAlphanumericVariables()static StringgetExample(String mask)Returns an example value which can be used with the given maskstatic intgetMaskedValueLength(String mask)Returns the length of a value for the given maskstatic List<Character>getNumericVariables()static booleanhasValidBeginning(String mask, String maskedValue)Returns true if the value has a correct beginning for the given mask For example: mask: ##-# value: 1 result: true mask: ##-# value: 11- result: true mask: ##-# value: 11-a result: falsestatic booleanisValidMask(String mask)Returns true if the mask has a valid syntaxstatic booleanisValidMaskedValue(String mask, String value)Returns true if the value matches the mask.static StringremoveAndValidateMask(String mask, String value)Removes the mask validating the given value is a valid masked/unmasked value.static StringremoveMask(String mask, String value)Removes the given mask from the given value, trimming to mask length.
If mask is blank, value is null or not a valid masked then value is returned as is.static StringremoveMask(String mask, String value, boolean trimToMask)Removes the given mask from the given value, optionally trimming at mask max length (ex: mask is ###, 12345 would result 123 if true, and 12345 if false)static StringunescapeMask(String mask)
-
-
-
Field Detail
-
MASK_VARIABLES
public static final String MASK_VARIABLES
- See Also:
- Constant Field Values
-
-
Method Detail
-
applyAndValidateMask
public static String applyAndValidateMask(String mask, String value)
Applies the mask validating the given value is a valid masked/unmasked value. If the given value is already a valid masked then it returns as-is.
-
applyMask
public static String applyMask(String mask, String value)
Applies the given mask from the given value
-
countPlaceholders
public static int countPlaceholders(String mask)
Returns the number of placeholders in the given mask
-
generateMaskedValue
public static String generateMaskedValue(String mask)
Generates a random masked value according to the mask
-
generateValue
public static String generateValue(String mask)
Generates a random (unmasked) value according to the mask
-
generateValue
public static String generateValue(String mask, boolean withMask)
Generates a random value masked or unmasked according to the given flag
-
getExample
public static String getExample(String mask)
Returns an example value which can be used with the given mask
-
getMaskedValueLength
public static int getMaskedValueLength(String mask)
Returns the length of a value for the given mask
-
hasValidBeginning
public static boolean hasValidBeginning(String mask, String maskedValue)
Returns true if the value has a correct beginning for the given mask For example: mask: ##-# value: 1 result: true mask: ##-# value: 11- result: true mask: ##-# value: 11-a result: false
-
isValidMask
public static boolean isValidMask(String mask)
Returns true if the mask has a valid syntax
-
isValidMaskedValue
public static boolean isValidMaskedValue(String mask, String value)
Returns true if the value matches the mask.
-
removeAndValidateMask
public static String removeAndValidateMask(String mask, String value)
Removes the mask validating the given value is a valid masked/unmasked value. If the given value is already an unmasked then it returns as-is.
-
removeMask
public static String removeMask(String mask, String value)
Removes the given mask from the given value, trimming to mask length.
If mask is blank, value is null or not a valid masked then value is returned as is.- See Also:
removeMask(String, String, boolean)
-
removeMask
public static String removeMask(String mask, String value, boolean trimToMask)
Removes the given mask from the given value, optionally trimming at mask max length (ex: mask is ###, 12345 would result 123 if true, and 12345 if false)
-
-