@FunctionalInterface
public interface NodeFilter
Node
, based on some criterion.
You may use a concrete implementation of this interface in combination with the static methods provided.
Some of the static methods take an instance of Node
as their first parameter argument and an instance of NodeFilter
as their second and returns a List
with the Node
s that satisfies said
criterion.
Modifier and Type | Method and Description |
---|---|
static NodeFilter |
and(NodeFilter... nodeFilters)
|
static NodeFilter |
any()
Returns a
NodeFilter that accepts any Node . |
static java.util.List<Node> |
filter(Node node)
Returns a
List with all Node s. |
static java.util.List<Node> |
filter(Node node,
NodeFilter nodeFilter)
|
static <T extends Node> |
filter(Node node,
NodeFilter nodeFilter,
java.lang.Class<T> clazz)
Returns a
List with the Node s that satisfies the criterion specified by nodeFilter , but only if they are assignment compatible to clazz . |
boolean |
isAccepted(Node node)
Returns
true if, and only if, node is accepted, false otherwise. |
static NodeFilter |
or(NodeFilter... nodeFilters)
Returns a
NodeFilter that accepts all Node s that are accepted by at least one of the aggregated NodeFilter s. |
static NodeFilter |
regex(java.lang.String regex)
Returns a
NodeFilter that accepts all Node s that have a toString() method that matches the given Regex. |
boolean isAccepted(Node node)
true
if, and only if, node
is accepted, false
otherwise.
If node
is null
, a NullPointerException
may be thrown. But no guarantees can be made.
node
- the Node
to accept or rejecttrue
if, and only if, node
is accepted, false
otherwisejava.lang.NullPointerException
- thrown if, and only if, node
is null
static NodeFilter and(NodeFilter... nodeFilters)
NodeFilter
that accepts all Node
s that are accepted by all of the aggregated NodeFilter
s.
This means that this NodeFilter
does not on its own contain any filtering logic. The logic that determines whether a Node
is accepted or rejected, is fully up to the aggregated NodeFilter
s.
When isAccepted(Node)
is called, it iterates over the aggregated NodeFilter
s until either one of them rejects the Node
, in which case false
is returned, or all of them accepts, in
which case true
is returned.
If either nodeFilters
, or at least one of its elements are null
, a NullPointerException
will be thrown.
The NodeFilter
returned by this method will throw a NullPointerException
if, and only if, the Node
to accept or reject is null
.
nodeFilters
- the aggregated NodeFilter
s that make up the filtering logicNodeFilter
that accepts all Node
s that are accepted by all of the aggregated NodeFilter
sjava.lang.NullPointerException
- thrown if, and only if, either nodeFilters
, or at least one of its elements are null
static NodeFilter any()
NodeFilter
that accepts any Node
.
The NodeFilter
returned by this method will throw a NullPointerException
if, and only if, the Node
to accept or reject is null
.
NodeFilter
that accepts any Node
static NodeFilter or(NodeFilter... nodeFilters)
NodeFilter
that accepts all Node
s that are accepted by at least one of the aggregated NodeFilter
s.
This means that this NodeFilter
does not on its own contain any filtering logic. The logic that determines whether a Node
is accepted or rejected, is fully up to the aggregated NodeFilter
s.
When isAccepted(Node)
is called, it iterates over the aggregated NodeFilter
s until either one of them accepts the Node
, in which case true
is returned, or none of them does, in which
case false
is returned.
If either nodeFilters
, or at least one of its elements are null
, a NullPointerException
will be thrown.
The NodeFilter
returned by this method will throw a NullPointerException
if, and only if, the Node
to accept or reject is null
.
nodeFilters
- the aggregated NodeFilter
s that make up the filtering logicNodeFilter
that accepts all Node
s that are accepted by at least one of the aggregated NodeFilter
sjava.lang.NullPointerException
- thrown if, and only if, either nodeFilters
, or at least one of its elements are null
static NodeFilter regex(java.lang.String regex)
NodeFilter
that accepts all Node
s that have a toString()
method that matches the given Regex.
If regex
is null
, a NullPointerException
will be thrown.
The NodeFilter
returned by this method will throw a NullPointerException
if, and only if, the Node
to accept or reject is null
.
regex
- a String
representing the Regex to be used in the filtering processNodeFilter
that accepts all Node
s that have a toString()
method that matches the given Regexjava.lang.NullPointerException
- thrown if, and only if, regex
is null
static java.util.List<Node> filter(Node node)
List
with all Node
s.
All Node
s are found by traversing node
using a simple NodeHierarchicalVisitor
implementation.
If node
is null
, a NullPointerException
will be thrown.
node
- the Node
to start traversal fromList
with all Node
sjava.lang.NullPointerException
- thrown if, and only if, node
is null
static java.util.List<Node> filter(Node node, NodeFilter nodeFilter)
List
with the Node
s that satisfies the criterion specified by nodeFilter
.
All Node
s are found by traversing node
using a simple NodeHierarchicalVisitor
implementation.
If either node
or nodeFilter
are null
, a NullPointerException
will be thrown.
node
- the Node
to start traversal fromnodeFilter
- the NodeFilter
to accept or reject Node
sList
with the Node
s that satisfies the criterion specified by nodeFilter
java.lang.NullPointerException
- thrown if, and only if, either node
or nodeFilter
are null
static <T extends Node> java.util.List<T> filter(Node node, NodeFilter nodeFilter, java.lang.Class<T> clazz)
List
with the Node
s that satisfies the criterion specified by nodeFilter
, but only if they are assignment compatible to clazz
.
The List
returned will be cast to the Class
specified by clazz
.
All Node
s are found by traversing node
using a simple NodeHierarchicalVisitor
implementation.
If either node
, nodeFilter
or clazz
are null
, a NullPointerException
will be thrown.
T
- the type the List
should be cast tonode
- the Node
to start traversal fromnodeFilter
- the NodeFilter
to accept or reject Node
sclazz
- the Class
that is of the type T
List
with the Node
s that satisfies the criterion specified by nodeFilter
, but only if they are assignment compatible to clazz
java.lang.NullPointerException
- thrown if, and only if, either node
, nodeFilter
or clazz
are null