Package eu.bandm.tools.util
Class DynamicVisitor<C>
java.lang.Object
eu.bandm.tools.util.DynamicVisitor<C>
An abstract base class for reflection-based type case
distinctions. Subclasses should overload the
visit(C, boolean)
method with a method void visit(A x)
to match
objects of class A
. 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
visit
, and - exactly
one parameter of a subclass of
C
.
void
do match, but their result
is ignored.-
Constructor Summary
-
Method Summary
-
Constructor Details
-
DynamicVisitor
public DynamicVisitor()
-
-
Method Details
-
visit
Finds the best-matchingvisit
method for the dynamic type of a given object and invokes it.- Parameters:
x
- the input object.total
- iftrue
andx
isnull
or no match is found, then nothing is done.- Throws:
IllegalArgumentException
- if the matching method throws an exception or cannot be invoked for some reason, or iftotal
isfalse
and no match is found.NullPointerException
- iftotal
is false andx
isnull
.
-