KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > FloatingFieldFunction


1 package jfun.yan;
2
3 import jfun.util.SerializableField;
4 import jfun.yan.function.Function;
5
6
7 /**
8  * For an instance field with the receiver object not fixed.
9  * <p>
10  * Zephyr Business Solution
11  *
12  * @author Ben Yu
13  *
14  */

15 final class FloatingFieldFunction implements Function {
16   private final Class JavaDoc type;
17   private final SerializableField fld;
18   public boolean isConcrete(){
19     return false;
20   }
21   FloatingFieldFunction(final Class JavaDoc type,
22       final java.lang.reflect.Field JavaDoc fld) {
23     this.type = type;
24     this.fld = new SerializableField(fld);
25   }
26   public Class JavaDoc getReturnType() {
27     return fld.getField().getType();
28   }
29   public Class JavaDoc[] getParameterTypes() {
30     return new Class JavaDoc[]{type};
31   }
32   public Object JavaDoc call(Object JavaDoc[] args)
33   throws IllegalAccessException JavaDoc{
34     return fld.getField().get(args[0]);
35   }
36
37   public boolean equals(Object JavaDoc obj) {
38     if(obj instanceof FloatingFieldFunction){
39       final FloatingFieldFunction other = (FloatingFieldFunction)obj;
40       return type.equals(other.type) && fld.equals(other.fld);
41     }
42     else return false;
43   }
44   public int hashCode() {
45     return type.hashCode()*31+fld.hashCode();
46   }
47   public String JavaDoc toString() {
48     return jfun.util.Misc.getTypeName(type)
49       + "::" + fld.getField().getName();
50   }
51   public String JavaDoc getName(){
52     return fld.getField().getName();
53   }
54 }
55
Popular Tags