Class WildcardMatcher
- java.lang.Object
-
- co.elastic.apm.agent.matcher.WildcardMatcher
-
public abstract class WildcardMatcher extends java.lang.ObjectThis 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 likef?oare 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 toString.startsWith(String),String.endsWith(String)andString.contains(CharSequence).
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDOCUMENTATION
-
Constructor Summary
Constructors Constructor Description WildcardMatcher()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static WildcardMatcheranyMatch(java.util.List<WildcardMatcher> matchers, java.lang.CharSequence s)Returns the firstWildcardMatchermatching the provided string.static WildcardMatcheranyMatch(java.util.List<WildcardMatcher> matchers, java.lang.CharSequence firstPart, java.lang.CharSequence secondPart)Returns the firstWildcardMatchermatching the provided partitioned string.static WildcardMatchercaseSensitiveMatcher(java.lang.String matcher)booleanequals(java.lang.Object obj)abstract java.lang.StringgetMatcher()static intindexOfIgnoreCase(java.lang.CharSequence haystack1, java.lang.CharSequence haystack2, java.lang.String needle, boolean ignoreCase, int start, int end)static booleanisAnyMatch(java.util.List<WildcardMatcher> matchers, java.lang.CharSequence s)Returnstrue, if any of the matchers match the provided string.static booleanisNoneMatch(java.util.List<WildcardMatcher> matchers, java.lang.CharSequence s)Returnstrue, if none of the matchers match the provided string.static WildcardMatchermatchAll()static java.util.List<WildcardMatcher>matchAllList()abstract booleanmatches(java.lang.CharSequence s)Checks if the given string matches the wildcard pattern.abstract booleanmatches(java.lang.CharSequence firstPart, java.lang.CharSequence secondPart)This is a different version ofmatches(CharSequence)which has the same semantics as callingmatcher.matches(firstPart + secondPart);.static WildcardMatchervalueOf(java.lang.String wildcardString)Constructs a newWildcardMatchervia a wildcard string.
-
-
-
Field Detail
-
DOCUMENTATION
public static final java.lang.String DOCUMENTATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
caseSensitiveMatcher
public static WildcardMatcher caseSensitiveMatcher(java.lang.String matcher)
-
matchAll
public static WildcardMatcher matchAll()
-
matchAllList
public static java.util.List<WildcardMatcher> matchAllList()
-
valueOf
public static WildcardMatcher valueOf(java.lang.String wildcardString)
Constructs a newWildcardMatchervia 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 stringfoobarbut does not matchFOOBAR.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)
Returnstrue, if any of the matchers match the provided string.- Parameters:
matchers- the matchers which should be used to match the provided strings- 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)
Returnstrue, if none of the matchers match the provided string.- Parameters:
matchers- the matchers which should be used to match the provided strings- 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 firstWildcardMatchermatching the provided string.- Parameters:
matchers- the matchers which should be used to match the provided strings- the string to match against- Returns:
- the first matching
WildcardMatcher, ornullif none match.
-
anyMatch
@Nullable public static WildcardMatcher anyMatch(java.util.List<WildcardMatcher> matchers, java.lang.CharSequence firstPart, @Nullable java.lang.CharSequence secondPart)
Returns the firstWildcardMatchermatching the provided partitioned string.- Parameters:
matchers- the matchers which should be used to match the provided stringfirstPart- The first part of the string to match against.secondPart- The second part of the string to match against.- Returns:
- the first matching
WildcardMatcher, ornullif 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 ofmatches(CharSequence)which has the same semantics as callingmatcher.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,falseotherwise.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getMatcher
public abstract java.lang.String getMatcher()
-
-