⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryimpl.java

📁 这个是perst-269.zip下面的SOURCECODE,和大家分享了。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

    Object getValue() { 
        return new Double(value);
    }

    double evaluateReal(FilterIterator t) {
        return value;
    }
    
    RealLiteralNode(double value) { 
        super(tpReal, opRealConst);
        this.value = value;
    }
}

class StrLiteralNode extends LiteralNode { 
    String value;
    
    public boolean equals(Object o) { 
        return o instanceof StrLiteralNode && ((StrLiteralNode)o).value.equals(value);
    }

    Object getValue() { 
        return value;
    }

    String evaluateStr(FilterIterator t) {
        return value;
    }
    
    StrLiteralNode(String value) { 
        super(tpStr, opStrConst);
        this.value = value;
    }
}


class CurrentNode extends Node { 
    Class getType() {
        return cls;
    }

    Object evaluateObj(FilterIterator t) {
        return t.currObj;
    }

    CurrentNode(Class cls) { 
        super(tpObj, opCurrent);
        this.cls = cls;
    }
    Class cls;
}

class ConstantNode extends LiteralNode { 
    Object getValue() { 
        switch (tag) { 
          case opNull:
            return null;
          case opFalse:
            return Boolean.FALSE;
          case opTrue:
            return Boolean.TRUE;
          default:
            throw new Error("Invalid tag " + tag);            
        }
    }
    
    boolean evaluateBool(FilterIterator t) { 
        return tag != opFalse;
    }

    ConstantNode(int type, int tag) { 
        super(type, tag);
    }
}

class IndexOutOfRangeError extends Error {
    int loopId;

    IndexOutOfRangeError(int loop) {
        loopId = loop;
    }
}

class ExistsNode extends Node {
    Node expr;
    int  loopId;
    
    public boolean equals(Object o) { 
        return o instanceof ExistsNode && ((ExistsNode)o).expr.equals(expr) && ((ExistsNode)o).loopId == loopId;
    }

    boolean evaluateBool(FilterIterator t) { 
        t.indexVar[loopId] = 0;
        try { 
            while (!expr.evaluateBool(t)) { 
                t.indexVar[loopId] += 1;
            }
            return true;
        } catch (IndexOutOfRangeError x) { 
            if (x.loopId != loopId) { 
                throw x;
            }
            return false;
        }
    }
    
    ExistsNode(Node expr, int loopId) { 
        super(tpBool, opExists);
        this.expr = expr;
        this.loopId = loopId;
    }
}


class IndexNode extends Node {
    int loopId;
    
    public boolean equals(Object o) { 
        return o instanceof IndexNode && ((IndexNode)o).loopId == loopId;
    }

    long evaluateInt(FilterIterator t) { 
        return t.indexVar[loopId];
    }
    
    IndexNode(int loop) { 
        super(tpInt, opIndexVar);
        loopId = loop;
    }
}

class GetAtNode extends Node { 
    Node left;
    Node right;
    
    public boolean equals(Object o) { 
        return o instanceof GetAtNode && ((GetAtNode)o).left.equals(left) && ((GetAtNode)o).right.equals(right);
    }

    long evaluateInt(FilterIterator t) { 
        Object arr = left.evaluateObj(t);
        long idx = right.evaluateInt(t);

        if (right.tag == opIndexVar) { 
            try { 
                if (idx >= Array.getLength(arr)) {
                    throw new IndexOutOfRangeError(((IndexNode)right).loopId);
                }
            } catch (IllegalArgumentException x) {
                throw new Error("Argument is not array");
            }
        }
        int index = (int)idx;
        switch (tag) { 
          case opGetAtInt1:
            return ((byte[])arr)[index];
          case opGetAtInt2:
            return ((short[])arr)[index];
          case opGetAtInt4:
            return ((int[])arr)[index];
          case opGetAtInt8:
            return ((long[])arr)[index];
          case opGetAtChar:
            return ((char[])arr)[index];
          case opStrGetAt:
            return ((String)arr).charAt(index);
          default:
            throw new Error("Invalid tag " + tag);
        }
    }       

    double evaluateReal(FilterIterator t) { 
        Object arr = left.evaluateObj(t);
        long index = right.evaluateInt(t);

        if (right.tag == opIndexVar) { 
            try { 
                if (index >= Array.getLength(arr)) {
                    throw new IndexOutOfRangeError(((IndexNode)right).loopId);
                }
            } catch (IllegalArgumentException x) {
                throw new Error("Argument is not array");
            }
        }
        switch (tag) { 
          case opGetAtReal4:
            return ((float[])arr)[(int)index];
          case opGetAtReal8:
            return ((double[])arr)[(int)index];
          default:
            throw new Error("Invalid tag " + tag);
        }
    }       

    boolean evaluateBool(FilterIterator t) { 
        boolean[] arr = (boolean[])left.evaluateObj(t);
        long index = right.evaluateInt(t);

        if (right.tag == opIndexVar) { 
            try { 
                if (index >= arr.length) {
                    throw new IndexOutOfRangeError(((IndexNode)right).loopId);
                }
            } catch (IllegalArgumentException x) {              
                throw new Error("Argument is not array");
            }
        }
        return arr[(int)index];
    }

