|
JMMF API pre-release v0.7 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--fr.umlv.jmmf.matcher.PatternMatcher
This class ease the use of multi-polymorphism. A simple way to use it consist in subclassing the PatternMatcher class. An example on a tree recursive type :
public class Test extends PatternMatcher
{
interface Tree {}
static class Leaf implements Tree {
Leaf(int value) {
this.value=value;
}
int value;
}
static class Node implements Tree {
Node(Tree left,Tree right) {
this.left=left; this.right=right;
}
Tree left,right;
}
public int sum(Node node)
{ return sum(left)+sum(right); }
public int sum(Leaf leaf)
{ return value; }
public int sum(Tree tree)
{ return ((Integer)match("sum",tree)).intValue(); }
public static void main(String[] args) {
Tree tree=new Node(new Node(new Leaf(1),new Leaf(3)),new Leaf(7));
System.out.println("sum "+new Test().sum(tree));
}
}
| Constructor Summary | |
PatternMatcher()
create a pattern matcher component. |
|
PatternMatcher(java.lang.Object bean)
create a pattern matcher component on a bean object. |
|
PatternMatcher(java.lang.Object bean,
MultiFactory factory)
create a pattern matcher component on a bean object. |
|
| Method Summary | |
java.lang.Object |
match(java.lang.String name,
java.lang.Object arg)
lookup the best method in the multi-method named name and invoke it. |
java.lang.Object |
match(java.lang.String name,
java.lang.Object[] args)
lookup the best method in the multi-method named name and invoke it. |
java.lang.Object |
match(java.lang.String name,
java.lang.Object[] args,
java.lang.Class[] classes)
lookup the best method in the multi-method named name and invoke it. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public PatternMatcher()
public PatternMatcher(java.lang.Object bean)
public PatternMatcher(java.lang.Object bean,
MultiFactory factory)
| Method Detail |
public java.lang.Object match(java.lang.String name,
java.lang.Object arg)
name - name of the multi-method.arg - first parameter of the multi-method.NoMatchingMethodException - there is no method that
match the parameter arguments.MultipleMatchingMethodsException - there is no method that
match the parameter arguments.MatchingMethodInvocationException - throws by
the target method invoked.IllegalStateException - is method find isn't accessible,
due to an internal error.match(String, Object[], Class[])
public java.lang.Object match(java.lang.String name,
java.lang.Object[] args)
name - name of the multi-method.args - parameters of the multi-method.NoMatchingMethodException - there is no method that
match the parameter arguments.MultipleMatchingMethodsException - there is no method that
match the parameter arguments.MatchingMethodInvocationException - throws by
the target method invoked.IllegalStateException - is method find isn't accessible,
due to an internal error.match(String, Object[], Class[])
public java.lang.Object match(java.lang.String name,
java.lang.Object[] args,
java.lang.Class[] classes)
name - name of the multi-method.args - parameters of the multi-method.classes - type of the parameter.NoMatchingMethodException - there is no method that
match the parameter arguments.MultipleMatchingMethodsException - there is no method that
match the parameter arguments.MatchingMethodInvocationException - throws by
the target method invoked.IllegalStateException - is method find isn't accessible,
due to an internal error.
|
JMMF API pre-release v0.7 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||