KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jga > fn > arithmetic > ArithmeticFunctors


1 // ============================================================================
2
// $Id: ArithmeticFunctors.java,v 1.2 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.arithmetic;
34
35 import java.util.Iterator JavaDoc;
36 import net.sf.jga.fn.BinaryFunctor;
37 import net.sf.jga.fn.UnaryFunctor;
38
39 /**
40  * Static factory methods for the functors in the Comparison package.
41  * <p>
42  * Copyright &copy; 2006 David A. Hall
43  */

44
45 // This class suppresses unchecked cast warnings in numerous methods that take a generic
46
// value of type T, call getClass(), then cast the class to a Class<T>. I believe that
47
// the warning is technically correct, but the way these methods are written, you'd have
48
// to be pretty abusive to trigger the error condition.
49

50 public final class ArithmeticFunctors {
51     /**
52      */

53     static public <T extends Number JavaDoc> UnaryFunctor<Iterator JavaDoc<T>,T> average(Class JavaDoc<T> t) {
54         return new Average<T>(t);
55     }
56     
57 // /**
58
// */
59
// static public <T extends Number> BinaryFunctor<T,T,T> and(Class<T> t) {
60
// return new BitwiseAnd<T>(t);
61
// }
62

63 // /**
64
// */
65
// @SuppressWarnings("unchecked")
66
// static public <T extends Number> UnaryFunctor<T,T> and(T value) {
67
// return new BitwiseAnd<T>((Class<T>) value.getClass()).bind2nd(value);
68
// }
69

70     
71     /**
72      */

73     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> bitwiseAnd(Class JavaDoc<T> t) {
74         return new BitwiseAnd<T>(t);
75     }
76         
77     /**
78      */

79     @SuppressWarnings JavaDoc("unchecked")
80     static public <T extends Number JavaDoc> UnaryFunctor<T,T> bitwiseAnd(T value) {
81         return new BitwiseAnd<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
82     }
83         
84     /**
85      */

86     static public <T extends Number JavaDoc> UnaryFunctor<T,T> bitwiseNot(Class JavaDoc<T> t) {
87         return new BitwiseNot<T>(t);
88     }
89         
90     /**
91      */

92     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> bitwiseOr(Class JavaDoc<T> t) {
93         return new BitwiseOr<T>(t);
94     }
95
96     /**
97      */

98     @SuppressWarnings JavaDoc("unchecked")
99     static public <T extends Number JavaDoc> UnaryFunctor<T,T> bitwiseOr(T value) {
100         return new BitwiseOr<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
101     }
102
103     /**
104      */

105     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> bitwiseXor(Class JavaDoc<T> t) {
106         return new BitwiseXor<T>(t);
107     }
108         
109     /**
110      */

111     @SuppressWarnings JavaDoc("unchecked")
112     static public <T extends Number JavaDoc> UnaryFunctor<T,T> bitwiseXor(T value) {
113         return new BitwiseXor<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
114     }
115         
116     /**
117      */

118     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> divides(Class JavaDoc<T> t) {
119         return new Divides<T>(t);
120     }
121
122     /**
123      */

124     @SuppressWarnings JavaDoc("unchecked")
125     static public <T extends Number JavaDoc> UnaryFunctor<T,T> divides(T value) {
126         // Unchecked warning
127
return new Divides<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
128     }
129
130     /**
131      */

132     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> minus(Class JavaDoc<T> t) {
133         return new Minus<T>(t);
134     }
135
136     /**
137      */

138     @SuppressWarnings JavaDoc("unchecked")
139     static public <T extends Number JavaDoc> UnaryFunctor<T,T> minus(T value) {
140         return new Minus<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
141     }
142     
143     /**
144      */

145     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> modulus(Class JavaDoc<T> t) {
146         return new Modulus<T>(t);
147     }
148
149     /**
150      */

151     @SuppressWarnings JavaDoc("unchecked")
152     static public <T extends Number JavaDoc> UnaryFunctor<T,T> modulus(T value) {
153         return new Modulus<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
154     }
155
156     /**
157      */

158     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> multiplies(Class JavaDoc<T> t) {
159         return new Multiplies<T>(t);
160     }
161
162     /**
163      */

164     @SuppressWarnings JavaDoc("unchecked")
165     static public <T extends Number JavaDoc> UnaryFunctor<T,T> multiplies(T value) {
166         return new Multiplies<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
167     }
168
169     /**
170      */

171     static public <T extends Number JavaDoc> UnaryFunctor<T,T> negate(Class JavaDoc<T> t) {
172         return new Negate<T>(t);
173     }
174
175 // /**
176
// /**
177
// */
178
// static public <T extends Number> UnaryFunctor<T,T> not(Class<T> t) {
179
// return new BitwiseNot<T>(t);
180
// }
181

182 // */
183
// static public <T extends Number> BinaryFunctor<T,T,T> or(Class<T> t) {
184
// return new BitwiseOr<T>(t);
185
// }
186

187 // /**
188
// */
189
// @SuppressWarnings("unchecked")
190
// static public <T extends Number> UnaryFunctor<T,T> or(T value) {
191
// return new BitwiseOr<T>((Class<T>) value.getClass()).bind2nd(value);
192
// }
193

194     /**
195      */

196     static public <T extends Number JavaDoc> BinaryFunctor<T,T,T> plus(Class JavaDoc<T> t) {
197         return new Plus<T>(t);
198     }
199
200     /**
201      */

202     @SuppressWarnings JavaDoc("unchecked")
203     static public <T extends Number JavaDoc> UnaryFunctor<T,T> plus(T value) {
204         return new Plus<T>((Class JavaDoc<T>) value.getClass()).bind2nd(value);
205     }
206
207     /**
208      */

209     static public <T extends Number JavaDoc> BinaryFunctor<T,Integer JavaDoc,T> shiftLeft(Class JavaDoc<T> t) {
210         return new ShiftLeft<T>(t);
211     }
212
213
214     /**
215      */

216     static public <T extends Number JavaDoc> BinaryFunctor<T,Integer JavaDoc,T> shiftRight(Class JavaDoc<T> t) {
217         return new ShiftRight<T>(t);
218     }
219     
220     /**
221      */

222     static public <T extends Number JavaDoc> BinaryFunctor<T,Integer JavaDoc,T> unsignedShiftRight(Class JavaDoc<T> t) {
223         return new UnsignedShiftRight<T>(t);
224     }
225
226     /**
227      */

228     static public <T extends Number JavaDoc,R extends Number JavaDoc> UnaryFunctor<T,R> valueOf(Class JavaDoc<R> r) {
229         return new ValueOf<T,R>(r);
230     }
231     
232 // /**
233
// */
234
// static public <T extends Number> BinaryFunctor<T,T,T> xor(Class<T> t) {
235
// return new BitwiseXor<T>(t);
236
// }
237

238 // /**
239
// */
240
// @SuppressWarnings("unchecked")
241
// static public <T extends Number> UnaryFunctor<T,T> xor(T value) {
242
// return new BitwiseXor<T>((Class<T>) value.getClass()).bind2nd(value);
243
// }
244
}
245
246
Popular Tags