KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > dynamic > C


1 /* Copyright (c) 2002 Nat Pryce. All rights reserved.
2  *
3  * Created on February 14, 2002, 4:02 PM
4  */

5 package com.mockobjects.dynamic;
6
7 import com.mockobjects.constraint.*;
8
9
10 /** Convenient factory functions and constants for building predicates.
11  */

12 public abstract class C
13 {
14     public static final IsAnything IS_ANYTHING = new IsAnything();
15     public static final IsNull IS_NULL = new IsNull();
16     public static final Constraint IS_NOT_NULL = not(IS_NULL);
17     public static final Constraint IS_TRUE = eq(new Boolean JavaDoc(true));
18     public static final Constraint IS_FALSE = eq(new Boolean JavaDoc(false));
19     public static final Constraint IS_ZERO = eq(new Integer JavaDoc(0));
20     public static final Constraint IS_NOT_ZERO = not(IS_ZERO);
21     
22     public static final ConstraintMatcher NO_ARGS = new FullConstraintMatcher(new Constraint[0]);
23     public static final ConstraintMatcher ANY_ARGS = new AnyConstraintMatcher();
24     
25     public static Constraint same( Object JavaDoc o ) {
26         return new IsSame(o);
27     }
28     
29     public static Constraint eq( Object JavaDoc o ) {
30         return new IsEqual(o);
31     }
32         
33     public static ConstraintMatcher eq( Object JavaDoc arg0, Object JavaDoc arg1 ) {
34         return args(eq(arg0), eq(arg1));
35     }
36     
37     public static ConstraintMatcher eq( Object JavaDoc arg0, Object JavaDoc arg1, Object JavaDoc arg2 ) {
38         return args(eq(arg0), eq(arg1), eq(arg2));
39     }
40
41     public static Constraint eq( int n ) {
42         return new IsEqual( new Integer JavaDoc(n) );
43     }
44     
45     public static Constraint eq( long l ) {
46         return new IsEqual( new Long JavaDoc(l) );
47     }
48     
49     public static Constraint eq( double d ) {
50         return new IsEqual( new Double JavaDoc(d) );
51     }
52     
53     public static Constraint gt( int n ) {
54         return new IsGreaterThan( new Integer JavaDoc(n) );
55     }
56     
57     public static Constraint gt( long l ) {
58         return new IsGreaterThan( new Long JavaDoc(l) );
59     }
60     
61     public static Constraint gt( double d ) {
62         return new IsGreaterThan( new Double JavaDoc(d) );
63     }
64     
65     public static Constraint gt( char c ) {
66         return new IsGreaterThan( new Character JavaDoc(c) );
67     }
68     
69     public static Constraint lt( int n ) {
70         return new IsLessThan( new Integer JavaDoc(n) );
71     }
72     
73     public static Constraint lt( long l ) {
74         return new IsLessThan( new Long JavaDoc(l) );
75     }
76     
77     public static Constraint lt( double d ) {
78         return new IsLessThan( new Double JavaDoc(d) );
79     }
80     
81     public static Constraint lt( char c ) {
82         return new IsLessThan( new Character JavaDoc(c) );
83     }
84     
85     public static Constraint not( Constraint p ) {
86         return new IsNot(p);
87     }
88     
89     public static Constraint and( Constraint p1, Constraint p2 ) {
90         return new And(p1,p2);
91     }
92     
93     public static Constraint or( Constraint p1, Constraint p2 ) {
94         return new Or(p1,p2);
95     }
96     
97     public static Constraint isA( Class JavaDoc c ) {
98         return new IsInstanceOf(c);
99     }
100     
101
102
103     /* Helper methods for succinctly constructing Constraint arrays
104      */

105
106     public static ConstraintMatcher args() {
107         return NO_ARGS;
108     }
109
110     public static ConstraintMatcher args(Constraint p) {
111         return new FullConstraintMatcher(new Constraint[]{p});
112     }
113
114     public static ConstraintMatcher args(Constraint p1, Constraint p2) {
115         return new FullConstraintMatcher(new Constraint[]{p1, p2});
116     }
117
118     public static ConstraintMatcher args(Constraint p1, Constraint p2, Constraint p3) {
119         return new FullConstraintMatcher(new Constraint[]{p1, p2, p3});
120     }
121     
122     public static ConstraintMatcher anyArgs( int argCount) {
123         Constraint[] constraints = new Constraint[argCount];
124         for (int i = 0; i < constraints.length; i++) {
125             constraints[i] = new IsAnything();
126         }
127         
128         return new FullConstraintMatcher(constraints);
129      }
130 }
131
Popular Tags