package jfun.yan.xml.nuts.optional;
import jfun.yan.Component;
import jfun.yan.Components;
import jfun.yan.Map2;
import jfun.yan.Monad;
/**
* Super class for any Nut that supports "val1" and "val2" attributes
* and checks a binary predicate on them.
* <p>
* @author Ben Yu
* Nov 9, 2005 11:56:26 PM
*/
public abstract class BinaryAssertionNut extends BinaryNut {
/**
* Apply the binary assertion.
* @param v1 the first value.
* @param v2 the second value.
*/
public abstract void assertion(Object v1, Object v2);
public Component eval(){
if(!isVal1Set() || !isVal2Set())
throw raise("both values should be set for comparison.");
final Map2 cmp = new Map2(){
public Object map(Object o1, Object o2){
assertion(o1, o2);
return Components.value(null);
}
};
final Component c1 = getComponent1();
final Component c2 = getComponent2();
return Monad.map(c1, c2, cmp);
/*assertion(getVal1(), getVal2());
return Components.value(true);*/
}
}