Package eu.bandm.tools.util
Class DynamicMatcher<C>
java.lang.Object
eu.bandm.tools.util.DynamicMatcher<C>
An abstract base class for reflection-based type case
distinctions. Subclasses should specify a method name and
overload it with methods
B rewrite(A x)
to
match objects of class A
, and return objects of class
B
. Methods of subclasses will only be considered as
matches for an input if they have -
public
access to be retrieved withClass.getMethod(java.lang.String, java.lang.Class<?>...)
, - the specified name, and
- exactly one parameter of a subclass of
C
.
-
Field Summary
-
Constructor Summary
-
Method Summary
-
Field Details
-
phaseNames
-
-
Constructor Details
-
DynamicMatcher
-
-
Method Details
-
getMatchFor
-
match
Finds the best-matchingrewrite
method for the dynamic type of a given object and invokes it.- Parameters:
targetClass
- the expected class of the result.x
- the input object.- Throws:
IllegalArgumentException
- if the matching method throws an exception or cannot be invoked for some reason, or if no match is found.ClassCastException
- if the result cannot be cast to the classtargetClass
.NullPointerException
- ifx
isnull
.
-