KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > constraint > Or


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package org.jmock.core.constraint;
4
5 import org.jmock.core.Constraint;
6
7
8 /**
9  * Calculates the logical disjunction of two constraints. Evaluation is
10  * shortcut, so that the second constraint is not called if the first
11  * constraint returns <code>true</code>.
12  */

13 public class Or implements Constraint
14 {
15     Constraint left, right;
16
17     public Or( Constraint left, Constraint right ) {
18         this.left = left;
19         this.right = right;
20     }
21
22     public boolean eval( Object JavaDoc o ) {
23         return left.eval(o) || right.eval(o);
24     }
25
26     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
27         buffer.append("(");
28         left.describeTo(buffer);
29         buffer.append(" or ");
30         right.describeTo(buffer);
31         buffer.append(")");
32         return buffer;
33     }
34 }
35
Popular Tags