Class WildcardMatcher


  • public abstract class WildcardMatcher
    extends java.lang.Object
    This matcher is used in for example to disable tracing for certain URLs. The advantage of this class compared to alternatives is is that matching strings is completely allocation free.

    The wildcard matcher supports the * wildcard which matches zero or more characters. By default, matches are a case insensitive. Single character wildcards like f?o are not supported.

    The syntax should be very familiar to any developer. The most common use cases are ignoring URLs paths starting with a specific string like /resources/* or /heartbeat/* and ignoring URLs by file ending like *.js. It also allows to have a single configuration option which, depending on the input string, allows for prefix, postfix and infix matching. This implementation is also very fast, as it just resorts to String.startsWith(String), String.endsWith(String) and String.contains(CharSequence).

    • Constructor Detail

      • WildcardMatcher

        public WildcardMatcher()
    • Method Detail

      • caseSensitiveMatcher

        public static WildcardMatcher caseSensitiveMatcher​(java.lang.String matcher)
      • matchAllList

        public static java.util.List<WildcardMatcher> matchAllList()
      • valueOf

        public static WildcardMatcher valueOf​(java.lang.String wildcardString)
        Constructs a new WildcardMatcher via a wildcard string.

        It supports the * wildcard which matches zero or more characters.

        By default, matches are a case insensitive. Prepend (?-i) to your pattern to make it case sensitive. Example: (?-i)foo* matches the string foobar but does not match FOOBAR.

        It does NOT support single character wildcards like f?o

        Parameters:
        wildcardString - The wildcard string.
        Returns:
        The WildcardMatcher
      • isAnyMatch

        public static boolean isAnyMatch​(java.util.List<WildcardMatcher> matchers,
                                         @Nullable
                                         java.lang.CharSequence s)
        Returns true, if any of the matchers match the provided string.
        Parameters:
        matchers - the matchers which should be used to match the provided string
        s - the string to match against
        Returns:
        true, if any of the matchers match the provided string
      • isNoneMatch

        public static boolean isNoneMatch​(java.util.List<WildcardMatcher> matchers,
                                          @Nullable
                                          java.lang.CharSequence s)
        Returns true, if none of the matchers match the provided string.
        Parameters:
        matchers - the matchers which should be used to match the provided string
        s - the string to match against
        Returns:
        true, if none of the matchers match the provided string
      • anyMatch

        @Nullable
        public static WildcardMatcher anyMatch​(java.util.List<WildcardMatcher> matchers,
                                               @Nullable
                                               java.lang.CharSequence s)
        Returns the first WildcardMatcher matching the provided string.
        Parameters:
        matchers - the matchers which should be used to match the provided string
        s - the string to match against
        Returns:
        the first matching WildcardMatcher, or null if none match.
      • anyMatch

        @Nullable
        public static WildcardMatcher anyMatch​(java.util.List<WildcardMatcher> matchers,
                                               java.lang.CharSequence firstPart,
                                               @Nullable
                                               java.lang.CharSequence secondPart)
        Returns the first WildcardMatcher matching the provided partitioned string.
        Parameters:
        matchers - the matchers which should be used to match the provided string
        firstPart - The first part of the string to match against.
        secondPart - The second part of the string to match against.
        Returns:
        the first matching WildcardMatcher, or null if none match.
        See Also:
        matches(CharSequence, CharSequence)
      • indexOfIgnoreCase

        public static int indexOfIgnoreCase​(java.lang.CharSequence haystack1,
                                            java.lang.CharSequence haystack2,
                                            java.lang.String needle,
                                            boolean ignoreCase,
                                            int start,
                                            int end)
      • matches

        public abstract boolean matches​(java.lang.CharSequence s)
        Checks if the given string matches the wildcard pattern.
        Parameters:
        s - the String to match
        Returns:
        whether the String matches the given pattern
      • matches

        public abstract boolean matches​(java.lang.CharSequence firstPart,
                                        @Nullable
                                        java.lang.CharSequence secondPart)
        This is a different version of matches(CharSequence) which has the same semantics as calling matcher.matches(firstPart + secondPart);.

        The difference is that this method does not allocate memory.

        Parameters:
        firstPart - The first part of the string to match against.
        secondPart - The second part of the string to match against.
        Returns:
        true, when the wildcard pattern matches the partitioned string, false otherwise.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getMatcher

        public abstract java.lang.String getMatcher()