Package net.bytebuddy.matcher
Class CachingMatcher<T>
- java.lang.Object
-
- net.bytebuddy.matcher.ElementMatcher.Junction.AbstractBase<T>
-
- net.bytebuddy.matcher.CachingMatcher<T>
-
- Type Parameters:
T
- The actual matched type of this matcher.
- All Implemented Interfaces:
ElementMatcher<T>
,ElementMatcher.Junction<T>
- Direct Known Subclasses:
CachingMatcher.WithInlineEviction
@Enhance(permitSubclassEquality=true) public class CachingMatcher<T> extends ElementMatcher.Junction.AbstractBase<T>
A matcher that remembers the results of previously matching an equal target.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CachingMatcher.WithInlineEviction<S>
A caching matcher with inline cache eviction.-
Nested classes/interfaces inherited from interface net.bytebuddy.matcher.ElementMatcher
ElementMatcher.Junction<S>
-
Nested classes/interfaces inherited from interface net.bytebuddy.matcher.ElementMatcher.Junction
ElementMatcher.Junction.AbstractBase<V>, ElementMatcher.Junction.Conjunction<W>, ElementMatcher.Junction.Disjunction<W>
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentMap<? super T,java.lang.Boolean>
map
A map that serves as a cache for previous matches.private ElementMatcher<? super T>
matcher
The underlying matcher to apply for non-cached targets.
-
Constructor Summary
Constructors Constructor Description CachingMatcher(ElementMatcher<? super T> matcher, java.util.concurrent.ConcurrentMap<? super T,java.lang.Boolean> map)
Creates a new caching matcher.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
matches(T target)
Matches a target against this element matcher.protected boolean
onCacheMiss(T target)
Invoked if the cache is not hit.java.lang.String
toString()
-
Methods inherited from class net.bytebuddy.matcher.ElementMatcher.Junction.AbstractBase
and, or
-
-
-
-
Field Detail
-
matcher
private final ElementMatcher<? super T> matcher
The underlying matcher to apply for non-cached targets.
-
map
@ValueHandling(IGNORE) protected final java.util.concurrent.ConcurrentMap<? super T,java.lang.Boolean> map
A map that serves as a cache for previous matches.
-
-
Constructor Detail
-
CachingMatcher
public CachingMatcher(ElementMatcher<? super T> matcher, java.util.concurrent.ConcurrentMap<? super T,java.lang.Boolean> map)
Creates a new caching matcher.- Parameters:
matcher
- The underlying matcher to apply for non-cached targets.map
- A map that serves as a cache for previous matches. This match is strongly referenced and can cause a memory leak if it is not evicted while keeping this matcher alive.
-
-
Method Detail
-
matches
public boolean matches(T target)
Matches a target against this element matcher.- Parameters:
target
- The instance to be matched.- Returns:
true
if the given element is matched by this matcher orfalse
otherwise.
-
onCacheMiss
protected boolean onCacheMiss(T target)
Invoked if the cache is not hit.- Parameters:
target
- The element to be matched.- Returns:
true
if the element is matched.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-