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

📄 queryimpl.java

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

import java.lang.reflect.*;
import java.util.*;
import java.util.Arrays.*;
import org.garret.perst.*;

class FilterIterator implements Iterator { 
    Iterator  iterator;
    Node      condition;
    QueryImpl query;
    int[]     indexVar;
    long[]    intAggragateFuncValue;
    double[]  realAggragateFuncValue;
    Object[]  containsArray;
    Object    currObj;
    Object    containsElem;
    
    final static int maxIndexVars = 32;
    
    public boolean hasNext() { 
        if (currObj != null) { 
            return true;
        }
        while (iterator.hasNext()) { 
            currObj = iterator.next();
            try { 
                if (condition.evaluateBool(this)) {
                    return true;
                }
            } catch (JSQLRuntimeException x) { 
                query.reportRuntimeError(x);
            }
            currObj = null;
        }
        return false;
    }
    
    public Object next() { 
        if (!hasNext()) { 
            throw new NoSuchElementException();
        }
        Object obj = currObj;
        currObj = null;
        return obj;
    }

    public void remove() {
        throw new UnsupportedOperationException();
    }
        
    
    FilterIterator(QueryImpl query, Iterator iterator, Node condition) { 
        this.query = query;
        this.iterator = iterator;
        this.condition = condition;
        indexVar = new int[maxIndexVars];
    }
}



class Node { 
    int type;
    int tag;

    final static int tpBool       = 0;
    final static int tpInt        = 1;
    final static int tpReal       = 2;
    final static int tpFreeVar    = 3;
    final static int tpList       = 4;
    final static int tpObj        = 5;
    final static int tpStr        = 6;
    final static int tpArrayBool  = 7;
    final static int tpArrayChar  = 8;
    final static int tpArrayInt1  = 9;
    final static int tpArrayInt2  = 10;
    final static int tpArrayInt4  = 11;
    final static int tpArrayInt8  = 12;
    final static int tpArrayReal4 = 13;
    final static int tpArrayReal8 = 14;
    final static int tpArrayStr   = 15;
    final static int tpArrayObj   = 16;
    final static int tpCollection = 17;
    final static int tpTable      = 18;
    final static int tpUnknown    = 19;
    final static int tpAny        = 20;

    final static String typeNames[] = {
        "boolean", 
        "integer", 
        "real", 
        "index variable", 
        "list", 
        "object",
        "string",
        "array of boolean",
        "array of char",
        "array of byte",
        "array of short",
        "array of int",
        "array of long",
        "array of float",
        "array of double",
        "array of string",
        "array of object",
        "unknown",
        "any"
    };

    final static int opNop     = 0;
    final static int opIntAdd  = 1;
    final static int opIntSub  = 2;
    final static int opIntMul  = 3;
    final static int opIntDiv  = 4;
    final static int opIntAnd  = 5;
    final static int opIntOr   = 6;
    final static int opIntNeg  = 7;
    final static int opIntNot  = 8;
    final static int opIntAbs  = 9;
    final static int opIntPow  = 10;
    final static int opIntEq   = 11;
    final static int opIntNe   = 12;
    final static int opIntGt   = 13;
    final static int opIntGe   = 14;
    final static int opIntLt   = 15;
    final static int opIntLe   = 16;
    final static int opIntBetween = 17;

    final static int opRealEq   = 18;
    final static int opRealNe   = 19;
    final static int opRealGt   = 20;
    final static int opRealGe   = 21;
    final static int opRealLt   = 22;
    final static int opRealLe   = 23;
    final static int opRealBetween = 24;

    final static int opStrEq   = 25;
    final static int opStrNe   = 26;
    final static int opStrGt   = 27;
    final static int opStrGe   = 28;
    final static int opStrLt   = 29;
    final static int opStrLe   = 30;
    final static int opStrBetween = 31;
    final static int opStrLike    = 32;
    final static int opStrLikeEsc = 33;

    final static int opBoolEq   = 34;
    final static int opBoolNe   = 35;
    
    final static int opObjEq   = 36;
    final static int opObjNe   = 37;
    
    final static int opRealAdd = 38;
    final static int opRealSub = 39;
    final static int opRealMul = 40;
    final static int opRealDiv = 41;
    final static int opRealNeg = 42;
    final static int opRealAbs  = 43;
    final static int opRealPow  = 44;

    final static int opIntToReal = 45;
    final static int opRealToInt = 46;
    final static int opIntToStr = 47;
    final static int opRealToStr = 48;

    final static int opIsNull = 49;

    final static int opStrGetAt  = 50;
    final static int opGetAtBool = 51;
    final static int opGetAtChar = 52;
    final static int opGetAtInt1 = 53;
    final static int opGetAtInt2 = 54;
    final static int opGetAtInt4 = 55;
    final static int opGetAtInt8 = 56;
    final static int opGetAtReal4 = 57;
    final static int opGetAtReal8 = 58;
    final static int opGetAtStr = 59;
    final static int opGetAtObj = 60;

    final static int opLength = 61;
    final static int opExists = 62;
    final static int opIndexVar = 63;

    final static int opFalse   = 64;
    final static int opTrue    = 65;
    final static int opNull    = 66;
    final static int opCurrent = 67;

    final static int opIntConst = 68;
    final static int opRealConst = 69;
    final static int opStrConst = 70;

    final static int opInvoke = 71;

    final static int opScanArrayBool = 72;
    final static int opScanArrayChar = 73;
    final static int opScanArrayInt1 = 74;
    final static int opScanArrayInt2 = 75;
    final static int opScanArrayInt4 = 76;
    final static int opScanArrayInt8 = 77;
    final static int opScanArrayReal4 = 78;
    final static int opScanArrayReal8 = 79;
    final static int opScanArrayStr = 80;
    final static int opScanArrayObj = 81;
    final static int opInString = 82;

