001: // ============================================================================
002: // $Id: PropertyFunctors.java,v 1.3 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.property;
034:
035: import java.lang.reflect.Constructor;
036: import java.lang.reflect.Field;
037: import java.lang.reflect.Method;
038: import net.sf.jga.fn.BinaryFunctor;
039: import net.sf.jga.fn.UnaryFunctor;
040: import net.sf.jga.fn.adaptor.Identity;
041: import net.sf.jga.fn.Generator;
042:
043: /**
044: * Static factory methods for the functors in the Property package.
045: * <p>
046: * Copyright © 2006 David A. Hall
047: * @author <a href="mailto:davidahall@users.sf.net">David A. Hall</a>
048: */
049:
050: public final class PropertyFunctors {
051: /**
052: */
053: static public <T1, T2> BinaryFunctor<T1, T2, Object[]> arrayBinary() {
054: return new ArrayBinary<T1, T2>();
055: }
056:
057: /**
058: */
059: static public <T> UnaryFunctor<T, Object[]> arrayUnary() {
060: return new ArrayUnary<T>();
061: }
062:
063: /**
064: */
065: static public <T, R> UnaryFunctor<T, R> cast(Class<R> r) {
066: return new Cast<T, R>(r);
067: }
068:
069: /**
070: */
071: static public <T, V> UnaryFunctor<T, Boolean> compareProperty(
072: Class<T> t, String name, V value) {
073: return new CompareProperty<T, V>(t, name, value);
074: }
075:
076: /**
077: */
078: static public <T, V> UnaryFunctor<T, Boolean> compareProperty(
079: Class<T> t, String name, BinaryFunctor<V, V, Boolean> pred,
080: V value) {
081: return new CompareProperty<T, V>(t, name, pred, value);
082: }
083:
084: /**
085: */
086: static public <R> UnaryFunctor<Object[], R> construct(
087: Constructor<R> ctor) {
088: return new Construct<R>(ctor);
089: }
090:
091: /**
092: */
093: static public <R> UnaryFunctor<Object[], R> construct(Class<R> r,
094: Class... argclasses) {
095: return new Construct<R>(r, argclasses);
096: }
097:
098: /**
099: */
100: static public <R> Generator<R> constructDefault(Class<R> r) {
101: return new ConstructDefault<R>(r);
102: }
103:
104: /**
105: */
106: static public <T, R> UnaryFunctor<T, R> constructUnary(Class<R> r,
107: Class<T> t) {
108: return new ConstructUnary<T, R>(t, r);
109: }
110:
111: /**
112: */
113: static public <T, R> UnaryFunctor<T, R> getField(Class<T> t,
114: String name) {
115: return new GetField<T, R>(t, name);
116: }
117:
118: /**
119: */
120: static public <T, R> UnaryFunctor<T, R> getField(Class<T> t,
121: Field field) {
122: return new GetField<T, R>(t, field);
123: }
124:
125: /**
126: */
127: static public <T, R> UnaryFunctor<T, R> getField(Field field) {
128: return new GetField<T, R>(field);
129: }
130:
131: /**
132: */
133: static public <T, R> UnaryFunctor<T, R> getProperty(Class<T> t,
134: String name) {
135: return new GetProperty<T, R>(t, name);
136: }
137:
138: /**
139: */
140: static public <T, R> UnaryFunctor<T, R> getProperty(Class<T> t,
141: String name, Class<R> hint) {
142: return new GetProperty<T, R>(t, name);
143: }
144:
145: /**
146: */
147: static public <T> UnaryFunctor<T, Boolean> instanceOf(Class<?> type) {
148: return new InstanceOf<T>(type);
149: }
150:
151: // TODO -- think about this exception -- seriously!!!
152: /**
153: */
154: static public <T1, T2, R> BinaryFunctor<T1, Object[], R>
155: // static public <T1,T2,R> BinaryFunctor<T1,T2,R>
156: invokeMethod(Class<T1> t1, String name, Class<T2> t2) {
157: return new InvokeMethod<T1, R>(t1, name, t2)
158: // .distribute(new Identity<T1>(), new ArrayUnary<T2>());
159: ;
160: }
161:
162: /**
163: */
164: static public <T, R> BinaryFunctor<T, Object[], R> invokeMethod(
165: Class<T> t, Method method) {
166: return new InvokeMethod<T, R>(t, method);
167: }
168:
169: /**
170: */
171: static public <T, R> BinaryFunctor<T, Object[], R> invokeMethod(
172: Class<T> t, String name, Class... argtypes) {
173: return new InvokeMethod<T, R>(t, name, argtypes);
174: }
175:
176: /**
177: */
178: static public <T, R> UnaryFunctor<T, R> invokeNoArgMethod(
179: Class<T> t, Method method) {
180: return new InvokeNoArgMethod<T, R>(t, method);
181: }
182:
183: /**
184: */
185: static public <T, R> UnaryFunctor<T, R> invokeNoArgMethod(
186: Class<T> t, String name) {
187: return new InvokeNoArgMethod<T, R>(t, name);
188: }
189:
190: /**
191: */
192: static public <T1, T2> BinaryFunctor<T1, T2, T2> setField(
193: Field field) {
194: return new SetField<T1, T2>(field);
195: }
196:
197: /**
198: */
199: static public <T1, T2> BinaryFunctor<T1, T2, T2> setField(
200: Class<T1> t1, Field field) {
201: return new SetField<T1, T2>(t1, field);
202: }
203:
204: /**
205: */
206: static public <T1, T2> BinaryFunctor<T1, T2, T2> setField(
207: Class<T1> t1, Field field, Class<T2> t2) {
208: return new SetField<T1, T2>(t1, field, t2);
209: }
210:
211: /**
212: */
213: static public <T1, T2> BinaryFunctor<T1, T2, T2> setField(
214: Class<T1> t1, String name, Class<T2> t2) {
215: return new SetField<T1, T2>(t1, name, t2);
216: }
217:
218: /**
219: */
220: static public <T1, T2> BinaryFunctor<T1, T2, T2> setProperty(
221: Class<T1> t1, String name, Class<T2> t2) {
222: return new SetProperty<T1, T2>(t1, name, t2);
223: }
224: }
|