KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > co > jezuk > mango > Predicates


1 package uk.co.jezuk.mango;
2
3 /**
4  * The Mango Library Unary and Binary Predicates
5  *
6  * @author Jez Higgins, jez@jezuk.co.uk
7  * @version $Id: Predicates.java 80 2003-04-03 12:44:26Z jez $
8  */

9 public class Predicates
10 {
11   ///////////////////////////////////////////////////////
12
// Unary Predicates
13
/**
14    * A <code>Predicate</code> which always returns <code>true</code>
15    */

16   static public Predicate True() { return new uk.co.jezuk.mango.unarypredicates.True(); }
17   /**
18    * A <code>Predicate</code> which always returns <code>false</code>
19    */

20   static public Predicate False() { return new uk.co.jezuk.mango.unarypredicates.False(); }
21   /**
22    * A <code>Predicate</code> which is the logical negation of some other <code>Predicate</code>. If <code>n</code>
23    * is a <code>Not</code> object, and <code>pred</code> is the <code>Predicate</code> it was constructed with,
24    * then <code>n.test(x)</code> returns <code>!pred.test(x)</code>.
25    */

26   static public Predicate Not(Predicate pred) { return new uk.co.jezuk.mango.unarypredicates.Not(pred); }
27   /**
28    * A <code>Predicate</code> which returns the logical AND of two other <code>Predicate</code>. If <code>a</code>
29    * is an <code>And</code> object, constructed with <code>pred1</code> and <code>pred2</code>, then
30    * <code>a.test(x)</code> returns <code>pred1.test(x) && pred2.test(x)</code>
31    */

32   static public Predicate And(Predicate pred1, Predicate pred2) { return new uk.co.jezuk.mango.unarypredicates.And(pred1, pred2); }
33   /**
34    * A <code>Predicate</code> which returns the logical OR of two other <code>Predicate</code>. If <code>a</code>
35    * is an <code>Or</code> object, constructed with <code>pred1</code> and <code>pred2</code>, then
36    * <code>a.test(x)</code> returns <code>pred1.test(x) || pred2.test(x)</code>
37    */

38   static public Predicate Or(Predicate pred1, Predicate pred2) { return new uk.co.jezuk.mango.unarypredicates.Or(pred1, pred2); }
39
40   /////////////////////////////////////////////////
41
// Binary Predicates
42
/**
43    * <code>BinaryPredicate</code> testing for equality.
44    * <code>true</code> if <code>x.equals(y)</code> or <code>(x == null && y == null)</code>
45    */

46   static public BinaryPredicate EqualTo() { return new uk.co.jezuk.mango.binarypredicates.EqualTo(); }
47   /**
48    * <code>BinaryPredicate</code> that returns true if <code>x</code> is greater than <code>y</code>.
49    * <code>x</code> and <code>y</code> must implement the <code>java.lang.Comparable<code> interface.
50    */

51   static public BinaryPredicate GreaterThan() { return new uk.co.jezuk.mango.binarypredicates.GreaterThan(); }
52   /**
53    * <code>BinaryPredicate</code> that returns true if <code>x</code> is greater than or equal to <code>y</code>.
54    * <code>x</code> and <code>y</code> must implement the <code>java.lang.Comparable<code> interface.
55    */

56   static public BinaryPredicate GreaterThanEquals() { return new uk.co.jezuk.mango.binarypredicates.GreaterThanEquals(); }
57   /**
58    * <code>BinaryPredicate</code> that returns true if <code>x</code> is less than <code>y</code>.
59    * <code>x</code> and <code>y</code> must implement the <code>java.lang.Comparable<code> interface.
60    */

61   static public BinaryPredicate LessThan() { return new uk.co.jezuk.mango.binarypredicates.LessThan(); }
62   /**
63    * <code>BinaryPredicate</code> that returns true if <code>x</code> is less than or equal to <code>y</code>.
64    * <code>x</code> and <code>y</code> must implement the <code>java.lang.Comparable<code> interface.
65    */

66   static public BinaryPredicate LessThanEquals() { return new uk.co.jezuk.mango.binarypredicates.LessThanEquals(); }
67   /**
68    * <code>true</code> if <code>not(x.equals(y))</code>, <code>(x == null) && not(y == null)</code> or <code>not(x == null) && (y == null)</code>
69    */

70   static public BinaryPredicate NotEqualTo() { return new uk.co.jezuk.mango.binarypredicates.NotEqualTo(); }
71   /**
72    * A <code>BinaryPredicate</code> which is the logical negation of some other <code>BinaryPredicate</code>. If <code>n</code>
73    * is a <code>Not</code> object, and <code>pred</code> is the <code>Predicate</code> it was constructed with,
74    * then <code>n.test(x,y)</code> returns <code>!pred.test(x,y)</code>.
75    */

76   static public BinaryPredicate Not(BinaryPredicate pred) { return new uk.co.jezuk.mango.binarypredicates.Not(pred); }
77   /**
78    * A <code>BinaryPredicate</code> which returns the logical AND of two other <code>BinaryPredicate</code>. If <code>a</code>
79    * is an <code>And</code> object, constructed with <code>pred1</code> and <code>pred2</code>, then
80    * <code>a.test(x,y)</code> returns <code>pred1.test(x,y) && pred2.test(x,y)</code>
81    */

82   static public BinaryPredicate And(BinaryPredicate pred1, BinaryPredicate pred2) { return new uk.co.jezuk.mango.binarypredicates.And(pred1, pred2); }
83   /**
84    * A <code>BinaryPredicate</code> which returns the logical OR of two other <code>BinaryPredicate</code>. If <code>a</code>
85    * is an <code>Or</code> object, constructed with <code>pred1</code> and <code>pred2</code>, then
86    * <code>a.test(x,y)</code> returns <code>pred1.test(x,y) || pred2.test(x,y)</code>
87    */

88   static public BinaryPredicate Or(BinaryPredicate pred1, BinaryPredicate pred2) { return new uk.co.jezuk.mango.binarypredicates.Or(pred1, pred2); }
89
90   //////////////////////////////////
91
private Predicates() { }
92 } // Predicates
93

94
95
Popular Tags