Sofia API Reference

  • Package Index
  • Class Index
  • Packages
  • sofia.app
  • sofia.content
  • sofia.data
  • sofia.graphics
    • Interfaces
    • Joint
    • PropertyTransformer
    • Classes
    • AbstractJoint
    • Anchor
    • Color
    • CoordinateSystem
    • DirectionalPad
    • DistanceJoint
    • ElasticInInterpolator
    • ElasticInOutInterpolator
    • ElasticOutInterpolator
    • FillableShape
    • FillableShape.Animator
    • Geometry
    • Image
    • LineShape
    • MotionStep
    • OvalShape
    • PointAndAnchor
    • Polygon
    • PolygonShape
    • Predicate
    • RectangleShape
    • RevoluteJoint
    • Shape
    • Shape.Animator
    • Shape.Filter
    • ShapeField
    • ShapeFilter
    • ShapeSet
    • ShapeView
    • SizeF
    • StrokedShape
    • StrokedShape.Animator
    • TextShape
    • TextShape.Animator
    • Timings
    • ViewEdges
    • ZIndexComparator
    • Enums
    • RepeatMode
    • ShapeMotion
  • sofia.util
  • sofia.view
  • sofia.widget

public abstract class
Predicate

extends Object

Inheritance

  • java.lang.Object
    • sofia.graphics.Predicate<T>

Class Overview

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(...);
 


Summary

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)

Public Constructors

public Predicate ()


Public Methods

public 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.

Parameters
value
the value to accept or reject
Returns

true if the predicate accepts the value, otherwise false

public static final 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.

Parameters
lowerBound
the lower bound
upperBound
the upper bound
Returns

a predicate that evaluates to true for numeric values between (and including) the specified lower and upper bounds

public static final Predicate<T> equalTo (T target)

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.

Parameters
target
the target value
Returns

a predicate that evaluates to true for values equal to a specified target value

public static final 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. 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.

Returns

a predicate that evaluates to true for class that extend (or are the same as) the specified class

public static final 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. 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.

Returns

a predicate that evaluates to true for class that extend (or are the same as) the specified class

public static final Predicate<Number> greaterThan (Number lowerBound)

Returns a predicate that evaluates to true for numeric values greater than the specified lower bound.

Parameters
lowerBound
the lower bound
Returns

a predicate that evaluates to true for numeric values greater than the specified lower bound

public static final Predicate<Number> greaterThanOrEqualTo (Number lowerBound)

Returns a predicate that evaluates to true for numeric values greater than or equal to the specified lower bound.

Parameters
lowerBound
the lower bound
Returns

a predicate that evaluates to true for numeric values greater than or equal to the specified lower bound

public static final Predicate<Number> lessThan (Number upperBound)

Returns a predicate that evaluates to true for numeric values less than the specified upper bound.

Parameters
upperBound
the upper bound
Returns

a predicate that evaluates to true for numeric values less than the specified upper bound

public static final Predicate<Number> lessThanOrEqualTo (Number upperBound)

Returns a predicate that evaluates to true for numeric values less than or equal to the specified upper bound.

Parameters
upperBound
the upper bound
Returns

a predicate that evaluates to true for numeric values less than or equal to the specified upper bound

public static final Predicate<T> notEqualTo (T target)

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.

Parameters
target
the target value
Returns

a predicate that evaluates to true for values not equal to a specified target value

public abstract String toString ()

Subclasses must override toString to provide a human readable description of the predicate.

Returns

a human readable description of the predicate