Class InstanceFilter<T>

java.lang.Object
org.springframework.util.InstanceFilter<T>
Type Parameters:
T - the instance type
Direct Known Subclasses:
ExceptionTypeFilter

public class InstanceFilter<T> extends Object
A simple instance filter that checks if a given instance matches based on collections of includes and excludes.

Subclasses may override match(Object, Object) to provide a custom matching algorithm.

Since:
4.1
Author:
Stephane Nicoll, Sam Brannen
  • Field Details

    • includes

      protected final Collection<? extends T> includes
    • excludes

      protected final Collection<? extends T> excludes
    • matchIfEmpty

      protected final boolean matchIfEmpty
  • Constructor Details

    • InstanceFilter

      public InstanceFilter(@nullable Collection<? extends T> includes, @nullable Collection<? extends T> excludes)
      Create a new InstanceFilter based on include and exclude collections, with the matchIfEmpty flag set to true.

      See InstanceFilter(Collection, Collection, boolean) for details.

      Parameters:
      includes - the collection of includes
      excludes - the collection of excludes
      Since:
      7.0
    • InstanceFilter

      public InstanceFilter(@nullable Collection<? extends T> includes, @nullable Collection<? extends T> excludes, boolean matchIfEmpty)
      Create a new InstanceFilter based on include and exclude collections.

      A particular element will match if it matches one of the elements in the includes list and does not match one of the elements in the excludes list.

      Subclasses may redefine what matching means. By default, an element matches another if the two elements are equal.

      If both collections are empty, matchIfEmpty defines if an element matches or not.

      Parameters:
      includes - the collection of includes
      excludes - the collection of excludes
      matchIfEmpty - the matching result if the includes and the excludes collections are both null or empty
  • Method Details

    • match

      public boolean match(T instance)
      Determine if the specified instance matches this filter.
    • match

      protected boolean match(T instance, T candidate)
      Determine if the specified instance matches the specified candidate.

      By default, the two instances match if they are equal.

      Can be overridden by subclasses.

      Parameters:
      instance - the instance to check
      candidate - a candidate defined by this filter
      Returns:
      true if the instance matches the candidate
    • match

      protected boolean match(T instance, Collection<? extends T> candidates)
      Determine if the specified instance matches one of the candidates.
      Parameters:
      instance - the instance to check
      candidates - the collection of candidates
      Returns:
      true if the instance matches; false if the candidates collection is empty or there is no match
    • toString

      public String toString()
      Overrides:
      toString in class Object