001: // ============================================================================
002: // $Id: LogicalFunctors.java,v 1.2 2006/12/16 16:48:58 davidahall Exp $
003: // Copyright (c) 2006 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 java.util.Arrays;
036: import java.util.Collection;
037: import net.sf.jga.fn.BinaryFunctor;
038: import net.sf.jga.fn.UnaryFunctor;
039:
040: /**
041: * Static factory methods for the functors in the Logical package.
042: * <p>
043: * Copyright © 2006 David A. Hall
044: * @author <a href="mailto:davidahall@users.sf.net">David A. Hall</a>
045: */
046:
047: public final class LogicalFunctors {
048:
049: static private LogicalAnd _andInstance = new LogicalAnd();
050: static private LogicalNot _notInstance = new LogicalNot();
051: static private LogicalOr _orInstance = new LogicalOr();
052:
053: /**
054: */
055: static public <T> UnaryFunctor<T, Boolean> all() {
056: return new All<T>();
057: }
058:
059: /**
060: */
061: static public <T> UnaryFunctor<T, Boolean> all(
062: Collection<UnaryFunctor<T, Boolean>> branches) {
063: return new All<T>(branches);
064: }
065:
066: /**
067: */
068: static public <T> UnaryFunctor<T, Boolean> all(
069: UnaryFunctor<T, Boolean>... branches) {
070: return new All<T>(Arrays.asList(branches));
071: }
072:
073: // /**
074: // */
075: // static public BinaryFunctor<Boolean,Boolean,Boolean> and() {
076: // return logicalAnd();
077: // }
078:
079: /**
080: */
081: static public <T> UnaryFunctor<T, Boolean> any() {
082: return new Any<T>();
083: }
084:
085: /**
086: */
087: static public <T> UnaryFunctor<T, Boolean> any(
088: Collection<UnaryFunctor<T, Boolean>> branches) {
089: return new Any<T>(branches);
090: }
091:
092: /**
093: */
094: static public <T> UnaryFunctor<T, Boolean> any(
095: UnaryFunctor<T, Boolean>... branches) {
096: return new Any<T>(Arrays.asList(branches));
097: }
098:
099: /**
100: */
101: static public <T1, T2> BinaryFunctor<T1, T2, Boolean> binaryNegate(
102: BinaryFunctor<? super T1, ? super T2, Boolean> p) {
103: return new BinaryNegate<T1, T2>(p);
104: }
105:
106: /**
107: */
108: static public BinaryFunctor<Boolean, Boolean, Boolean> logicalAnd() {
109: return _andInstance;
110: }
111:
112: /**
113: */
114: static public BinaryFunctor<Boolean, Boolean, Boolean> logicalOr() {
115: return _orInstance;
116: }
117:
118: /**
119: */
120: static public UnaryFunctor<Boolean, Boolean> logicalNot() {
121: return _notInstance;
122: }
123:
124: // /**
125: // */
126: // static public <T1,T2> BinaryFunctor<T1,T2,Boolean>
127: // negate(BinaryFunctor<? super T1, ? super T2, Boolean> p)
128: // {
129: // return binaryNegate(p);
130: // }
131:
132: // /**
133: // */
134: // static public <T> UnaryFunctor<T,Boolean> negate(UnaryFunctor<? super T, Boolean> p) {
135: // return unaryNegate(p);
136: // }
137:
138: // /**
139: // */
140: // static public UnaryFunctor<Boolean,Boolean> not() {
141: // return logicalNot();
142: // }
143:
144: // /**
145: // */
146: // static public BinaryFunctor<Boolean,Boolean,Boolean> or() {
147: // return logicalOr();
148: // }
149:
150: /**
151: */
152: static public <T> UnaryFunctor<T, Boolean> unaryNegate(
153: UnaryFunctor<? super T, Boolean> p) {
154: return new UnaryNegate<T>(p);
155: }
156: }
|