Class RegexNameValidatingRewriter

  • All Implemented Interfaces:
    NameRewriter

    public final class RegexNameValidatingRewriter
    extends Object
    implements NameRewriter
    A regular expression-based name validation rewriter. Always returns the original name if the name is valid.
    Author:
    David M. Lloyd
    • Field Detail

      • pattern

        private final Pattern pattern
      • match

        private final boolean match
    • Constructor Detail

      • RegexNameValidatingRewriter

        public RegexNameValidatingRewriter​(Pattern pattern,
                                           boolean match)
        Construct a new instance. The pattern is a partial pattern; if the whole string is to be matched, then the appropriate regex anchors should be used.
        Parameters:
        pattern - the pattern that the name must match (or not match) in order to be considered valid (must not be null)
        match - true if the pattern must match, false if the pattern must not match
    • Method Detail

      • rewriteName

        public String rewriteName​(String original)
        Description copied from interface: NameRewriter
        Rewrite a name. Must not return null.
        Specified by:
        rewriteName in interface NameRewriter
        Parameters:
        original - the original name (must not be null)
        Returns:
        the rewritten name, or null if the name is invalid
      • getPattern

        public Pattern getPattern()
        Get the pattern.
        Returns:
        the pattern
      • isMatch

        public boolean isMatch()
        Get the match flag. If the flag is true, the pattern must match; if false, the pattern must not match.
        Returns:
        the match flag