KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jga > fn > property > PropertyFunctors


1 // ============================================================================
2
// $Id: PropertyFunctors.java,v 1.3 2006/12/16 16:48:58 davidahall Exp $
3
// Copyright (c) 2006 David A. Hall
4
// ============================================================================
5
// The contents of this file are subject to the Common Development and
6
// Distribution License (CDDL), Version 1.0 (the License); you may not use this
7
// file except in compliance with the License. You should have received a copy
8
// of the the License along with this file: if not, a copy of the License is
9
// available from Sun Microsystems, Inc.
10
//
11
// http://www.sun.com/cddl/cddl.html
12
//
13
// From time to time, the license steward (initially Sun Microsystems, Inc.) may
14
// publish revised and/or new versions of the License. You may not use,
15
// distribute, or otherwise make this file available under subsequent versions
16
// of the License.
17
//
18
// Alternatively, the contents of this file may be used under the terms of the
19
// GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
20
// case the provisions of the LGPL are applicable instead of those above. If you
21
// wish to allow use of your version of this file only under the terms of the
22
// LGPL, and not to allow others to use your version of this file under the
23
// terms of the CDDL, indicate your decision by deleting the provisions above
24
// and replace them with the notice and other provisions required by the LGPL.
25
// If you do not delete the provisions above, a recipient may use your version
26
// of this file under the terms of either the CDDL or the LGPL.
27
//
28
// This library is distributed in the hope that it will be useful,
29
// but WITHOUT ANY WARRANTY; without even the implied warranty of
30
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31
// ============================================================================
32

33 package net.sf.jga.fn.property;
34
35 import java.lang.reflect.Constructor JavaDoc;
36 import java.lang.reflect.Field JavaDoc;
37 import java.lang.reflect.Method JavaDoc;
38 import net.sf.jga.fn.BinaryFunctor;
39 import net.sf.jga.fn.UnaryFunctor;
40 import net.sf.jga.fn.adaptor.Identity;
41 import net.sf.jga.fn.Generator;
42
43 /**
44  * Static factory methods for the functors in the Property package.
45  * <p>
46  * Copyright &copy; 2006 David A. Hall
47  * @author <a HREF="mailto:davidahall@users.sf.net">David A. Hall</a>
48  */

