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: * Function backed by a Java method.
13: * @author <a href="http://www-ist.massey.ac.nz/JBDietrich/">Jens Dietrich</a>
14: */
15:
16: public class JFunction implements Function {
17:
18: private java.lang.reflect.Method method = null;
19:
20: public String getName() {
21: return method == null ? null : method.getName();
22: }
23:
24: public java.lang.reflect.Method getMethod() {
25: return method;
26: }
27:
28: public void setMethod(java.lang.reflect.Method method) {
29: this .method = method;
30: }
31:
32: public Class[] getParamTypes() {
33: return method.getParameterTypes();
34: }
35:
36: public Class getReturnType() {
37: return method.getReturnType();
38: }
39:
40: public String toString() {
41: return method.getName();
42: }
43:
44: @Override
45: public int hashCode() {
46: final int prime = 31;
47: int result = 1;
48: result = prime * result
49: + ((method == null) ? 0 : method.hashCode());
50: return result;
51: }
52:
53: @Override
54: public boolean equals(Object obj) {
55: if (this == obj)
56: return true;
57: if (obj == null)
58: return false;
59: if (getClass() != obj.getClass())
60: return false;
61: final JFunction other = (JFunction) obj;
62: if (method == null) {
63: if (other.method != null)
64: return false;
65: } else if (!method.equals(other.method))
66: return false;
67: return true;
68: }
69:
70: }
|