KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

34     public XorPredicate(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         boolean val = false;
46         Iterator JavaDoc iter = m_clauses.iterator();
47         if ( iter.hasNext() ) {
48             val = ((Predicate)iter.next()).getBoolean(t);
49         }
50         while ( iter.hasNext() ) {
51             val ^= ((Predicate)iter.next()).getBoolean(t);
52         }
53         return val;
54     }
55     
56     /**
57      * @see java.lang.Object#toString()
58      */

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