com.github.dakusui.lisj.pred.Comp Maven / Gradle / Ivy
package com.github.dakusui.lisj.pred;
import static com.github.dakusui.lisj.Basic.get;
import com.github.dakusui.jcunit.core.Utils;
import com.github.dakusui.lisj.Context;
import com.github.dakusui.lisj.FormResult;
public abstract class Comp extends BinomialPredicate {
/**
* Serial version UID.
*/
private static final long serialVersionUID = 234943933153946011L;
@Override
protected Object checkParams(Object params) {
super.checkParams(params);
Utils.checknull(get(params, 0));
Utils.checknull(get(params, 1));
return params;
}
@Override
protected FormResult evaluateLast(Context context, Object[] evaluatedParams, FormResult lastResult) {
FormResult ret = lastResult;
Object value = evaluatedParams[0];
Object another = evaluatedParams[1];
if (value == null || !(value instanceof Comparable)) throw new IllegalArgumentException(msgIllegalArgumentFound(value, evaluatedParams));
if (another == null || !(another instanceof Comparable)) throw new IllegalArgumentException(msgIllegalArgumentFound(another, evaluatedParams));
ret.value(evaluate(value, another));
return ret;
}
protected abstract boolean evaluate(Object value, Object another);
@SuppressWarnings("unchecked")
protected int compare(
@SuppressWarnings("rawtypes") Comparable a,
@SuppressWarnings("rawtypes") Comparable b
) {
return a.compareTo(b);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy