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.
@FunctionalInterface public interface NodeEqualityPredicate
An equality test for determining if two nodes are to be considered equal.Recall that
Nodes have 4 key attributes: key, value, context, expiry.In the default
Node.equals(Object)implementation (equivalent toEXACT), 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 theareEqual(Node, Node)method, or can be passed as a parameter to theNode.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
Fields Modifier and Type Field Description static NodeEqualityPredicateEXACTRepresents an exact match.static NodeEqualityPredicateIGNORE_EXPIRY_TIMEAll attributes must match, except for theexpiry time, which is ignored.static NodeEqualityPredicateIGNORE_EXPIRY_TIME_AND_VALUEAll attributes must match, except forvalueand theexpiry time, which are ignored.static NodeEqualityPredicateIGNORE_VALUEAll attributes must match, except forvalue, which is ignored.static NodeEqualityPredicateIGNORE_VALUE_OR_IF_TEMPORARYAll attributes must match, except forvalueand the if the nodehas an expiry, which are ignored.static NodeEqualityPredicateONLY_KEYOnly thekeys need match, all other attributes are ignored.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleanareEqual(@NonNull Node o1, @NonNull Node o2)Returns if the two nodes are equal.default Predicate<Node>equalTo(Node node)Returns aPredicate, returning true if the tested node is equal to the one given, according to theNodeEqualityPredicate.
-
-
-
Field Detail
-
EXACT
static final NodeEqualityPredicate 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
static final NodeEqualityPredicate ONLY_KEY
Only thekeys need match, all other attributes are ignored.
-
IGNORE_VALUE
static final NodeEqualityPredicate IGNORE_VALUE
-
IGNORE_EXPIRY_TIME
static final NodeEqualityPredicate 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
static final NodeEqualityPredicate 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
static final NodeEqualityPredicate 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 Detail
-
areEqual
boolean areEqual(@NonNull Node o1, @NonNull Node o2)
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
default Predicate<Node> equalTo(Node node)
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
-
-