Interface NodeEqualityPredicate
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final NodeEqualityPredicateRepresents an exact match.static final NodeEqualityPredicateAll attributes must match, except for theexpiry time, which is ignored.static final NodeEqualityPredicateAll attributes must match, except forvalueand theexpiry time, which are ignored.static final NodeEqualityPredicateAll attributes must match, except forvalue, which is ignored.static final NodeEqualityPredicateAll attributes must match, except forvalueand the if the nodehas an expiry, which are ignored.static final NodeEqualityPredicateOnly thekeys need match, all other attributes are ignored. -
Method Summary
-
Field Details
-
EXACT
Represents an exact match.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). -
ONLY_KEY
Only thekeys need match, all other attributes are ignored. -
IGNORE_VALUE
-
IGNORE_EXPIRY_TIME
All attributes must match, except for theexpiry 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 expiry
-
IGNORE_EXPIRY_TIME_AND_VALUE
All attributes must match, except forvalueand theexpiry 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 expiry
-
IGNORE_VALUE_OR_IF_TEMPORARY
All attributes must match, except forvalueand the if the nodehas an expiry, which are ignored.Effectively only considers the key and the context.
Returns true if: (and)
-
-
Method Details
-
areEqual
Returns if the two nodes are equal.This method should avoid making calls to
Node.equals(Node, NodeEqualityPredicate)withthisas the second argument, directly or otherwise.- Parameters:
o1- the first nodeo2- the second node- Returns:
- true if equal
-
equalTo
Returns aPredicate, returning true if the tested node is equal to the one given, according to theNodeEqualityPredicate.- Parameters:
node- the given node- Returns:
- a predicate
-