Class MaskHelper


  • public class MaskHelper
    extends Object
    Helper class for masks
    • Constructor Detail

      • MaskHelper

        public MaskHelper()
    • 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
      • getAlphabeticVariables

        public static List<Character> getAlphabeticVariables()
      • getAlphanumericVariables

        public static List<Character> getAlphanumericVariables()
      • 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
      • getNumericVariables

        public static List<Character> getNumericVariables()
      • 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)
      • unescapeMask

        public static String unescapeMask​(String mask)