11 |
* transparent run-time data-sensitive caching and super-lazy caching. |
* transparent run-time data-sensitive caching and super-lazy caching. |
12 |
*/ |
*/ |
13 |
public abstract class Functional { |
public abstract class Functional { |
14 |
|
public static boolean dbg = false; |
15 |
|
private void p(String s) { System.out.println(s); } |
16 |
|
|
17 |
/** Hints about a Function class. |
/** Hints about a Function class. |
18 |
* Hints tell the Functional API about a Function: is it slow to evaluate, |
* Hints tell the Functional API about a Function: is it slow to evaluate, |
122 |
// If it's a node, allow functions and nodefunctions. |
// If it's a node, allow functions and nodefunctions. |
123 |
if(FunctionInstance.class.isAssignableFrom(givenParamType)) { |
if(FunctionInstance.class.isAssignableFrom(givenParamType)) { |
124 |
if(ptypes[j].isAssignableFrom(Function.class) || |
if(ptypes[j].isAssignableFrom(Function.class) || |
125 |
ptypes[j].isAssignableFrom(NodeFunction.class)) |
ptypes[j].isAssignableFrom(NodeFunction.class)) { |
126 |
|
if (dbg) p("MATCH: "+givenParamType+", "+ptypes[j]); |
127 |
continue PARAMETERS; |
continue PARAMETERS; |
128 |
|
} |
129 |
} |
} |
130 |
|
|
131 |
if(! ptypes[j].isAssignableFrom(givenParamType)) |
// Allow float parameter for double and integer. |
132 |
|
if(ptypes[j].isAssignableFrom(java.lang.Float.TYPE)) { |
133 |
|
if (parameters[j] instanceof java.lang.Double) { |
134 |
|
parameters[j] = new java.lang.Float(((java.lang.Double)parameters[j]).floatValue()); |
135 |
|
if (dbg) p("MATCH: "+givenParamType+", "+ptypes[j]); |
136 |
|
continue PARAMETERS; |
137 |
|
} else if (parameters[j] instanceof java.lang.Integer) { |
138 |
|
parameters[j] = new java.lang.Float(((java.lang.Integer)parameters[j]).floatValue()); |
139 |
|
if (dbg) p("MATCH: "+givenParamType+", "+ptypes[j]); |
140 |
|
continue PARAMETERS; |
141 |
|
} |
142 |
|
} |
143 |
|
|
144 |
|
// Allow double parameter for float. |
145 |
|
if(ptypes[j].isAssignableFrom(java.lang.Double.TYPE)) { |
146 |
|
if (parameters[j] instanceof java.lang.Float) { |
147 |
|
parameters[j] = new java.lang.Double(((java.lang.Float)parameters[j]).doubleValue()); |
148 |
|
if (dbg) p("MATCH: "+givenParamType+", "+ptypes[j]); |
149 |
|
continue PARAMETERS; |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
|
if(! ptypes[j].isAssignableFrom(givenParamType)) { |
154 |
|
if (dbg) p("DISMATCH: "+givenParamType+", "+ptypes[j]); |
155 |
continue CONSTRUCTORS; |
continue CONSTRUCTORS; |
156 |
|
} |
157 |
|
if (dbg) p("MATCH: "+givenParamType+", "+ptypes[j]); |
158 |
} |
} |
159 |
return constructors[i]; |
return constructors[i]; |
160 |
} |
} |