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

📄 userproperty.java

📁 实现网格环境下资源调度和分配的仿真
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @throws Exception if the given number is incorrect     * @pre text != null     * @post $result >= 0     */    private int checkValue(int value, JTextField text) throws Exception    {        value = new Integer( text.getText() ).intValue();        if (value < 0) {            throw new Exception("Invalid for having negative value.");        }        return value;    }    /**     * Another overloaded method.      * Checks whether the given value is correct or not     * @param value     given number     * @param text      a JTextField object     * @param type      type of a JTextField object     * @return the correct number     * @throws Exception if the given number is incorrect     * @pre text != null     * @pre type != null     * @post $result >= 0     */    private double checkValue(double value, JTextField text, String type)                        throws Exception    {        value = new Double( text.getText() ).doubleValue();        if (value < 0.0) {            throw new Exception("Invalid for having negative value.");        }                if (type.equals("deviation") == true)        {            if (value > 100.0) {                throw new Exception("Invalid value for exceeding 100.");            }        }        else if (type.equals("factor") == true)        {            if (radioFactor_.isSelected() == true)            {                if (value > 1.0) {                    throw new Exception("Invalid value for exceeding 1.");                }             }        }        return value;    }    /**     * Resets all the values     * @pre $none      * @post $none     */    private void resetValue()    {        resetTextValue(name_, "user");        resetTextValue(baudRate_, "baud");        resetTextValue(delay_, "delay");        resetTextValue(hour_, "hour");        resetTextValue(min_, "min");        resetTextValue(sec_, "sec");        resetTextValue(bNum_, "budget");        resetTextValue(dNum_, "deadline");        resetTextValue(gridSize_, "grid_size");        resetTextValue(gridMin_, "grid_min");        resetTextValue(gridMax_, "grid_max");        resetTextValue(lengthSize_, "length_size");        resetTextValue(lengthMin_, "length_min");        resetTextValue(lengthMax_, "length_max");        resetTextValue(outputSize_, "output_size");        resetTextValue(outputMin_, "output_min");        resetTextValue(outputMax_, "output_max");        resetTextValue(fileSize_, "file_size");        resetTextValue(fileMin_, "file_min");        resetTextValue(fileMax_, "file_max");        combo_.setSelectedIndex(comboPolicy_);        if (curRadioFactor_ == true) {            radioFactor_.setSelected(true);        }        else {            radioValue_.setSelected(true);        }    }    /**     * Resets a given key object with the specified value     * @param value  object value      * @param key    object key for a hash table     * @pre value != null     * @pre key != null     * @post $none     */    private void resetTextValue(String value, String key)    {        JTextField text = (JTextField) hashText_.get(key);        text.setText(value);        hashText_.put(key, text);    }    /**     * Overloaded method. Resets a given key object with the specified value.     * @param num    object value     * @param key    object key for a hash table     * @pre num >= 0.0     * @pre key != null     * @post $none     */    private void resetTextValue(double num, String key)    {        JTextField text = (JTextField) hashText_.get(key);        text.setText("" + num);        hashText_.put(key, text);    }    /**     * Overloaded method. Resets a given key object with the specified value.     * @param num    object value     * @param key    object key for a hash table     * @pre num >= 0     * @pre key != null     * @post $none     */    private void resetTextValue(int num, String key)    {        JTextField text = (JTextField) hashText_.get(key);        text.setText("" + num);        hashText_.put(key, text);    }    /**     * Loads a XML code regarding to time allocation     * @param nodeList  a NodeList object     * @pre nodeList != null     * @post $none     */    private void loadXmlTime(final NodeList nodeList)    {        Node node;        String name, value;        int length = nodeList.getLength();        for (int i = 0; i < length; i++)        {            node = nodeList.item(i);            // only element nodes that need to be take care,            // the rests are ignored            if (node.getNodeType() != Node.ELEMENT_NODE) {                continue;            }            name = node.getNodeName();            if (name.equals("hour") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                int id = Integer.parseInt(value.trim());                hour_ = id;            }            else if (name.equals("minute") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                int id = Integer.parseInt(value.trim());                min_ = id;            }            else if (name.equals("second") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                int id = Integer.parseInt(value.trim());                sec_ = id;            }        }    }    /**     * Loads a XML code regarding to a scheduling policy     * @param value     a scheduling policy     * @pre value != null     * @post $none     */    private void loadXmlPolicy(String value)    {        int i = 0;        int length = comboValue_.length;                for (i = 0; i < length; i++)        {            if (comboValue_[i].equals(value) == true) {                break;            }        }        if (i == comboValue_.length) {            i = 0;        }        comboPolicy_ = i;    }    /**     * Loads a XML code regarding to budget and deadline properties     * @param nodeList  a NodeList object     * @pre nodeList != null     * @post $none     */    private void loadXmlBudgetDeadline(final NodeList nodeList)    {        Node node;        String name, value;        int length = nodeList.getLength();        for (int i = 0; i < length; i++)        {            node = nodeList.item(i);            // only element nodes that need to be take care,            // the rests are ignored            if (node.getNodeType() != Node.ELEMENT_NODE) {                continue;            }            name = node.getNodeName();            if (name.equals("type") == true)            {                value = node.getFirstChild().getNodeValue().trim();                if (value.equals("factor") == true) {                    curRadioFactor_ = true;                }                else {                    curRadioFactor_ = false;                }            }            else if (name.equals("budget") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                bNum_ = num;            }            else if (name.equals("deadline") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                dNum_ = num;            }        }    }    /**     * Loads a XML code regarding to Gridlets     * @param nodeList  a NodeList object     * @pre nodeList != null     * @post $none     */    private void loadXmlGridlet(final NodeList nodeList)    {        Node node;        String name;        int length = nodeList.getLength();        for (int i = 0; i < length; i++)        {            node = nodeList.item(i);            // only element nodes that need to be take care,            // the rests are ignored            if (node.getNodeType() != Node.ELEMENT_NODE) {                continue;            }            name = node.getNodeName();            loadXmlGridletProperty(node.getChildNodes(), name);        }    }    /**     * Loads a XML code regarding to      * @param nodeList  a NodeList object     * @param type      object type     * @pre nodeList != null     * @pre type != null     * @post $none     */    private void loadXmlGridletProperty(final NodeList nodeList,                        final String type)    {        Node node;        String name, value;        final int PERCENT = 100;        int length = nodeList.getLength();        for (int i = 0; i < length; i++)        {            node = nodeList.item(i);            // only element nodes that need to be take care,            // the rests are ignored            if (node.getNodeType() != Node.ELEMENT_NODE) {                continue;            }            name = node.getNodeName();            if (name.equals("size") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                int num = Integer.parseInt(value.trim());                if (type.equals("gridlet") == true) {                    gridSize_ = num;                }                else if (type.equals("length") == true) {                    lengthSize_ = num;                }                else if (type.equals("file") == true) {                    fileSize_ = num;                }                else if (type.equals("output") == true) {                    outputSize_ = num;                }            }            else if (name.equals("minDeviation") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                if (type.equals("gridlet") == true) {                    gridMin_ = num * PERCENT;                }                else if (type.equals("length") == true) {                    lengthMin_ = num * PERCENT;                }                else if (type.equals("file") == true) {                    fileMin_ = num * PERCENT;                }                else if (type.equals("output") == true) {                    outputMin_ = num * PERCENT;                }            }            else if (name.equals("maxDeviation") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                if (type.equals("gridlet") == true) {                    gridMax_ = num * PERCENT;                }                else if (type.equals("length") == true) {                    lengthMax_ = num * PERCENT;                }                else if (type.equals("file") == true) {                    fileMax_ = num * PERCENT;                }                else if (type.equals("output") == true) {                    outputMax_ = num * PERCENT;                }            }        }    }} // end class

⌨️ 快捷键说明

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