KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > data > expression > AndPredicate


1 package prefuse.data.expression;
2
3 import java.util.Iterator JavaDoc;
4
5 import prefuse.data.Tuple;
6
7 /**
8  * Predicate representing an "and" clause of sub-predicates.
9  *
10  * @author <a HREF="http://jheer.org">jeffrey heer</a>
11  */

12 public class AndPredicate extends CompositePredicate {
13     
14     /**
15      * Create an empty AndPredicate. Empty AndPredicates return false
16      * by default.
17      */

18     public AndPredicate() {
19     }
20     
21     /**
22      * Create a new AndPredicate.
23      * @param p1 the sole clause of this predicate
24      */

25     public AndPredicate(Predicate p1) {
26         add(p1);
27     }
28     
29     /**
30      * Create a new AndPredicate.
31      * @param p1 the first clause of this predicate
32      * @param p2 the second clause of this predicate
33      */

34     public AndPredicate(Predicate p1, Predicate p2) {
35         super(p1, p2);
36     }
37     
38     /**
39      * @see prefuse.data.expression.Expression#getBoolean(prefuse.data.Tuple)
40      */

41     public boolean getBoolean(Tuple t) {
42         if ( m_clauses.size() == 0 )
43             return false;
44         
45         Iterator JavaDoc iter = m_clauses.iterator();
46         while ( iter.hasNext() ) {
47             Predicate p = (Predicate)iter.next();
48             if ( !p.getBoolean(t) ) {
49                 return false;
50             }
51         }
52         return true;
53     }
54     
55     /**
56      * @see java.lang.Object#toString()
57      */

58     public String JavaDoc toString() {
59         return ( size() == 0 ? "FALSE" : toString("AND") );
60     }
61
62 } // end of class AndPredicate
63
Popular Tags