Package eu.bandm.tools.util
Class DynamicRewriter<C>
java.lang.Object
eu.bandm.tools.util.DynamicRewriter<C>
An abstract base class for reflection-based type case
distinctions. Subclasses should overload the
rewrite(java.lang.Class<R>, C, boolean)
method with a method B rewrite(A x)
to match
objects of class A
, and replace them by 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 name
rewrite
, and - exactly one parameter of a subclass
of
C
.
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
DynamicRewriter
public DynamicRewriter()
-
-
Method Details
-
rewrite
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.total
- iftrue
andx
isnull
or no match is found, thenx
is cast to the classtargetClass
and returned.- Throws:
IllegalArgumentException
- if the matching method throws an exception or cannot be invoked for some reason, or iftotal
isfalse
and no match is found.ClassCastException
- if the result cannot be cast to the classtargetClass
.NullPointerException
- iftotal
is false andx
isnull
.
-