Package org.boris.expr

Examples of org.boris.expr.Expr


public class UPPER extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);
        Expr a = evalArg(args[0]);
        if (a instanceof ExprArray)
            return ExprError.VALUE;
        if (a instanceof ExprString)
            return new ExprString(((ExprString) a).str.toUpperCase());
        return new ExprString(a.toString().toUpperCase());
    }
View Full Code Here


public class LOWER extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);
        Expr a = evalArg(args[0]);
        if (a instanceof ExprArray)
            return ExprError.VALUE;
        if (a instanceof ExprString)
            return new ExprString(((ExprString) a).str.toLowerCase());
        return new ExprString(a.toString().toLowerCase());
    }
View Full Code Here

public class REPT extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 2);
        Expr str = evalArg(args[0]);
        if (str instanceof ExprArray) {
            str = ((ExprArray) str).get(0);
        }
        int rep = asInteger(args[1], true);
        if (rep < 0)
            return ExprError.VALUE;
        switch (rep) {
        case 0:
            return ExprString.EMPTY;
        case 1:
            return evalArg(args[0]);
        default:
            String s = str.toString();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < rep; i++) {
                sb.append(s);
            }
            return new ExprString(sb.toString());
View Full Code Here

{
    public Expr evaluate(Expr[] args) throws ExprException {
        if (args.length < 2)
            throw new ExprException("Too few arguments for CHOOSE");

        Expr index = args[0];
        if (index instanceof ExprEvaluatable)
            index = ((ExprEvaluatable) index).evaluate();

        if (!(index instanceof ExprNumber)) {
            throw new ExprException(
View Full Code Here

public class TRIM extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);
        Expr a = evalArg(args[0]);
        if (a instanceof ExprArray)
            return ExprError.VALUE;
        String str = null;
        if (a instanceof ExprString)
            str = ((ExprString) a).str;
        else
            str = a.toString();
        return new ExprString(str.trim());
    }
View Full Code Here

            throw new ExprException("Too few arguments entered for function IF");
        if (args.length > 3)
            throw new ExprException(
                    "Too many arguments entered for function IF");

        Expr cond = evalArg(args[0]);
        Expr yRes = args[1];
        Expr nRes = null;
        if (args.length == 2) {
            nRes = ExprBoolean.FALSE;
        } else {
            nRes = args[2];
        }
        if (cond instanceof ExprNumber) {
            Expr res = evalArg(((ExprNumber) cond).booleanValue() ? yRes : nRes);
            if (res instanceof ExprMissing) {
                res = ExprDouble.ZERO;
            }
            return res;
        }
View Full Code Here

public class ISLOGICAL extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);
        Expr e = evalArg(args[0]);
        return bool(e instanceof ExprBoolean);
    }
View Full Code Here

public class ISNONTEXT extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);
        Expr e = evalArg(args[0]);
        return bool(!(e instanceof ExprString) ||
                "".equals(((ExprString) e).str));
    }
View Full Code Here

public class BETADIST extends AbstractFunction
{
    public Expr evaluate(Expr[] args) throws ExprException {
        assertMinArgCount(args, 3);
        assertMaxArgCount(args, 5);
        Expr eX = evalArg(args[0]);
        if (!isNumber(eX))
            return ExprError.VALUE;
        double x = ((ExprNumber) eX).doubleValue();
        Expr eAlpha = evalArg(args[1]);
        if (!isNumber(eAlpha))
            return ExprError.VALUE;
        double alpha = ((ExprNumber) eAlpha).doubleValue();
        if (alpha <= 0)
            return ExprError.NUM;
        Expr eBeta = evalArg(args[2]);
        if (!isNumber(eBeta))
            return ExprError.VALUE;
        double beta = ((ExprNumber) eBeta).doubleValue();
        if (beta <= 0)
            return ExprError.NUM;
        double a = 0, b = 1;
        if (args.length > 3) {
            Expr eA = evalArg(args[3]);
            if (!isNumber(eA))
                return ExprError.VALUE;
            a = ((ExprNumber) eA).doubleValue();
        }
        if (args.length > 4) {
            Expr eB = evalArg(args[4]);
            if (!isNumber(eB))
                return ExprError.VALUE;
            b = ((ExprNumber) eB).doubleValue();
        }
        if (x < a || x > b || a == b)
View Full Code Here

{
    private static final ExprString EMPTY = new ExprString("");

    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);
        Expr a = evalArg(args[0]);

        if (a instanceof ExprString) {
            return a;
        } else {
            return EMPTY;
View Full Code Here

TOP

Related Classes of org.boris.expr.Expr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.