Package jodd.util

Class Wildcard


  • public class Wildcard
    extends java.lang.Object
    Checks whether a string or path matches a given wildcard pattern. Possible patterns allow to match single characters ('?') or any count of characters ('*'). Wildcard characters can be escaped (by an '\'). When matching path, deep tree wildcard also can be used ('**').

    This method uses recursive matching, as in linux or windows. regexp works the same. This method is very fast, comparing to similar implementations.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String PATH_MATCH  
      protected static java.lang.String PATH_SEPARATORS  
    • Constructor Summary

      Constructors 
      Constructor Description
      Wildcard()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean equalsOrMatch​(java.lang.CharSequence string, java.lang.CharSequence pattern)
      Checks if two strings are equals or if they match(CharSequence, CharSequence).
      static boolean match​(java.lang.CharSequence string, java.lang.CharSequence pattern)
      Checks whether a string matches a given wildcard pattern.
      static int matchOne​(java.lang.String src, java.lang.String... patterns)
      Matches string to at least one pattern.
      static boolean matchPath​(java.lang.String path, java.lang.String pattern)
      Matches path against pattern using *, ? and ** wildcards.
      static int matchPathOne​(java.lang.String path, java.lang.String... patterns)
      Matches path to at least one pattern.
      protected static boolean matchTokens​(java.lang.String[] tokens, java.lang.String[] patterns)
      Match tokenized string and pattern.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Wildcard

        public Wildcard()
    • Method Detail

      • match

        public static boolean match​(java.lang.CharSequence string,
                                    java.lang.CharSequence pattern)
        Checks whether a string matches a given wildcard pattern.
        Parameters:
        string - input string
        pattern - pattern to match
        Returns:
        true if string matches the pattern, otherwise false
      • equalsOrMatch

        public static boolean equalsOrMatch​(java.lang.CharSequence string,
                                            java.lang.CharSequence pattern)
        Checks if two strings are equals or if they match(CharSequence, CharSequence). Useful for cases when matching a lot of equal strings and speed is important.
      • matchOne

        public static int matchOne​(java.lang.String src,
                                   java.lang.String... patterns)
        Matches string to at least one pattern. Returns index of matched pattern, or -1 otherwise.
        See Also:
        match(CharSequence, CharSequence)
      • matchPathOne

        public static int matchPathOne​(java.lang.String path,
                                       java.lang.String... patterns)
        Matches path to at least one pattern. Returns index of matched pattern or -1 otherwise.
        See Also:
        matchPath(String, String)
      • matchPath

        public static boolean matchPath​(java.lang.String path,
                                        java.lang.String pattern)
        Matches path against pattern using *, ? and ** wildcards. Both path and the pattern are tokenized on path separators (both \ and /). '**' represents deep tree wildcard, as in Ant.
      • matchTokens

        protected static boolean matchTokens​(java.lang.String[] tokens,
                                             java.lang.String[] patterns)
        Match tokenized string and pattern.