Class 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.
  • Field Details

  • Constructor Details

    • CachingMatcher

      public CachingMatcher(ElementMatcher<? super T> matcher, ConcurrentMap<? super T,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 Details

    • 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 or false 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 String toString()
      Overrides:
      toString in class Object