01: package prefuse.data.expression;
02:
03: import java.util.Iterator;
04:
05: import prefuse.data.Tuple;
06:
07: /**
08: * Predicate representing an "or" clause of sub-predicates.
09: *
10: * @author <a href="http://jheer.org">jeffrey heer</a>
11: */
12: public class OrPredicate extends CompositePredicate {
13:
14: /**
15: * Create an empty OrPredicate. Empty OrPredicates return false
16: * by default.
17: */
18: public OrPredicate() {
19: }
20:
21: /**
22: * Create a new OrPredicate.
23: * @param p1 the sole clause of this predicate
24: */
25: public OrPredicate(Predicate p1) {
26: add(p1);
27: }
28:
29: /**
30: * Create a new OrPredicate.
31: * @param p1 the first clause of this predicate
32: * @param p2 the second clause of this predicate
33: */
34: public OrPredicate(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 iter = m_clauses.iterator();
46: while (iter.hasNext()) {
47: Predicate p = (Predicate) iter.next();
48: if (p.getBoolean(t)) {
49: return true;
50: }
51: }
52: return false;
53: }
54:
55: /**
56: * @see java.lang.Object#toString()
57: */
58: public String toString() {
59: return (size() == 0 ? "FALSE" : toString("OR"));
60: }
61:
62: } // end of class OrPredicate
|