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

📄 stafcommandparser.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                if (valueRequirement == VALUENOTALLOWED)                {                    result.addOptionInstance(optionInstance);                    optionInstance = result.new OptionInstance();                }            }            else if (valueRequirement == VALUENOTALLOWED)            {                result.addArg(currentWord.toString());            }            else            {                optionInstance.value = currentWord.toString();                result.addOptionInstance(optionInstance);                optionInstance = result.new OptionInstance();                valueRequirement = VALUENOTALLOWED;            }        }  // end for each word        // If the last word was an option, we need to check for its value        // requirements here        if (valueRequirement == VALUEREQUIRED)        {            result.errorBuffer = "Option, " + optionInstance.name +                                 ", requires a value";            result.rc = 1;            return result;        }        else if (valueRequirement == VALUEALLOWED)        {            result.addOptionInstance(optionInstance);        }                // Now check the restriction on number of arguments        if (result.numArgs() > fMaxArgs)        {            result.errorBuffer = "You may have no more than " + fMaxArgs +                                 " argument(s).  You specified " +                                 result.numArgs() + " argument(s)." +                                 "  The first excess argument is, " +                                 result.arg(fMaxArgs + 1) + ".";            result.rc = 1;            return result;        }                // Now check all the group requirements        for(int i = 0; i < fOptionGroups.size(); ++i)        {            OptionGroup group = (OptionGroup)fOptionGroups.elementAt(i);            int groupCount = 0;            int groupWordCount = group.names.size();            for (int j = 0; j < groupWordCount; ++j)            {                if (result.optionTimes((String)group.names.elementAt(j)) != 0)                    ++groupCount;            }            if ((groupCount < group.min) || (groupCount > group.max))            {                result.errorBuffer = "You must have at least " + group.min +                                     ", but no more than " + group.max +                                     " of the option(s), " + group.namesString;                result.rc = 1;                return result;            }        }        // Now check the need requirements        for(int i = 0; i < fOptionNeeds.size(); ++i)        {            OptionNeed need = (OptionNeed)fOptionNeeds.elementAt(i);            boolean foundNeeder = false;            boolean foundNeedee = false;            for(int j = 0; (j < need.needers.size()) && !foundNeeder; ++j)            {                if (result.optionTimes((String)need.needers.elementAt(j)) != 0)                    foundNeeder = true;            }            for(int k = 0; (k < need.needees.size()) && !foundNeedee; ++k)            {                if (result.optionTimes((String)need.needees.elementAt(k)) != 0)                    foundNeedee = true;            }            if (foundNeeder && !foundNeedee)            {                result.errorBuffer = "When specifying one of the options " +                                     need.needersString + ", you must also " +                                     "specify one of the options " +                                     need.needeesString;                result.rc = 1;                return result;            }        }        return result;    }  // end parse()    private boolean isOption(StringBuffer name)    {        return isOption(name.toString());    }    private boolean isOption(String name)    {        for(int i = 0; i < fOptions.size(); ++i)        {            Option option = (Option)fOptions.elementAt(i);            if ((fCaseSensitive && option.name.equals(name)) ||                (!fCaseSensitive && option.name.equalsIgnoreCase(name)))            {                return true;            }        }        return false;    }    private Option getOption(StringBuffer name)    {        return getOption(name.toString());    }    private Option getOption(String name)    {        for(int i = 0; i < fOptions.size(); ++i)        {            Option option = (Option)fOptions.elementAt(i);            if ((fCaseSensitive && option.name.equals(name)) ||                (!fCaseSensitive && option.name.equalsIgnoreCase(name)))            {                return option;            }        }        return new Option("<Unknown Option>", 1, VALUENOTALLOWED);    }    private int fMaxArgs;    private boolean fCaseSensitive;    private Vector fOptions;    private Vector fOptionGroups;    private Vector fOptionNeeds;    // This class is used to hold data about each option    private class Option    {        Option(String aName, int theMaxAllowed, int theValueRequirement)        {            name = aName;            maxAllowed = theMaxAllowed;            valueRequirement = theValueRequirement;        }        String name;        int maxAllowed;        int valueRequirement;    }    // This class is used to hold information about the way options may    // be grouped    private class OptionGroup    {        OptionGroup(String theNames, int theMin, int theMax)        {            min = theMin;            max = theMax;            namesString = theNames;            names = new Vector();            StringTokenizer tokenizer = new StringTokenizer(theNames);            while (tokenizer.hasMoreTokens())            {                names.addElement(tokenizer.nextToken());            }        }        String namesString;        Vector names;        int min;        int max;    }    // This class is used to hold information about which options are    // required in the procesence of other options    private class OptionNeed    {        OptionNeed(String theNeeders, String theNeedees)        {            needersString = theNeeders;            needers = new Vector();            StringTokenizer tokenizer = new StringTokenizer(theNeeders);            while (tokenizer.hasMoreTokens())            {                needers.addElement(tokenizer.nextToken());            }            needeesString = theNeedees;            needees = new Vector();            tokenizer = new StringTokenizer(theNeedees);            while (tokenizer.hasMoreTokens())            {                needees.addElement(tokenizer.nextToken());            }        }        String needersString;        String needeesString;        Vector needers;        Vector needees;    }    private static final int ISOPTION = 0;    private static final int ISVALUE = 1;    private class OptionValue    {        OptionValue()        {            data = new StringBuffer();            optionOrValue = STAFCommandParser.ISVALUE;        }        StringBuffer data;        int optionOrValue;    }}

⌨️ 快捷键说明

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