Package org.boris.expr.engine

Examples of org.boris.expr.engine.Range


    public void valueChanged(Range range, Expr value) {
        System.out.println("Value changed: " + range + "=\n" + value);
    }

    public void validate(ExprVariable variable) throws ExprException {
        Range r = (Range) variable.getAnnotation();
        if (r == null) {
            r = Range.valueOf(variable.getName());
        }

        validate(r.getDimension1());
        validate(r.getDimension2());
    }
View Full Code Here


    public static Expr columnsOrRows(Expr[] args, boolean cols)
            throws ExprException {

        if (args[0] instanceof ExprVariable) {
            ExprVariable v = (ExprVariable) args[0];
            Range r = (Range) v.getAnnotation();
            if (r == null) {
                r = Range.valueOf(v.getName());
            }
            if (r != null && r.getDimension1() != null) {
                GridReference dim1 = r.getDimension1();
                GridReference dim2 = r.getDimension2();
                if (dim2 == null) {
                    return new ExprInteger(1);
                } else {
                    if (cols) {
                        return new ExprInteger(Math.abs(dim2.getColumn() -
View Full Code Here

    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);

        if (args[0] instanceof ExprVariable) {
            ExprVariable v = (ExprVariable) args[0];
            Range r = (Range) v.getAnnotation();
            if (r == null) {
                r = Range.valueOf(v.getName());
            }
            if (r != null && r.getDimension1() != null) {
                return new ExprInteger(r.getDimension1().getRow());
            }

            return ExprError.NAME;
        }
View Full Code Here

        assertNull(GridReference.valueOf("   "));
        assertGrid(GridReference.valueOf("$A$1"), 1, true, 1, true);
    }

    public void testRange() throws Exception {
        assertEquals(Range.valueOf("Sheet1!A5:$G$7"), new Range("Sheet1",
                new GridReference(1, 5), new GridReference(7, true, 7, true)));
        assertEquals(Range.valueOf("A5:$G$7"), new Range(null,
                new GridReference(1, 5), new GridReference(7, true, 7, true)));
        assertEquals(Range.valueOf("$G$7"), new Range(null, new GridReference(
                7, true, 7, true), null));
        assertFalse(Range.valueOf("$G$7").equals(
                new Range(null, new GridReference(7, false, 7, true), null)));
        testInvalidRange("!asdf");
        testInvalidRange("Sheet!!");
    }
View Full Code Here

    public Expr evaluate(Expr[] args) throws ExprException {
        assertArgCount(args, 1);

        if (args[0] instanceof ExprVariable) {
            ExprVariable v = (ExprVariable) args[0];
            Range r = (Range) v.getAnnotation();
            if (r == null) {
                r = Range.valueOf(v.getName());
            }
            if (r != null && r.getDimension1() != null) {
                return new ExprInteger(r.getDimension1().getColumn());
            }

            return ExprError.NAME;
        }
View Full Code Here

        if (!(r instanceof ExprVariable)) {
            throw new ExprException("First argument to OFFSET not a reference");
        }

        ExprVariable ref = (ExprVariable) r;
        Range range = (Range) ref.getAnnotation();
        if (range == null) {
            range = Range.valueOf(ref.getName());
        }
        if (range == null) {
            throw new ExprException("First argument to OFFSET not a reference");
        }
        GridReference gf = range.getDimension1();
        int x = gf.getColumn();
        int y = gf.getRow();
        int rows = asInteger(args[1], true);
        int cols = asInteger(args[2], true);
        int height = 1;
        int width = 1;
        if (args.length > 3) {
            Expr h = args[3];
            if (!(h instanceof ExprMissing)) {
                height = asInteger(h, true);
            }
        }
        if (height < 1) {
            return ExprError.VALUE;
        }
        if (args.length > 4) {
            Expr w = args[4];
            if (!(w instanceof ExprMissing)) {
                width = asInteger(w, true);
            }
        }
        if (width < 1) {
            return ExprError.VALUE;
        }

        GridReference dim1 = new GridReference(x + cols, y + rows);
        if (dim1.getColumn() < 1 || dim1.getRow() < 1) {
            return ExprError.REF;
        }
        GridReference dim2 = null;
        if (height > 1 || width > 1) {
            dim2 = new GridReference(x + cols + width - 1, y + rows + height -
                    1);
        }
        Range result = new Range(range.getNamespace(), dim1, dim2);
        ExprVariable var = new ExprVariable(ref.getCallback(), result
                .toString());
        var.setAnnotation(result);

        return var;
    }
View Full Code Here

    public static ExprArray toArray(Object... args) {
        return Exprs.toArray(args);
    }

    public static ExprVariable var(String var) throws ExprException {
        Range r = Range.valueOf(var);
        if (r != null)
            var = r.toString();
        ExprVariable v = new ExprVariable(new BasicEvaluationCallback(), var);
        v.setAnnotation(r);
        return v;
    }
View Full Code Here

TOP

Related Classes of org.boris.expr.engine.Range

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.