@FunctionalInterface public interface NodeEqualityPredicate
Recall that Nodes have 4 key attributes: key, value, context, expiry.
In the default Node.equals(Object) implementation (equivalent to EXACT),
all 4 of these key attributes are considered. However, there are occasions where such strict
equality checking is not desired, hence the use of this class.
NodeEqualityPredicates can either be used inline, by directly calling the
areEqual(Node, Node) method, or can be passed as a parameter to the
Node.equals(Node, NodeEqualityPredicate) method. Either approach is valid, and both will
result in the same result.
Generally, implementations of this interface should fulfil the same
requirements as the Object.equals(Object) contract.
| Modifier and Type | Field and Description |
|---|---|
static NodeEqualityPredicate |
EXACT
Represents an exact match.
|
static NodeEqualityPredicate |
IGNORE_EXPIRY_TIME
All attributes must match, except for the
expiry time, which is
ignored. |
static NodeEqualityPredicate |
IGNORE_EXPIRY_TIME_AND_VALUE
All attributes must match, except for
value and the
expiry time, which are ignored. |
static NodeEqualityPredicate |
IGNORE_VALUE
All attributes must match, except for
value, which is ignored. |
static NodeEqualityPredicate |
IGNORE_VALUE_OR_IF_TEMPORARY
All attributes must match, except for
value and the if the node
has an expiry, which are ignored. |
static NodeEqualityPredicate |
ONLY_KEY
Only the
keys need match, all other attributes are ignored. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
areEqual(@NonNull Node o1,
@NonNull Node o2)
Returns if the two nodes are equal.
|
default Predicate<Node> |
equalTo(Node node)
Returns a
Predicate, returning true if the tested node is equal
to the one given, according to the NodeEqualityPredicate. |
static final NodeEqualityPredicate EXACT
Returns true if: (and)
All 4 attributes of the nodes must match to be considered equal.
This is the default form of equality, used by Node.equals(Object).
static final NodeEqualityPredicate ONLY_KEY
keys need match, all other attributes are ignored.static final NodeEqualityPredicate IGNORE_VALUE
static final NodeEqualityPredicate IGNORE_EXPIRY_TIME
expiry time, which is
ignored.
Note that with this setting, whether a node has an expiry or not is still considered.
Returns true if: (and)
key = keyvalue = valuecontext = contexthas expiry = has expirystatic final NodeEqualityPredicate IGNORE_EXPIRY_TIME_AND_VALUE
value and the
expiry time, which are ignored.
Note that with this setting, whether a node has an expiry or not is still considered.
Returns true if: (and)
key = keycontext = contexthas expiry = has expirystatic final NodeEqualityPredicate IGNORE_VALUE_OR_IF_TEMPORARY
value and the if the node
has an expiry, which are ignored.
Effectively only considers the key and the context.
Returns true if: (and)
boolean areEqual(@NonNull Node o1, @NonNull Node o2)
This method should avoid making calls to Node.equals(Node, NodeEqualityPredicate)
with this as the second argument, directly or otherwise.
o1 - the first nodeo2 - the second nodedefault Predicate<Node> equalTo(Node node)
Predicate, returning true if the tested node is equal
to the one given, according to the NodeEqualityPredicate.node - the given node