    String evaluateStr(FilterIterator t) { 
        String[] arr = (String[])left.evaluateObj(t);
        long index = right.evaluateInt(t);

        if (right.tag == opIndexVar) { 
            try { 
                if (index >= arr.length) {
                    throw new IndexOutOfRangeError(((IndexNode)right).loopId);
                }
            } catch (IllegalArgumentException x) {
                throw new Error("Argument is not array");
            }
        }
        return arr[(int)index];
    }

    Object evaluateObj(FilterIterator t) { 
        Object arr = left.evaluateObj(t);
        long index = right.evaluateInt(t);

        try { 
            if (right.tag == Node.opIndexVar) { 
                if (index >= Array.getLength(arr)) {
                    throw new IndexOutOfRangeError(((IndexNode)right).loopId);
                }
            }
            return Array.get(arr, (int)index);            
        } catch (IllegalArgumentException x) {
            throw new Error("Argument is not array");
        }
    }

    GetAtNode(int type, int tag, Node base, Node index) { 
        super(type, tag);
        left = base;
        right = index;
    }
}

class InvokeNode extends Node {
    Node target;
    Node[] arguments;
    Method mth;

    public boolean equals(Object o) { 
        return o instanceof InvokeNode 
            && equalObjects(((InvokeNode)o).target, target)
            && Arrays.equals(((InvokeNode)o).arguments, arguments)
            && equalObjects(((InvokeNode)o).mth, mth);
    }

    Class getType() { 
        return mth.getReturnType();
    }

    String getFieldName() { 
        if (target != null && target.tag != opCurrent) { 
            String baseName = target.getFieldName();
            return (baseName != null) ? baseName + "." + mth.getName() : null;
        } else { 
            return mth.getName();
        }
    }

    Object getTarget(FilterIterator t) { 
        if (target == null) { 
            return t.currObj;
        } 
        Object obj = target.evaluateObj(t);
        if (obj == null) { 
            throw new JSQLNullPointerException(target.getType(), mth.toString());
        }
        return obj;
    }

    Object[] evaluateArguments(FilterIterator t) {
        Object[] parameters = null;
        int n = arguments.length;
        if (n > 0) { 
            parameters = new Object[n];
            for (int i = 0; i < n; i++) { 
                Node arg = arguments[i];
                Object value;
                switch (arg.type) { 
                  case Node.tpInt:
                    value = new Long(arg.evaluateInt(t));
                    break;
                  case Node.tpReal:
                    value = new Double(arg.evaluateReal(t));
                    break;
                  case Node.tpStr:
                    value = arg.evaluateStr(t);
                    break;
                  case Node.tpBool:
                    value = new Boolean(arg.evaluateBool(t));
                    break;
                  default:
                    value = arg.evaluateObj(t);
                }
                parameters[i] = value;
            }
        }
        return parameters;
    }

    long evaluateInt(FilterIterator t) {
        Object obj = getTarget(t);
        Object[] parameters = evaluateArguments(t);
        try { 
            return ((Number)mth.invoke(obj, parameters)).longValue();
        } catch (Exception x) { 
            x.printStackTrace();
            throw new Error("Method invocation error");
        }
    }

    double evaluateReal(FilterIterator t) {
        Object obj = getTarget(t);
        Object[] parameters = evaluateArguments(t);
        try { 
            return ((Number)mth.invoke(obj, parameters)).doubleValue();
        } catch (Exception x) { 
            x.printStackTrace();
            throw new Error("Method invocation error");
        }
    }

    boolean evaluateBool(FilterIterator t) {
        Object obj = getTarget(t);
        Object[] parameters = evaluateArguments(t);
        try { 
            return ((Boolean)mth.invoke(obj, parameters)).booleanValue();
        } catch (Exception x) { 
            x.printStackTrace();
            throw new Error("Method invocation error");
        }
    }

    String evaluateStr(FilterIterator t) {
        Object obj = getTarget(t);
        Object[] parameters = evaluateArguments(t);
        try { 
            return (String)mth.invoke(obj, parameters);
        } catch (Exception x) { 
            x.printStackTrace();
            throw new Error("Method invocation error");
        }
    }
    
    Object evaluateObj(FilterIterator t) {
        Object obj = getTarget(t);
        Object[] parameters = evaluateArguments(t);
        try { 
            return mth.invoke(obj, parameters);
        } catch (Exception x) { 
            x.printStackTrace();
            throw new Error("Method invocation error");
        }
    }    

    InvokeNode(Node target, Method mth, Node arguments[]) { 
        super(getFieldType(mth.getReturnType()), opInvoke);
        this.target = target;
        this.arguments = arguments;
        this.mth = mth;
    }
}


class InvokeAnyNode extends Node { 
    Node     target;
    Node[]   arguments;
    Class[]  profile;
    String   methodName;
    String   containsFieldName;

    public boolean equals(Object o) { 
        if (!(o instanceof InvokeAnyNode)) { 
            return false;
        }
        InvokeAnyNode node = (InvokeAnyNode)o;        
        return equalObjects(node.target, target)
            && Arrays.equals(node.arguments, arguments)
            && Arrays.equals(node.profile, profile)
            && equalObjects(node.methodName, methodName)
            && equalObjects(node.containsFieldName, containsFieldName);
    }

    Class getType() { 
        return Object.class;
    }

    String getFieldName() { 
        if (target != null) {         
            if (target.tag != opCurrent) { 
                String baseName = target.getFieldName();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -