001: // ============================================================================
002: // $Id: LogicalAnd.java,v 1.12 2006/01/08 00:52:25 davidahall Exp $
003: // Copyright (c) 2002-2005 David A. Hall
004: // ============================================================================
005: // The contents of this file are subject to the Common Development and
006: // Distribution License (CDDL), Version 1.0 (the License); you may not use this
007: // file except in compliance with the License. You should have received a copy
008: // of the the License along with this file: if not, a copy of the License is
009: // available from Sun Microsystems, Inc.
010: //
011: // http://www.sun.com/cddl/cddl.html
012: //
013: // From time to time, the license steward (initially Sun Microsystems, Inc.) may
014: // publish revised and/or new versions of the License. You may not use,
015: // distribute, or otherwise make this file available under subsequent versions
016: // of the License.
017: //
018: // Alternatively, the contents of this file may be used under the terms of the
019: // GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
020: // case the provisions of the LGPL are applicable instead of those above. If you
021: // wish to allow use of your version of this file only under the terms of the
022: // LGPL, and not to allow others to use your version of this file under the
023: // terms of the CDDL, indicate your decision by deleting the provisions above
024: // and replace them with the notice and other provisions required by the LGPL.
025: // If you do not delete the provisions above, a recipient may use your version
026: // of this file under the terms of either the CDDL or the LGPL.
027: //
028: // This library is distributed in the hope that it will be useful,
029: // but WITHOUT ANY WARRANTY; without even the implied warranty of
030: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
031: // ============================================================================
032:
033: package net.sf.jga.fn.logical;
034:
035: import net.sf.jga.fn.BinaryPredicate;
036:
037: /**
038: * Binary Predicate that returns true when Boolean arguments <b>x</b>
039: * and <b>y</b> are both true.
040: * <p>
041: * Note that this functor does <i>not</i> short circuit the evaluation
042: * of the second argument. The reason for this is that, by itself,
043: * this functor accepts only boolean arguments. When it is used in
044: * conjunction with the adaptor functors to implement compound
045: * functors, the adaptor cannot know that the functor it is adapting
046: * may not need to use both arguments, so the adaptor will fully
047: * evaluate both arguments before passing them to the And functor.
048: * This would give the illusion that the short circuit logic is
049: * broken, when it is in fact unimplementable using the standard
050: * functor mechanism.
051: * <p>
052: * Copyright © 2002 David A. Hall
053: *
054: * @author <a href="mailto:davidahall@users.sourceforge.net">David A. Hall</a>
055: **/
056:
057: public class LogicalAnd extends BinaryPredicate<Boolean, Boolean> {
058:
059: static final long serialVersionUID = 7520826532411249757L;
060:
061: // BinaryPredicate interface
062:
063: /**
064: * Given Boolean arguments <b>x</b> and <b>y</b>, returns true when both
065: * x and y are true, otherwise false.
066: *
067: * @return x & y
068: */
069: public Boolean fn(Boolean x, Boolean y) {
070: return x & y;
071: }
072:
073: /**
074: * Calls the Visitor's <code>visit(LogicalAnd)</code> method, if it
075: * implements the nested Visitor interface.
076: */
077: public void accept(net.sf.jga.fn.Visitor v) {
078: if (v instanceof LogicalAnd.Visitor)
079: ((LogicalAnd.Visitor) v).visit(this );
080: else
081: v.visit(this );
082: }
083:
084: // Object overrides
085:
086: public String toString() {
087: return "LogicalAnd";
088: }
089:
090: // AcyclicVisitor
091:
092: /**
093: * Interface for classes that may interpret a <b>LogicalAnd</b>
094: * predicate.
095: */
096: public interface Visitor extends net.sf.jga.fn.Visitor {
097: public void visit(LogicalAnd host);
098: }
099:
100: }
|