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

📄 parser.java

📁 iiitAccessServer是一个用Java编写的基于规则的企业鉴别系统。它作为一个服务器工作
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (mArgumentOnly.matches())        {            result = new HashSet(evaluateArgument(argStack, name));        }        else        {            result = new HashSet();            boolean loop = true;                    String expr = expression;                    Matcher mOpenBrace    = pOpenBrace.matcher(expression);            Matcher mArgument     = pArgument.matcher(expression);            Matcher mOperator     = pOperator.matcher(expression);            Matcher mSpace        = pSpace.matcher(expression);            while (loop)            {                if (mOpenBrace.find(startPos) && mOpenBrace.start() == startPos)                 {                    startPos = handleBraces(argStack, name, formula, mOpenBrace, position, startPos);                }                else if (mArgument.find(startPos) && mArgument.start() == startPos)                {                    formula.add(mArgument.group(1));                    startPos = mArgument.end();                }                else if (! formula.isEmpty() || (mSpace.find(startPos) && mSpace.start() != startPos))                {                    throw new ParserException("There is something strange near position "                                                + (position + startPos) + " in <" + expression + ">");                }                            if (mOperator.find(startPos) && mOperator.start() == startPos)                {                    formula.add(mOperator.group(1));                    startPos = mOperator.end();                }                else if (mSpace.find(startPos) && mSpace.start() == startPos)                {                    loop = false;                }                else                {                    throw new ParserException("There is something strange near position "                                                 + (position + startPos) + " in <" + expression + ">");                }            }                    int i = 0, iMax = formula.size();                    String op = "+";            while (i < iMax)            {                argStack.pushArgument(formula.get(i++));                Set argSet = evaluateArgument(argStack, name);                argStack.pop();                            while (i < iMax && ((String) formula.get(i)).equals("&"))                {                    i++;                                    argStack.pushArgument(formula.get(i++));                    Set argSet2 = evaluateArgument(argStack, name);                    argStack.pop();                                    Set s1, s2;                                    if (argSet.size() < argSet2.size())                    {                        s1 = argSet;                        s2 = argSet2;                    }                    else                    {                        s2 = argSet;                        s1 = argSet2;                    }                                    Iterator iterator = s1.iterator();                                    argSet = new HashSet();                                    while (iterator.hasNext())                    {                        Object o = iterator.next();                                            if (s2.contains(o))                            argSet.add(o);                    }                }                            if (op.equals("+"))                {                    Iterator iterator = argSet.iterator();                                        while (iterator.hasNext())                        result.add(iterator.next());                                }                else if (op.equals("-"))                {                    Iterator iterator = argSet.iterator();                                    while (iterator.hasNext())                        result.remove(iterator.next());                }                            if (i < iMax)                {                    op = (String) formula.get(i++);                }            }        }        return result;    }          /** Evaluates the expression on top of argStack. The evaluation is optimized in such way that     * it only retrieves information regarding the given user name.     * @param argStack This stack includes all expressions and subexpressions of the current tree     * inside the orginal expression.     * @param name The name of the user for whom the expression should be evaluated.     * @throws ParserException if there is something wrong with the expression. The most common cases are syntax     * errors or circular references within the expression.     * @return An optimized set of users. It is guaranteed that it is correct for the given user     * but it is not guaranteed that it includes all users described by the expression.     */        public Set evaluate(ParserStackIf argStack, String name) throws ParserException    {        return evaluate(argStack, name, 0);    }    /** Evaluates the expression on top of argStack.     * @param argStack This stack includes all expressions and subexpressions of the current tree     * inside the orginal expression.     * @throws ParserException if there is something wrong with the expression. The most common cases are syntax     * errors or circular references within the expression.     * @return The set of users described by the expression.     */        public Set evaluate(ParserStackIf argStack) throws ParserException    {        return evaluate(argStack, null, 0);    }    /** Evaluates an expression. The evaluation is optimized in such way that     * it only retrieves information regarding the given user name.     * @param expression The expression to evaluate     * @param name The name of the user for whom the expression should be evaluated.     * @throws ParserException if there is something wrong with the expression. The most common cases are syntax     * errors or circular references within the expression.     * @return An optimized set of users. It is guaranteed that it is correct for the given user     * but it is not guaranteed that it includes all users described by the expression.     */        public Set evaluateExpression(String expression, String name) throws ParserException    {        ParserStack argStack = new ParserStack();        argStack.pushArgument(expression);                return evaluate(argStack, name);    }    /** Evaluates an expression     * @param expression The expression to evaluate     * @throws ParserException if there is something wrong with the expression. The most common cases are syntax     * errors or circular references within the expression.     * @return The set of users described by the expression.     */        public Set evaluateExpression(String expression) throws ParserException    {        return evaluateExpression(expression, null);    }}/** * $Log: Parser.java,v $ * Revision 1.7  2003/04/13 21:09:56  joerg * Package structure modified * * Revision 1.6  2003/04/13 20:28:01  joerg * Package structure modified * * Revision 1.5  2003/04/13 20:16:42  joerg * Package structure modified * * Revision 1.4  2003/04/07 20:08:49  joerg * Improved JavaDoc. * * Revision 1.3  2003/01/16 21:48:00  joerg * Kleine Bugfixes * * Revision 1.2  2003/01/01 21:04:18  joerg * Copyright-Statement aktualisiert * * Revision 1.1  2002/12/19 15:24:23  joerg * Reparatur des CVS-Repositories * * Revision 1.7  2002/12/09 19:29:17  joerg * Versionsdaten in allen JavaDoc-Klassenbeschreibungen ergaenzt * * Revision 1.6  2002/12/09 16:32:26  joerg * JavaDoc Kommentare ergaenzt * * Revision 1.5  2002/11/27 22:29:53  joerg * Auskommentierten Code entfernt * * Revision 1.4  2002/11/27 16:39:40  joerg * Parameteruebergabe geaendert, um circulaere Recursion * zu erkennen * * Revision 1.3  2002/11/26 21:46:56  joerg * Fehlerbehandlung verbessert * * Revision 1.2  2002/11/26 14:40:49  joerg * Kleine Optimierungen * * Revision 1.1  2002/11/26 10:55:36  joerg * Package exprparser durch parser erstzt. * */

⌨️ 快捷键说明

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