49
50 public final class PropertyFunctors {
51     /**
52      */

53     static public <T1,T2> BinaryFunctor<T1,T2,Object JavaDoc[]> arrayBinary() {
54         return new ArrayBinary<T1,T2>();
55     }
56
57     
58     /**
59      */

60     static public <T> UnaryFunctor<T,Object JavaDoc[]> arrayUnary() {
61         return new ArrayUnary<T>();
62     }
63
64     
65     /**
66      */

67     static public <T,R> UnaryFunctor<T,R> cast(Class JavaDoc<R> r) {
68         return new Cast<T,R>(r);
69     }
70
71      
72     /**
73      */

74     static public <T,V> UnaryFunctor<T,Boolean JavaDoc> compareProperty(Class JavaDoc<T> t, String JavaDoc name, V value) {
75         return new CompareProperty<T,V>(t, name, value);
76     }
77
78     
79     /**
80      */

81     static public <T,V> UnaryFunctor<T,Boolean JavaDoc>
82     compareProperty(Class JavaDoc<T> t, String JavaDoc name, BinaryFunctor<V,V,Boolean JavaDoc> pred, V value)
83     {
84         return new CompareProperty<T,V>(t, name, pred, value);
85     }
86
87     
88     /**
89      */

90     static public <R> UnaryFunctor<Object JavaDoc[],R> construct(Constructor JavaDoc<R> ctor) {
91         return new Construct<R>(ctor);
92     }
93
94     
95     /**
96      */

97     static public <R> UnaryFunctor<Object JavaDoc[],R> construct(Class JavaDoc<R> r, Class JavaDoc... argclasses) {
98         return new Construct<R>(r, argclasses);
99     }
100
101     
102     /**
103      */

104     static public <R> Generator<R> constructDefault(Class JavaDoc<R> r) {
105         return new ConstructDefault<R>(r);
106     }
107
108     
109     /**
110      */

111     static public <T,R> UnaryFunctor<T,R> constructUnary(Class JavaDoc<R> r, Class JavaDoc<T> t) {
112         return new ConstructUnary<T,R>(t,r);
113     }
114
115     
116     /**
117      */

118     static public <T,R> UnaryFunctor<T,R> getField(Class JavaDoc<T> t,String JavaDoc name) {
119         return new GetField<T,R>(t, name);
120     }
121     
122     
123     /**
124      */

125     static public <T,R> UnaryFunctor<T,R> getField(Class JavaDoc<T> t, Field JavaDoc field) {
126         return new GetField<T,R>(t, field);
127     }
128
129     
130     /**
131      */

132     static public <T,R> UnaryFunctor<T,R> getField(Field JavaDoc field) {
133         return new GetField<T,R>(field);
134     }
135
136     
137     /**
138      */

139     static public <T,R> UnaryFunctor<T,R> getProperty(Class JavaDoc<T> t,String JavaDoc name) {
140         return new GetProperty<T,R>(t, name);
141     }
142
143     
144     /**
145      */

146     static public <T,R> UnaryFunctor<T,R> getProperty(Class JavaDoc<T> t, String JavaDoc name, Class JavaDoc<R> hint) {
147         return new GetProperty<T,R>(t,name);
148     }
149     
150     
151     /**
152      */

153     static public <T> UnaryFunctor<T,Boolean JavaDoc> instanceOf(Class JavaDoc<?> type) {
154         return new InstanceOf<T>(type);
155     }
156
157
158     // TODO -- think about this exception -- seriously!!!
159
/**
160      */

161     static public <T1,T2,R> BinaryFunctor<T1,Object JavaDoc[],R>
162 // static public <T1,T2,R> BinaryFunctor<T1,T2,R>
163
invokeMethod(Class JavaDoc<T1> t1, String JavaDoc name, Class JavaDoc<T2> t2)
164     {
165         return new InvokeMethod<T1,R>(t1, name, t2)
166 // .distribute(new Identity<T1>(), new ArrayUnary<T2>());
167
;
168     }
169
170     
171     /**
172      */

173     static public <T,R> BinaryFunctor<T,Object JavaDoc[],R> invokeMethod(Class JavaDoc<T> t, Method JavaDoc method) {
174         return new InvokeMethod<T,R>(t, method);
175     }
176
177
178     /**
179      */

180     static public <T,R> BinaryFunctor<T,Object JavaDoc[],R>
181     invokeMethod(Class JavaDoc<T> t, String JavaDoc name, Class JavaDoc... argtypes) {
182         return new InvokeMethod<T,R>(t, name, argtypes);
183     }
184
185
186     /**
187      */

188     static public <T,R> UnaryFunctor<T,R> invokeNoArgMethod(Class JavaDoc<T> t, Method JavaDoc method) {
189         return new InvokeNoArgMethod<T,R>(t, method);
190     }
191
192
193     /**
194      */

195     static public <T,R> UnaryFunctor<T,R> invokeNoArgMethod(Class JavaDoc<T> t, String JavaDoc name) {
196         return new InvokeNoArgMethod<T,R>(t, name);
197     }
198
199
200     /**
201      */

202     static public <T1,T2> BinaryFunctor<T1,T2,T2> setField(Field JavaDoc field) {
203         return new SetField<T1,T2>(field);
204     }
205     
206     /**
207      */

208     static public <T1,T2> BinaryFunctor<T1,T2,T2> setField(Class JavaDoc<T1> t1, Field JavaDoc field) {
209         return new SetField<T1,T2>(t1, field);
210     }
211     
212     /**
213      */

214     static public <T1,T2> BinaryFunctor<T1,T2,T2> setField(Class JavaDoc<T1> t1, Field JavaDoc field, Class JavaDoc<T2> t2) {
215         return new SetField<T1,T2>(t1, field, t2);
216     }
217
218
219     /**
220      */

221     static public <T1,T2> BinaryFunctor<T1,T2,T2> setField(Class JavaDoc<T1> t1, String JavaDoc name, Class JavaDoc<T2> t2) {
222         return new SetField<T1,T2>(t1, name, t2);
223     }
224
225
226     /**
227      */

228     static public <T1,T2> BinaryFunctor<T1,T2,T2> setProperty(Class JavaDoc<T1> t1,String JavaDoc name,Class JavaDoc<T2> t2){
229         return new SetProperty<T1,T2>(t1, name, t2);
230     }
231 }
232
Popular Tags