001: // ============================================================================
002: // $Id: ComparisonFunctors.java,v 1.4 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.comparison;
034:
035: import java.util.Comparator;
036: import net.sf.jga.fn.BinaryFunctor;
037: import net.sf.jga.fn.UnaryFunctor;
038:
039: /**
040: * Static factory methods for the functors in the Comparison package.
041: * <p>
042: * Copyright © 2006 David A. Hall
043: * @author <a href="mailto:davidahall@users.sf.net">David A. Hall</a>
044: */
045:
046: public final class ComparisonFunctors {
047: /**
048: */
049: static public <T> UnaryFunctor<T, Boolean> between(T lo, T hi,
050: Comparator<? super T> comp) {
051: return new Between<T>(lo, hi, comp);
052: }
053:
054: /**
055: */
056: static public <T extends Comparable/*@*/<? super T>/*@*/> UnaryFunctor<T, Boolean> between(
057: T lo, T hi) {
058: return new Between.Comparable<T>(lo, hi);
059: }
060:
061: /**
062: */
063: static public <T> UnaryFunctor<T, Boolean> between(
064: UnaryFunctor<T, Boolean> lo, UnaryFunctor<T, Boolean> hi) {
065: return new Between<T>(lo, hi);
066: }
067:
068: /**
069: */
070: static public <T> BinaryFunctor<T, T, Integer> comparatorFn(
071: Comparator<T> comp) {
072: return new ComparatorFn<T>(comp);
073: }
074:
075: /**
076: */
077: static public <T> BinaryFunctor<T, T, Boolean> equalEqual() {
078: return new EqualEqual<T>();
079: }
080:
081: /**
082: */
083: static public <T> UnaryFunctor<T, Boolean> equalEqual(T value) {
084: return ComparisonFunctors.<T> equalEqual().bind2nd(value);
085: }
086:
087: /**
088: */
089: static public <T> BinaryFunctor<T, T, Boolean> equalTo(Class<T> hint) {
090: return new EqualTo<T>();
091: }
092:
093: /**
094: */
095: static public <T> BinaryFunctor<T, T, Boolean> equalTo(
096: Comparator<? super T> comp) {
097: return new EqualTo<T>(comp);
098: }
099:
100: /**
101: */
102: static public <T> UnaryFunctor<T, Boolean> equalTo(T value) {
103: return new EqualTo<T>().bind2nd(value);
104: }
105:
106: /**
107: */
108: static public <T> UnaryFunctor<T, Boolean> equalTo(
109: Comparator<? super T> comp, T value) {
110: return new EqualTo<T>(comp).bind2nd(value);
111: }
112:
113: /**
114: */
115: static public <T> UnaryFunctor<T, Boolean> equalTo(Equality<T> eq,
116: T value) {
117: return eq.bind2nd(value);
118: }
119:
120: /**
121: */
122: static public <T> BinaryFunctor<T, T, Boolean> greater(
123: Comparator<? super T> comp) {
124: return new Greater<T>(comp);
125: }
126:
127: /**
128: */
129: static public <T> UnaryFunctor<T, Boolean> greater(
130: Comparator<? super T> comp, T value) {
131: return ComparisonFunctors.<T> greater(comp).bind2nd(value);
132: }
133:
134: /**
135: */
136: static public <T extends Comparable/*@*/<? super T>/*@*/> BinaryFunctor<T, T, Boolean> greater(
137: Class<T> hint) {
138: return new Greater.Comparable<T>();
139: }
140:
141: /**
142: */
143: static public <T extends Comparable/*@*/<? super T>/*@*/> UnaryFunctor<T, Boolean> greater(
144: T value) {
145: return new Greater.Comparable<T>().bind2nd(value);
146: }
147:
148: /**
149: */
150: static public <T> BinaryFunctor<T, T, Boolean> greaterEqual(
151: Comparator<? super T> comp) {
152: return new GreaterEqual<T>(comp);
153: }
154:
155: /**
156: */
157: static public <T> UnaryFunctor<T, Boolean> greaterEqual(
158: Comparator<? super T> comp, T value) {
159: return ComparisonFunctors.<T> greaterEqual(comp).bind2nd(value);
160: }
161:
162: /**
163: */
164: static public <T extends Comparable/*@*/<? super T>/*@*/> BinaryFunctor<T, T, Boolean> greaterEqual(
165: Class<T> hint) {
166: return new GreaterEqual.Comparable<T>();
167: }
168:
169: /**
170: */
171: static public <T extends Comparable/*@*/<? super T>/*@*/> UnaryFunctor<T, Boolean> greaterEqual(
172: T value) {
173: return new GreaterEqual.Comparable<T>().bind2nd(value);
174: }
175:
176: /**
177: */
178: static public <T> UnaryFunctor<T, Boolean> isNull() {
179: return new EqualTo<T>().bind2nd(null);
180: }
181:
182: /**
183: */
184: static public <T> UnaryFunctor<T, Boolean> notNull() {
185: return new NotEqualTo<T>().bind2nd(null);
186: }
187:
188: /**
189: */
190: static public <T> BinaryFunctor<T, T, Boolean> less(
191: Comparator<? super T> comp) {
192: return new Less<T>(comp);
193: }
194:
195: /**
196: */
197: static public <T> UnaryFunctor<T, Boolean> less(
198: Comparator<? super T> comp, T value) {
199: return ComparisonFunctors.<T> less(comp).bind2nd(value);
200: }
201:
202: /**
203: */
204: static public <T extends Comparable/*@*/<? super T>/*@*/> BinaryFunctor<T, T, Boolean> less(
205: Class<T> hint) {
206: return new Less.Comparable<T>();
207: }
208:
209: /**
210: */
211: static public <T extends Comparable/*@*/<? super T>/*@*/> UnaryFunctor<T, Boolean> less(
212: T value) {
213: return new Less.Comparable<T>().bind2nd(value);
214: }
215:
216: /**
217: */
218: static public <T> BinaryFunctor<T, T, Boolean> lessEqual(
219: Comparator<? super T> comp) {
220: return new LessEqual<T>(comp);
221: }
222:
223: /**
224: */
225: static public <T> UnaryFunctor<T, Boolean> lessEqual(
226: Comparator<? super T> comp, T value) {
227: return ComparisonFunctors.<T> lessEqual(comp).bind2nd(value);
228: }
229:
230: /**
231: */
232: static public <T extends Comparable/*@*/<? super T>/*@*/> BinaryFunctor<T, T, Boolean> lessEqual(
233: Class<T> hint) {
234: return new LessEqual.Comparable<T>();
235: }
236:
237: /**
238: */
239: static public <T extends Comparable/*@*/<? super T>/*@*/> UnaryFunctor<T, Boolean> lessEqual(
240: T value) {
241: return new LessEqual.Comparable<T>().bind2nd(value);
242: }
243:
244: /**
245: */
246: static public <T> BinaryFunctor<T, T, T> max(
247: Comparator<? super T> comp) {
248: return new Max<T>(comp);
249: }
250:
251: /**
252: */
253: static public <T extends Comparable/*@*/<? super T>/*@*/> BinaryFunctor<T, T, T> max(
254: Class<T> hint) {
255: return new Max.Comparable<T>();
256: }
257:
258: /**
259: */
260: static public <T> BinaryFunctor<T, T, T> min(
261: Comparator<? super T> comp) {
262: return new Min<T>(comp);
263: }
264:
265: /**
266: */
267: static public <T extends Comparable/*@*/<? super T>/*@*/> BinaryFunctor<T, T, T> min(
268: Class<T> hint) {
269: return new Min.Comparable<T>();
270: }
271:
272: /**
273: */
274: static public <T> BinaryFunctor<T, T, Boolean> notEqualEqual() {
275: return new NotEqualEqual<T>();
276: }
277:
278: /**
279: */
280: static public <T> UnaryFunctor<T, Boolean> notEqualEqual(T value) {
281: return new NotEqualEqual<T>().bind2nd(value);
282: }
283:
284: /**
285: */
286: static public <T> BinaryFunctor<T, T, Boolean> notEqualTo(
287: Class<T> hint) {
288: return new NotEqualTo<T>();
289: }
290:
291: /**
292: */
293: static public <T> BinaryFunctor<T, T, Boolean> notEqualTo(
294: Comparator<? super T> comp) {
295: return new NotEqualTo<T>(comp);
296: }
297:
298: /**
299: */
300: static public <T> UnaryFunctor<T, Boolean> notEqualTo(T value) {
301: return new NotEqualTo<T>().bind2nd(value);
302: }
303:
304: /**
305: */
306: static public <T> UnaryFunctor<T, Boolean> notEqualTo(
307: Comparator<? super T> comp, T value) {
308: return new NotEqualTo<T>(comp).bind2nd(value);
309: }
310: }
|