dap4/d4core/src/main/java/dap4/core/ce/CECompiler.java
public void
    compilefilter(DapVariable var, DapSequence seq, CEAST expr)
            throws DapException
    {
        if(expr == null)
            return;
        if(expr.sort == CEAST.Sort.SEGMENT) {
            // This must be a simple segment and it must appear in seq
            if(expr.subnodes != null)
                throw new DapException("compilefilter: Non-simple segment:" + expr.name);
            // Look for the name in the top-level field of seq
            DapVariable field = seq.findByName(expr.name);
            if(field == null)
                throw new DapException("compilefilter: Unknown filter variable:" + expr.name);
            expr.field = field;
        } else if(expr.sort == CEAST.Sort.EXPR) {
            if(expr.lhs != null)
                compilefilter(var, seq, expr.lhs);
            if(expr.rhs != null)
                compilefilter(var, seq, expr.rhs);
            // If both lhs and rhs are non-null,
            // canonicalize any comparison so that it is var op const
            if(expr.lhs != null && expr.rhs != null) {
                boolean leftvar = (expr.lhs.sort == CEAST.Sort.SEGMENT);
                boolean rightvar = (expr.rhs.sort == CEAST.Sort.SEGMENT);

                if(rightvar && !leftvar) { // swap operands
                    CEAST tmp = expr.lhs;
                    expr.lhs = expr.rhs;
                    expr.rhs = tmp;
                    // fix operator
                    switch (expr.op) {
                    case LT:  //x<y -> y>x
                        expr.op = CEAST.Operator.GT;
                        break;
                    case LE: //x<=y -> y>=x
                        expr.op = CEAST.Operator.GE;
                        break;
                    case GT:  //x>y -> y<x
                        expr.op = CEAST.Operator.LT;
                        break;
                    case GE:   //x>=y -> y<=x
                        expr.op = CEAST.Operator.LE;
                        break;
                    default:
                        break; // leave as is
                    }
                }
            }
        } else if(expr.sort == CEAST.Sort.CONSTANT) {
            return;
        } else
            throw new DapException("compilefilter: Unexpected node type:" + expr.sort);
    }
public void
    compilefilter(DapVariable var, DapSequence seq, CEAST expr)
            throws DapException
    {
        if(expr == null)
            return;
        if(expr.sort == CEAST.Sort.SEGMENT) {
            // This must be a simple segment and it must appear in seq
            if(expr.subnodes != null)
                throw new DapException("compilefilter: Non-simple segment:" + expr.name);
            // Look for the name in the top-level field of seq
            DapVariable field = seq.findByName(expr.name);
            if(field == null)
                throw new DapException("compilefilter: Unknown filter variable:" + expr.name);
            expr.field = field;
        } else if(expr.sort == CEAST.Sort.EXPR) {
            if(expr.lhs != null)
                compilefilter(var, seq, expr.lhs);
            if(expr.rhs != null)
                compilefilter(var, seq, expr.rhs);
            // If both lhs and rhs are non-null,
            // canonicalize any comparison so that it is var op const
            if(expr.lhs != null && expr.rhs != null) {
                boolean leftvar = (expr.lhs.sort == CEAST.Sort.SEGMENT);
                boolean rightvar = (expr.rhs.sort == CEAST.Sort.SEGMENT);

                if(rightvar && !leftvar) { // swap operands
                    CEAST tmp = expr.lhs;
                    expr.lhs = expr.rhs;
                    expr.rhs = tmp;
                    // fix operator
                    switch (expr.op) {
                    case LT:  //x<y -> y>x
                        expr.op = CEAST.Operator.GT;
                        break;
                    case LE: //x<=y -> y>=x
                        expr.op = CEAST.Operator.GE;
                        break;
                    case GT:  //x>y -> y<x
                        expr.op = CEAST.Operator.LT;
                        break;
                    case GE:   //x>=y -> y<=x
                        expr.op = CEAST.Operator.LE;
                        break;
                    default:
                        break; // leave as is
                    }
                }
            }
        } else if(expr.sort == CEAST.Sort.CONSTANT) {
            return;
        } else
            throw new DapException("compilefilter: Unexpected node type:" + expr.sort);
    }
Convert field references in a filter