    final static int opRealSin = 83;
    final static int opRealCos = 84;
    final static int opRealTan = 85;
    final static int opRealAsin = 86;
    final static int opRealAcos = 87;
    final static int opRealAtan = 88;
    final static int opRealSqrt = 89;
    final static int opRealExp = 90;
    final static int opRealLog = 91;
    final static int opRealCeil = 92;
    final static int opRealFloor = 93;

    final static int opBoolAnd = 94;
    final static int opBoolOr  = 95;
    final static int opBoolNot = 96;

    final static int opStrLower = 97;
    final static int opStrUpper = 98;
    final static int opStrConcat = 99;
    final static int opStrLength = 100;

    final static int opLoad = 100;

    final static int opLoadAny = 101;
    final static int opInvokeAny = 102;

    final static int opContains = 111;
    final static int opElement   = 112;

    final static int opAvg    = 114;
    final static int opCount  = 115;
    final static int opMax    = 116;
    final static int opMin    = 117;
    final static int opSum    = 118;

    final static int opParameter = 119;
    
    final static int opAnyAdd  = 121;
    final static int opAnySub  = 122;
    final static int opAnyMul  = 123;
    final static int opAnyDiv  = 124;
    final static int opAnyAnd  = 125;
    final static int opAnyOr   = 126;
    final static int opAnyNeg  = 127;
    final static int opAnyNot  = 128;
    final static int opAnyAbs  = 129;
    final static int opAnyPow  = 130;
    final static int opAnyEq   = 131;
    final static int opAnyNe   = 132;
    final static int opAnyGt   = 133;
    final static int opAnyGe   = 134;
    final static int opAnyLt   = 135;
    final static int opAnyLe   = 136;
    final static int opAnyBetween = 137;
    final static int opAnyLength = 138;
    final static int opInAny   = 139;
    final static int opAnyToStr = 140;
    final static int opConvertAny = 141;
    
    final static int opResolve = 142;
    final static int opScanCollection = 143;
    final static int opScanTable = 144;

    public boolean equals(Object o) { 
        return o instanceof Node && ((Node)o).tag == tag && ((Node)o).type == type;
    }
    
    static final boolean equalObjects(Object a, Object b) { 
        return a == b || (a != null && a.equals(b));
    }


    static final int getFieldType(Class type) { 
        if (type.equals(byte.class) || type.equals(short.class) || type.equals(int.class) || type.equals(long.class)) { 
            return tpInt;
        } else if (type.equals(double.class) || type.equals(float.class)) { 
            return tpReal;
        } else if (type.equals(String.class)) { 
            return tpStr;
        } else if (type.equals(boolean[].class)) { 
            return tpArrayBool;
        } else if (type.equals(byte[].class)) { 
            return tpArrayInt1;
        } else if (type.equals(short[].class)) { 
            return tpArrayInt2;
        } else if (type.equals(char[].class)) { 
            return tpArrayChar;
        } else if (type.equals(int[].class)) { 
            return tpArrayInt4;
        } else if (type.equals(long[].class)) { 
            return tpArrayInt8;
        } else if (type.equals(float[].class)) { 
            return tpArrayReal4;
        } else if (type.equals(double[].class)) { 
            return tpArrayReal8;
        } else if (type.equals(String[].class)) { 
            return tpArrayStr;
        } else if (Collection.class.isAssignableFrom(type)){ 
            return tpCollection;
        } else if (ITable.class.isAssignableFrom(type)){ 
            return tpTable;
        } else if (type.isArray()) {
            return tpArrayObj;
        } else if (type.equals(Object.class)) {
            return tpAny;
        } else { 
            return tpObj;
        }
    }
    
    String getFieldName() { 
        return null;
    }

    boolean evaluateBool(FilterIterator t) { 
        throw new AbstractMethodError();
    }
    long    evaluateInt(FilterIterator t) {
        throw new AbstractMethodError();
    }
    double  evaluateReal(FilterIterator t) {
        throw new AbstractMethodError();
    }
    String  evaluateStr(FilterIterator t) {
        return (String)evaluateObj(t);
    }
    Object  evaluateObj(FilterIterator t) {
        switch (type) { 
          case tpStr:            
            return evaluateStr(t);
          case tpInt:
            return new Long(evaluateInt(t));
          case tpReal:
            return new Double(evaluateReal(t));
          case tpBool:
            return evaluateBool(t) ? Boolean.TRUE : Boolean.FALSE;
          default:
            throw new AbstractMethodError();
        }
    }
    Class   getType() { 
        return null;
    }
    
    public String toString() { 
        return "Node tag=" + tag + ", type=" + type;
    }

    Node(int type, int tag) {
        this.type = type;
        this.tag = tag;
    }
}

class EmptyNode extends Node { 
    boolean evaluateBool(FilterIterator t) { 
        return true;
    }

    EmptyNode() { 
        super(tpBool, opTrue);
    }
}

abstract class LiteralNode extends Node {  
    abstract Object getValue();

    Object evaluateObj(FilterIterator t) {
        return getValue();
    }

    LiteralNode(int type, int tag) { 
        super(type, tag);
    }
}
   
class IntLiteralNode extends LiteralNode { 
    long value;
    
    public boolean equals(Object o) { 
        return o instanceof IntLiteralNode && ((IntLiteralNode)o).value == value;
    }

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

    long evaluateInt(FilterIterator t) {
        return value;
    }
    
    IntLiteralNode(long value) { 
        super(tpInt, opIntConst);
        this.value = value;
    }
}


class RealLiteralNode extends LiteralNode { 
    double value;
    

⌨️ 快捷键说明

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