T
- type of object the predicate can evaluate in memory.public abstract class Predicate<T>
extends java.lang.Object
Implementations should be immutable, such that the meaning of a predicate never changes once constructed. They should ensure their immutable promise by defensively copying any structures which might be modified externally, but was passed into the object's constructor.
However, implementations may retain non-thread-safe caches internally,
to speed up evaluation operations within the context of one thread's
evaluation of the predicate. As a result, callers should assume predicates
are not thread-safe, but that two predicate graphs produce the same results
given the same inputs if they are equals(Object)
.
Predicates should support deep inspection whenever possible, so that generic
algorithms can be written to operate against them. Predicates which contain
other predicates should override getChildren()
to return the list of
children nested within the predicate.
Constructor and Description |
---|
Predicate() |
Modifier and Type | Method and Description |
---|---|
static <T> Predicate<T> |
and(java.util.Collection<? extends Predicate<T>> that)
Combine the passed predicates into a single AND node.
|
static <T> Predicate<T> |
and(Predicate<T>... that)
Combine the passed predicates into a single AND node.
|
static <T> Predicate<T> |
any()
A predicate that matches any input, always, with no cost.
|
Matchable<T> |
asMatchable() |
abstract Predicate<T> |
copy(java.util.Collection<? extends Predicate<T>> children)
Create a copy of this predicate, with new children.
|
abstract boolean |
equals(java.lang.Object other) |
int |
estimateCost() |
Predicate<T> |
getChild(int i)
Same as
getChildren().get(i) |
int |
getChildCount()
Same as
getChildren().size() |
java.util.List<Predicate<T>> |
getChildren()
Get the children of this predicate, if any.
|
abstract int |
hashCode() |
boolean |
isMatchable() |
static <T> Predicate<T> |
not(Predicate<T> that)
Invert the passed node.
|
static <T> Predicate<T> |
or(java.util.Collection<? extends Predicate<T>> that)
Combine the passed predicates into a single OR node.
|
static <T> Predicate<T> |
or(Predicate<T>... that)
Combine the passed predicates into a single OR node.
|
public static <T> Predicate<T> any()
@SafeVarargs public static <T> Predicate<T> and(Predicate<T>... that)
public static <T> Predicate<T> and(java.util.Collection<? extends Predicate<T>> that)
@SafeVarargs public static <T> Predicate<T> or(Predicate<T>... that)
public static <T> Predicate<T> or(java.util.Collection<? extends Predicate<T>> that)
public java.util.List<Predicate<T>> getChildren()
public int getChildCount()
getChildren().size()
public abstract Predicate<T> copy(java.util.Collection<? extends Predicate<T>> children)
public boolean isMatchable()
public int estimateCost()
public abstract int hashCode()
hashCode
in class java.lang.Object
public abstract boolean equals(java.lang.Object other)
equals
in class java.lang.Object