KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > nuts > optional > BinaryAssertionNut


1 package jfun.yan.xml.nuts.optional;
2
3 import jfun.yan.Component;
4 import jfun.yan.Components;
5 import jfun.yan.Map2;
6 import jfun.yan.Monad;
7
8
9 /**
10  * Super class for any Nut that supports "val1" and "val2" attributes
11  * and checks a binary predicate on them.
12  * <p>
13  * @author Ben Yu
14  * Nov 9, 2005 11:56:26 PM
15  */

16 public abstract class BinaryAssertionNut extends BinaryNut {
17   /**
18    * Apply the binary assertion.
19    * @param v1 the first value.
20    * @param v2 the second value.
21    */

22   public abstract void assertion(Object JavaDoc v1, Object JavaDoc v2);
23   public Component eval(){
24     if(!isVal1Set() || !isVal2Set())
25       throw raise("both values should be set for comparison.");
26     final Map2 cmp = new Map2(){
27       public Object JavaDoc map(Object JavaDoc o1, Object JavaDoc o2){
28         assertion(o1, o2);
29         return Components.value(null);
30       }
31     };
32     final Component c1 = getComponent1();
33     final Component c2 = getComponent2();
34     return Monad.map(c1, c2, cmp);
35     /*assertion(getVal1(), getVal2());
36     return Components.value(true);*/

37   }
38
39 }
40
Popular Tags