@ReplacedBy(value="com.google.common.base.Predicate") public abstract class Predicate<T> extends Object
public Iterator<PeanutButter> findBestKinds (Collection<PeanutButter> pbs)
{
return new Predicate<PeanutButter>() {
public boolean isMatch (PeanutButter pb)
{
return pb.isCreamy() && !pb.containsPartiallyHydrogenatedOils();
}
}.filter(pbs.iterator());
}
An interface like this may someday be in the Java library, but until then...Modifier and Type | Class and Description |
---|---|
static class |
Predicate.And<T>
Includes an object if and only if all the predicates with which it
was constructed also include the object.
|
static class |
Predicate.InstanceOf<T>
A simple predicate that includes an object if it is an instance
of the specified class.
|
static class |
Predicate.Not<T>
Negates any other predicate.
|
static class |
Predicate.Or<T>
Includes an object if at least one of the predicates specified in the
constructor include the object.
|
Constructor and Description |
---|
Predicate() |
Modifier and Type | Method and Description |
---|---|
<E extends T> |
createView(Collection<E> input)
Create a view of the specified collection that only contains elements
that match the predicate.
|
<E extends T> |
createView(Iterable<E> input)
Create an Iterable view of the specified Iterable that only contains
elements that match the predicate.
|
static <T> Predicate<T> |
falseInstance()
Returns a type-safe reference to the shared instance of a predicate that always returns
false . |
<E extends T> |
filter(Collection<E> coll)
Remove non-matching elements from the specified collection.
|
<E extends T> |
filter(Iterator<E> input)
Return a new iterator that contains only matching elements from
the input iterator.
|
abstract boolean |
isMatch(T obj)
Does the specified object belong to the special set that we test for?
|
static <T> Predicate<T> |
trueInstance()
Returns a type-safe reference to the shared instance of a predicate that always returns
true . |
public static <T> Predicate<T> trueInstance()
true
.public static <T> Predicate<T> falseInstance()
false
.public abstract boolean isMatch(T obj)
public <E extends T> Iterator<E> filter(Iterator<E> input)
public <E extends T> void filter(Collection<E> coll)
public <E extends T> Iterable<E> createView(Iterable<E> input)
public <E extends T> Collection<E> createView(Collection<E> input)
Copyright © 2015. All rights reserved.