public class InstanceFilter<T> extends Object
Subclasses may want to override match(Object, Object)
to provide
a custom matching algorithm.
Constructor and Description |
---|
InstanceFilter(Collection<? extends T> includes,
Collection<? extends T> excludes,
boolean matchIfEmpty)
Create a new instance based on includes/excludes collections.
|
Modifier and Type | Method and Description |
---|---|
boolean |
match(T instance)
Determine if the specified {code instance} matches this filter.
|
protected boolean |
match(T instance,
Collection<? extends T> candidates)
Determine if the specified
instance matches one of the candidates. |
protected boolean |
match(T instance,
T candidate)
Determine if the specified
instance is equal to the
specified candidate . |
String |
toString() |
public InstanceFilter(Collection<? extends T> includes, Collection<? extends T> excludes, boolean matchIfEmpty)
A particular element will match if it "matches" the one of the element in the includes list and does not match one of the element in the excludes list.
Subclasses may redefine what matching means. By default, an element match with
another if it is equals according to Object.equals(Object)
If both collections are empty, matchIfEmpty
defines if
an element matches or not.
includes
- the collection of includesexcludes
- the collection of excludesmatchIfEmpty
- the matching result if both the includes and the excludes
collections are emptypublic boolean match(T instance)
protected boolean match(T instance, T candidate)
instance
is equal to the
specified candidate
.instance
- the instance to handlecandidate
- a candidate defined by this filtertrue
if the instance matches the candidateprotected boolean match(T instance, Collection<? extends T> candidates)
instance
matches one of the candidates.
If the candidates collection is null
, returns false
.
instance
- the instance to checkcandidates
- a list of candidatestrue
if the instance match or the candidates collection is null