|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjigcell.compare.data.MethodDispatcher
public class MethodDispatcher
Performs automated method dispatching based on a tuneable heuristic.
This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details.
| Nested Class Summary | |
|---|---|
protected static class |
MethodDispatcher.MethodScorer
Intermediate results for computing a method score. |
protected static class |
MethodDispatcher.NoDispatchableMethodException
Indicates that method dispatching failed because no suitable methods were found. |
| Field Summary | |
|---|---|
protected boolean |
allowWildcardMatches
Whether wildcard matches of the method name are allowed |
protected static char |
CLASS_ARRAY
Character representing an array reference |
protected static java.lang.String |
CLASS_BOOLEAN
Character representing a boolean reference |
protected static java.lang.String |
CLASS_CHARACTER
Character representing a character reference |
protected static java.lang.String |
CLASS_DOUBLE
Character representing a double reference |
protected static java.lang.String |
CLASS_FLOAT
Character representing a float reference |
protected static java.lang.String |
CLASS_INTEGER
Character representing an integer reference |
protected static java.lang.String |
CLASS_LONG
Character representing a long reference |
protected static java.lang.String |
CLASS_OBJECT_END
Character representing an object reference |
protected static java.lang.String |
CLASS_OBJECT_START
Character representing an object reference |
protected static java.lang.String |
CLASS_SHORT
Character representing a short reference |
protected static java.lang.reflect.Method |
CONVERTER_LONGDOUBLE
Converter from Long to Double |
static long |
DEFAULT_PENALTYLENGTH
Default penalty value for length mismatches |
static long |
DEFAULT_PENALTYLOOSEMATCH
Default penalty value for loose matches. |
static long |
DEFAULT_REWARDMATCH
Default value for a match. |
static long |
DEFAULT_REWARDSUBCLASS
Default value for having a specialized match. |
protected static long |
ERROR
Maximally bad score |
protected static java.util.Map |
MAP_CLASSNAMETYPE
Map from primitive class names to formalTypes |
protected static java.util.Map |
MAP_CLASSTYPENAME
Map from primitive class formalTypes to names |
protected static java.lang.String |
MESSAGE_METHOD
Beginning of a method error message |
protected static java.lang.String |
MESSAGE_NOTIMPLEMENTED
Error message when an unimplemented function is invoked |
protected static java.lang.String |
MESSAGE_PARAMETERERROR
Error message when the parameter formalType of a method is illegal |
protected static java.lang.String |
MESSAGE_RETURNERROR
Error message when the return formalType of a method is illegal |
protected static java.lang.String |
MESSAGE_TOOBIGERROR
Error message when an element is larger than can be reflected |
protected static java.lang.String |
METHOD_LONGDOUBLE
Name of the method to convert a Long to a Double |
protected java.lang.String |
methodName
Name of the method to invoke |
protected java.util.HashMap |
parameterTypeCache
Map between the known methods and their formalType signature |
protected long |
penaltyLength
Penalty value for length mismatches |
protected boolean |
penaltyLengthChecked
Whether length mismatches are allowed |
protected long |
penaltyLooseMatch
Penalty value for loose matches |
protected boolean |
penaltyLooseMatchChecked
Whether loose formalType matches are allowed |
protected long |
rewardMatch
Reward value for a match |
protected long |
rewardSubclass
Reward value for having a specialized match |
protected boolean |
rewardSubclassChecked
Whether specialized matches are rewarded |
protected java.lang.Object |
target
Target of method invocations |
| Constructor Summary | |
|---|---|
MethodDispatcher(java.lang.Object target,
java.lang.String methodName)
Creates a new method dispatcher. |
|
| Method Summary | |
|---|---|
static java.lang.Class |
computePrimitiveBox(java.lang.Class clazz)
Boxes a primitive formalType or returns the formalType unchanged if it is not a primitive formalType. |
static java.lang.Object |
convertArrayClass(java.lang.Object array,
java.lang.Class clazz,
java.lang.reflect.Method converter)
Converts an array from one formalType to another. |
static java.lang.Object |
convertFromElement(IDataElement element)
Converts a DataElement to a collection of objects. |
static java.lang.Double |
convertLongDouble(java.lang.Long l)
Converts a Long to a Double. |
static IDataElement |
convertToElement(java.lang.Object o)
Converts a collection of objects to a DataElement. |
static java.lang.Class |
createArrayClass(java.lang.Class clazz,
int dimension)
Creates a multidimensional array formalType. |
protected void |
createTypeCache()
Fills in the entries of the parameter formalType cache. |
IDataElement |
dispatch(IDataElement element)
Performs method dispatching on the target with a DataElement. |
java.lang.Object |
dispatch(java.lang.Object o)
Performs method dispatching on the target with a collection of objects. |
protected java.lang.Object |
dispatchExact(MethodDispatcher.MethodScorer scorer,
java.lang.reflect.Method method)
Dispatches an exact match. |
protected java.lang.Object |
dispatchLoose(MethodDispatcher.MethodScorer scorer,
java.lang.reflect.Method method)
Dispatches a loose match. |
static java.lang.Class |
findCommonSuperclass(java.lang.Object[] objects)
The common superclass for a collection of objects. |
boolean |
getAllowWildcardMatches()
Whether wildcard matches are allowed. |
static int |
getDimension(java.lang.Class clazz)
The dimension of a formalType. |
java.lang.String |
getMethodName()
Name of the method to invoke. |
long |
getPenaltyLength()
The penalty for length mismatches. |
boolean |
getPenaltyLengthChecked()
Whether length mismatches are allowed. |
long |
getPenaltyLooseMatch()
The penalty for loose formalType matches. |
boolean |
getPenaltyLooseMatchChecked()
Whether loose formalType matches are allowed. |
long |
getRewardMatch()
The reward for matches. |
long |
getRewardSubclass()
The reward for specialized matches. |
boolean |
getRewardSubclassChecked()
Whether specialized matches are rewarded. |
java.lang.Object |
getTarget()
The target to invoke. |
static java.lang.Class |
getUnderlyingClass(java.lang.Class clazz)
The non-array formalType of a formalType. |
static boolean |
isConvertibleClass(java.lang.Class clazz)
Whether a class is of a convertible formalType. |
protected long |
scoreExact(MethodDispatcher.MethodScorer scorer)
Scores for exact matches. |
protected long |
scoreLoose(MethodDispatcher.MethodScorer scorer)
Scores for loose matches. |
void |
setAllowWildcardMatches(boolean allowWildcardMatches)
Sets whether wildcard matches are allowed. |
void |
setMethodName(java.lang.String methodName)
Sets the name of the method to invoke. |
void |
setPenaltyLength(long penaltyLength)
Sets the penalty for length mismatches. |
void |
setPenaltyLengthChecked(boolean penaltyLengthChecked)
Sets whether length mismatches are allowed. |
void |
setPenaltyLooseMatch(long penaltyLooseMatch)
Sets the penalty for loose formalType matches. |
void |
setPenaltyLooseMatchChecked(boolean penaltyLooseMatchChecked)
Sets whether loose formalType matches are allowed. |
void |
setRewardMatch(long rewardMatch)
Sets the reward for matches. |
void |
setRewardSubclass(long rewardSubclass)
Sets the reward for specialized matches. |
void |
setRewardSubclassChecked(boolean rewardSubclassChecked)
Sets whether specialized matches are rewarded. |
void |
setTarget(java.lang.Object target)
Sets the target to invoke. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long DEFAULT_REWARDMATCH
public static final long DEFAULT_REWARDSUBCLASS
public static final long DEFAULT_PENALTYLENGTH
public static final long DEFAULT_PENALTYLOOSEMATCH
protected static final char CLASS_ARRAY
protected static final java.util.Map MAP_CLASSTYPENAME
protected static final java.util.Map MAP_CLASSNAMETYPE
protected static final java.lang.String CLASS_BOOLEAN
protected static final java.lang.String CLASS_CHARACTER
protected static final java.lang.String CLASS_DOUBLE
protected static final java.lang.String CLASS_FLOAT
protected static final java.lang.String CLASS_INTEGER
protected static final java.lang.String CLASS_LONG
protected static final java.lang.String CLASS_OBJECT_START
protected static final java.lang.String CLASS_OBJECT_END
protected static final java.lang.String CLASS_SHORT
protected static final java.lang.String METHOD_LONGDOUBLE
protected static final java.lang.String MESSAGE_METHOD
protected static final java.lang.String MESSAGE_NOTIMPLEMENTED
protected static final java.lang.String MESSAGE_PARAMETERERROR
protected static final java.lang.String MESSAGE_RETURNERROR
protected static final java.lang.String MESSAGE_TOOBIGERROR
protected static final long ERROR
protected static java.lang.reflect.Method CONVERTER_LONGDOUBLE
protected boolean allowWildcardMatches
protected boolean penaltyLengthChecked
protected boolean penaltyLooseMatchChecked
protected boolean rewardSubclassChecked
protected transient java.util.HashMap parameterTypeCache
protected long penaltyLength
protected long penaltyLooseMatch
protected long rewardMatch
protected long rewardSubclass
protected java.lang.Object target
protected java.lang.String methodName
| Constructor Detail |
|---|
public MethodDispatcher(java.lang.Object target,
java.lang.String methodName)
target - Object to dispatch tomethodName - Name of method to invoke| Method Detail |
|---|
public static java.lang.Class computePrimitiveBox(java.lang.Class clazz)
clazz - Class
public static java.lang.Object convertArrayClass(java.lang.Object array,
java.lang.Class clazz,
java.lang.reflect.Method converter)
array - Arrayclazz - New formalTypeconverter - Method that takes the objectified formalType of the underlying class of array as a parameter and returns an object of the
objectified formalType of formalType clazzpublic static java.lang.Object convertFromElement(IDataElement element)
element - Elementpublic static java.lang.Double convertLongDouble(java.lang.Long l)
l - Longpublic static IDataElement convertToElement(java.lang.Object o)
o - Objects
public static java.lang.Class createArrayClass(java.lang.Class clazz,
int dimension)
clazz - Type classdimension - Dimensionpublic static java.lang.Class findCommonSuperclass(java.lang.Object[] objects)
objects - Objectspublic static int getDimension(java.lang.Class clazz)
clazz - Classpublic static java.lang.Class getUnderlyingClass(java.lang.Class clazz)
clazz - Classpublic static boolean isConvertibleClass(java.lang.Class clazz)
clazz - Class
public IDataElement dispatch(IDataElement element)
throws MethodDispatcher.NoDispatchableMethodException
element - Element
MethodDispatcher.NoDispatchableMethodException
public java.lang.Object dispatch(java.lang.Object o)
throws MethodDispatcher.NoDispatchableMethodException
o - Objects
MethodDispatcher.NoDispatchableMethodExceptionpublic boolean getAllowWildcardMatches()
public java.lang.String getMethodName()
public long getPenaltyLength()
public boolean getPenaltyLengthChecked()
public long getPenaltyLooseMatch()
public boolean getPenaltyLooseMatchChecked()
public long getRewardMatch()
public long getRewardSubclass()
public boolean getRewardSubclassChecked()
public java.lang.Object getTarget()
public void setAllowWildcardMatches(boolean allowWildcardMatches)
allowWildcardMatches - Whether wildcard matches are allowedpublic void setMethodName(java.lang.String methodName)
methodName - Namepublic void setPenaltyLength(long penaltyLength)
penaltyLength - The penalty for length mismatchespublic void setPenaltyLengthChecked(boolean penaltyLengthChecked)
penaltyLengthChecked - Whether length mismatches are allowedpublic void setPenaltyLooseMatch(long penaltyLooseMatch)
penaltyLooseMatch - The penalty for loose formalType matchespublic void setPenaltyLooseMatchChecked(boolean penaltyLooseMatchChecked)
penaltyLooseMatchChecked - Whether loose formalType matches are allowedpublic void setRewardMatch(long rewardMatch)
rewardMatch - The rewarded for matchespublic void setRewardSubclass(long rewardSubclass)
rewardSubclass - The rewarded for specialized matchespublic void setRewardSubclassChecked(boolean rewardSubclassChecked)
rewardSubclassChecked - Whether specialized matches are rewardedpublic void setTarget(java.lang.Object target)
target - Targetprotected void createTypeCache()
protected java.lang.Object dispatchExact(MethodDispatcher.MethodScorer scorer,
java.lang.reflect.Method method)
throws MethodDispatcher.NoDispatchableMethodException
method - Method
MethodDispatcher.NoDispatchableMethodException
protected java.lang.Object dispatchLoose(MethodDispatcher.MethodScorer scorer,
java.lang.reflect.Method method)
throws MethodDispatcher.NoDispatchableMethodException
method - Method
MethodDispatcher.NoDispatchableMethodExceptionprotected long scoreExact(MethodDispatcher.MethodScorer scorer)
protected long scoreLoose(MethodDispatcher.MethodScorer scorer)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||