Predicates are used to specify numeric (and other) criteria when filtering shapes. For example, it doesn't make sense to filter shapes that have a velocity of exactly 3 (because velocity is a rapidly changing floating-point value), but rather to find all the shapes with a velocity of 3 or higher.
This class defines static factory methods for several commonly used numeric
comparisons. The easiest way to use them is to do a static import
:
import static sofia.graphics.Predicate.*;
Then, you can call the methods inside a filter chain without having to use the class name as a prefix:
getShapes().withLinearVelocity(greaterThan(3)).withColor(...);
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Predicate()
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract
boolean
|
accept(T value)
Subclasses of
Predicate must override this method and return
true if the predicate accepts the specified value or false if it rejects
it. | ||||||||||
final
static
Predicate<Number>
|
between(Number lowerBound, Number upperBound)
Returns a predicate that evaluates to true for numeric values between
(and including) the specified lower and upper bounds.
| ||||||||||
final
static
<T>
Predicate<T>
|
equalTo(T target)
Returns a predicate that evaluates to true for values equal to a
specified target value.
| ||||||||||
final
static
<T>
Predicate<Class<? extends T>>
|
equalTo(Class<? extends T> theClass)
Returns a predicate that evaluates to true for classes that extend (or are the same as) the specified class. | ||||||||||
final
static
<T>
Predicate<Class<? extends T>>
|
extending(Class<? extends T> theClass)
Returns a predicate that evaluates to true for classes that extend (or are the same as) the specified class. | ||||||||||
final
static
Predicate<Number>
|
greaterThan(Number lowerBound)
Returns a predicate that evaluates to true for numeric values greater
than the specified lower bound.
| ||||||||||
final
static
Predicate<Number>
|
greaterThanOrEqualTo(Number lowerBound)
Returns a predicate that evaluates to true for numeric values greater
than or equal to the specified lower bound.
| ||||||||||
final
static
Predicate<Number>
|
lessThan(Number upperBound)
Returns a predicate that evaluates to true for numeric values less than
the specified upper bound.
| ||||||||||
final
static
Predicate<Number>
|
lessThanOrEqualTo(Number upperBound)
Returns a predicate that evaluates to true for numeric values less than
or equal to the specified upper bound.
| ||||||||||
final
static
<T>
Predicate<T>
|
notEqualTo(T target)
Returns a predicate that evaluates to true for values not equal to a
specified target value.
| ||||||||||
abstract
String
|
toString()
Subclasses must override
toString to provide a
human readable description of the predicate. |
Methods inherited from
class
java.lang.Object
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Object
|
clone()
| ||||||||||
boolean
|
equals(Object arg0)
| ||||||||||
void
|
finalize()
| ||||||||||
final
Class<?>
|
getClass()
| ||||||||||
int
|
hashCode()
| ||||||||||
final
void
|
notify()
| ||||||||||
final
void
|
notifyAll()
| ||||||||||
String
|
toString()
| ||||||||||
final
void
|
wait()
| ||||||||||
final
void
|
wait(long arg0, int arg1)
| ||||||||||
final
void
|
wait(long arg0)
|
Subclasses of Predicate
must override this method and return
true if the predicate accepts the specified value or false if it rejects
it.
true if the predicate accepts the value, otherwise false
Returns a predicate that evaluates to true for numeric values between (and including) the specified lower and upper bounds.
a predicate that evaluates to true for numeric values between (and including) the specified lower and upper bounds
Returns a predicate that evaluates to true for values equal to a specified target value. If the values being compared are floating-point numbers, then they return equal if the difference between them is within a tolerance of 10-6.
a predicate that evaluates to true for values equal to a specified target value
Returns a predicate that evaluates to true for classes that extend (or
are the same as) the specified class. Note that allowing matches of the
class type itself and not just "strict" subclasses is consistent with
the behavior of Java generics, where the type parameter
<T extends X>
can be satisfied not only by subclasses of
X
but also by X
itself.
To find only exact matches and exclude subclasses, use
the equalTo(Object)
predicate instead.
a predicate that evaluates to true for class that extend (or are the same as) the specified class
Returns a predicate that evaluates to true for classes that extend (or
are the same as) the specified class. Note that allowing matches of the
class type itself and not just "strict" subclasses is consistent with
the behavior of Java generics, where the type parameter
<T extends X>
can be satisfied not only by subclasses of
X
but also by X
itself.
To find only exact matches and exclude subclasses, use
the equalTo(Object)
predicate instead.
a predicate that evaluates to true for class that extend (or are the same as) the specified class
Returns a predicate that evaluates to true for numeric values greater than the specified lower bound.
a predicate that evaluates to true for numeric values greater than the specified lower bound
Returns a predicate that evaluates to true for numeric values greater than or equal to the specified lower bound.
a predicate that evaluates to true for numeric values greater than or equal to the specified lower bound
Returns a predicate that evaluates to true for numeric values less than the specified upper bound.
a predicate that evaluates to true for numeric values less than the specified upper bound
Returns a predicate that evaluates to true for numeric values less than or equal to the specified upper bound.
a predicate that evaluates to true for numeric values less than or equal to the specified upper bound
Returns a predicate that evaluates to true for values not equal to a specified target value. If the values being compared are floating-point numbers, then they return not equal if the difference between them is greater than a tolerance of 10-6.
a predicate that evaluates to true for values not equal to a specified target value
Subclasses must override toString
to provide a
human readable description of the predicate.
a human readable description of the predicate