01: /**
02: * Copyright 2007 Jens Dietrich Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
05: * Unless required by applicable law or agreed to in writing, software distributed under the
06: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
07: * either express or implied. See the License for the specific language governing permissions
08: * and limitations under the License.
09: */package nz.org.take;
10:
11: /**
12: * Functions representing binary operations on numbers.
13: * @author <a href="http://www-ist.massey.ac.nz/JBDietrich/">Jens Dietrich</a>
14: */
15:
16: public class BinaryArithmeticFunction implements Function {
17:
18: private String name = null;
19: private Class returnType = null;
20: private Class[] paramTypes = null;
21:
22: public static BinaryArithmeticFunction getInstance(String name,
23: Class type1, Class type2) {
24: Class returnType = PrimitiveTypeUtils
25: .getBinOperationReturnType(type1, type2);
26: return new BinaryArithmeticFunction(name, returnType, type1,
27: type2);
28: }
29:
30: public BinaryArithmeticFunction() {
31: super ();
32: }
33:
34: public BinaryArithmeticFunction(String name, Class returnType,
35: Class paramType1, Class paramType2) {
36: super ();
37: this .name = name;
38: this .returnType = returnType;
39: this .paramTypes = new Class[] { paramType1, paramType2 };
40: }
41:
42: public String getName() {
43: return name;
44: }
45:
46: public void setName(String name) {
47: this .name = name;
48: }
49:
50: public Class getReturnType() {
51: return returnType;
52: }
53:
54: public void setReturnType(Class returnType) {
55: this .returnType = returnType;
56: }
57:
58: public Class[] getParamTypes() {
59: return paramTypes;
60: }
61:
62: public void setParamTypes(Class[] paramTypes) {
63: this .paramTypes = paramTypes;
64: }
65:
66: @Override
67: public String toString() {
68: return name == null ? super.toString() : name;
69: }
70:
71: }
|