01: // ============================================================================
02: // $Id: LogicalOr.java,v 1.12 2006/01/08 00:52:25 davidahall Exp $
03: // Copyright (c) 2002-2005 David A. Hall
04: // ============================================================================
05: // The contents of this file are subject to the Common Development and
06: // Distribution License (CDDL), Version 1.0 (the License); you may not use this
07: // file except in compliance with the License. You should have received a copy
08: // of the the License along with this file: if not, a copy of the License is
09: // available from Sun Microsystems, Inc.
10: //
11: // http://www.sun.com/cddl/cddl.html
12: //
13: // From time to time, the license steward (initially Sun Microsystems, Inc.) may
14: // publish revised and/or new versions of the License. You may not use,
15: // distribute, or otherwise make this file available under subsequent versions
16: // of the License.
17: //
18: // Alternatively, the contents of this file may be used under the terms of the
19: // GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
20: // case the provisions of the LGPL are applicable instead of those above. If you
21: // wish to allow use of your version of this file only under the terms of the
22: // LGPL, and not to allow others to use your version of this file under the
23: // terms of the CDDL, indicate your decision by deleting the provisions above
24: // and replace them with the notice and other provisions required by the LGPL.
25: // If you do not delete the provisions above, a recipient may use your version
26: // of this file under the terms of either the CDDL or the LGPL.
27: //
28: // This library is distributed in the hope that it will be useful,
29: // but WITHOUT ANY WARRANTY; without even the implied warranty of
30: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31: // ============================================================================
32:
33: package net.sf.jga.fn.logical;
34:
35: import net.sf.jga.fn.BinaryPredicate;
36:
37: /**
38: * Binary Predicate that returns true when either of Boolean arguments <b>x</b>
39: * and <b>y</b> are true.
40: * <p>
41: * Note that this functor does <i>not</i> short circuit the evaluation
42: * of the second argument. The reason for this is that, by itself,
43: * this functor accepts only boolean arguments. When it is used in
44: * conjunction with the adaptor functors to implement compound
45: * functors, the adaptor cannot know that the functor it is adapting
46: * may not need to use both arguments, so the adaptor will fully
47: * evaluate both arguments before passing them to the And functor.
48: * This would give the illusion that the short circuit logic is
49: * broken, when it is in fact unimplementable using the standard
50: * functor mechanism.
51: * <p>
52: * Copyright © 2002-2005 David A. Hall
53: *
54: * @author <a href="mailto:davidahall@users.sourceforge.net">David A. Hall</a>
55: **/
56:
57: public class LogicalOr extends BinaryPredicate<Boolean, Boolean> {
58:
59: static final long serialVersionUID = -5329467559457020210L;
60:
61: // BinaryPredicate interface
62:
63: /**
64: * Given Boolean arguments <b>x</b> and <b>y</b>, returns true when either
65: * x and y are true, otherwise false.
66: *
67: * @return x | y
68: */
69: public Boolean fn(Boolean x, Boolean y) {
70: return x | y;
71: }
72:
73: /**
74: * Calls the Visitor's <code>visit(LogicalOr)</code> method, if it
75: * implements the nested Visitor interface.
76: */
77: public void accept(net.sf.jga.fn.Visitor v) {
78: if (v instanceof LogicalOr.Visitor)
79: ((LogicalOr.Visitor) v).visit(this );
80: else
81: v.visit(this );
82: }
83:
84: // Object overrides
85:
86: public String toString() {
87: return "LogicalOr";
88: }
89:
90: // AcyclicVisitor
91:
92: /**
93: * Interface for classes that may interpret a <b>LogicalOr</b>
94: * predicate.
95: */
96: public interface Visitor extends net.sf.jga.fn.Visitor {
97: public void visit(LogicalOr bp);
98: }
99: }
|