| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
A class of predicates that evaluate to true or 
 false for an object.

The Predicate class is actually an implementation of the Strategy pattern. You can write code that works with predicates (e.g. filters, quantifiers,...) in general, and the user of that code can write the specific predicate.
This class evolved from the ForAll, 
 Exists, Counter and
 Filter classes (which will be deprecated
 soon). This class has the advantage that the predicate itself is reusable. 
 Using the classes mentioned above, you'd have to implement a predicate multiple 
 times if you wanted to use it for more than one type of operation. With the 
 Predicate class, you write the predicate once, and the client 
 can do with it whatever he/she wants.
 
The ForAll, 
 Exists, 
 Counter and 
 Filter classes are replaced by 
 instance methods of this class so they can be removed in the future. 
 The recommended use for operations that do not work on collections is to 
 use an internal iterator (like the forall,... method of this class) in the 
 objects that contain the information. This was not possible for collections
 since we don't have access to the source code, and so these methods are 
 put in this class.
Typically, this class will be used as an anonymous inner class as follows:
Predicate myPredicate = new AbstractPredicate() {
            /oo
             o also public behavior
             o
             o post postcondition;
             o/
            public boolean eval(Object o) throws MyException {
              //calculate boolean value
              //using the given object
            }
            public int nbSubPredicates() {
              // ...
            }
            public List getSubPredicates() {
              // ...
            }
          };
 AbstractPredicate implements all methods of this interface except for
 eval().
If your predicate does not throw an exception, you should use 
 TotalPredicate, so users
 of your predicate won't have to write try-catch constructions when no
 exceptions can be thrown.
In case your predicate doesn't wrap another one, use PrimitivePredicate. If it also doesn't throw 
 exceptions, extend PrimitiveTotalPredicate.
| Field Summary | |
| static java.lang.String | CVS_REVISION | 
| Method Summary | |
| abstract  int | count(java.util.Collection collection)Count the number of object in the given collection for which this Predicate evaluates to true. | 
| abstract  boolean | equals(java.lang.Object other)Check whether or not this Predicate equals another object | 
| abstract  boolean | eval(java.lang.Object object)Evaluate this Predicate for the given object. | 
| abstract  boolean | exists(java.util.Collection collection)Check wether or not the given collection contains an object for which this predicate evaluates to true. | 
| abstract  void | filter(java.util.Collection collection)Remove all objects for which this Predicate evaluates to falsefrom the given collection.
 If you want to remove all object for which this Predicate evaluates
 totrue, wrap aNotpredicate around this predicate, and
 perform the filter using that predicate. | 
| abstract  boolean | forall(java.util.Collection collection)Check wether or not this Predicate evaluates to truefor all object in the given collection. | 
| abstract  java.util.List | getSubPredicates()Return the subpredicates of this Predicate. | 
| abstract  int | nbSubPredicates()Return the size of this Predicate. | 
| Methods inherited from interface org.jutil.java.collections.CollectionOperator | 
| isValidElement | 
| Field Detail | 
public static final java.lang.String CVS_REVISION
| Method Detail | 
public abstract boolean eval(java.lang.Object object)
                      throws java.lang.Exception
object - The object for which this Predicate must be evaluated. In general,
        because collections can contain null, this might be null.
public abstract boolean exists(java.util.Collection collection)
                        throws java.util.ConcurrentModificationException,
                               java.lang.Exception
true.
collection - The collection which has to be searched for an object
        for which this Predicate evaluates to true.
public abstract boolean forall(java.util.Collection collection)
                        throws java.util.ConcurrentModificationException,
                               java.lang.Exception
true 
 for all object in the given collection.
collection - The collection of which one wants to know if all object
        evaluate to true for this Predicate.
public abstract int count(java.util.Collection collection)
                   throws java.util.ConcurrentModificationException,
                          java.lang.Exception
true.
collection - The collection for which the number of object evaluating to 
        true for this Predicate must be counted.
public abstract void filter(java.util.Collection collection)
                     throws java.util.ConcurrentModificationException,
                            java.lang.Exception
Remove all objects for which this Predicate evaluates to false
 from the given collection.
If you want to remove all object for which this Predicate evaluates
 to true, wrap a Not predicate around this predicate, and
 perform the filter using that predicate. For example:
 new Not(myPredicate).filter(collection);
 
collection - The collection to be filtered. public abstract java.util.List getSubPredicates()
public abstract boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - The object to compare this Predicate with.public abstract int nbSubPredicates()
| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||