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

📄 configuration.java

📁 Boosting算法软件包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    try {		v= (String) m_parsedCommands.get(name);		retval= Double.parseDouble(v);	    } catch (NumberFormatException e) {		if (Monitor.logLevel > 3)		    Monitor.log("Error Parsing Option: " + v);	    }	} else {	    m_unSpecified += name + ",";	}	return retval;    }    /**     * returns the String value corresponding to an option name or the def value     * if parsing fails or the option is not found     *      * @param name of the configuration parameter     * @param def default value to use     * @return retval the value of the configuration parameter     */    public String getString(String name, String def) {	String retval= def;	if (m_parsedCommands.containsKey(name)) {	    retval= (String) m_parsedCommands.get(name);	} else {	    m_unSpecified += name + ",";	}	return retval;    }      /**     * Returns a String value corresponding to the option name, but uses null as the default     * @param name     * @return     */    public String getString(String name) {	return getString(name, null);    }    /**     * returns the a boolean value which is true if the option is set false     * otherwise.     *      * @param name of the configuration parameter     * @param def default value to use     * @return retval the value of the configuration parameter     */    public boolean getBool(String name, boolean def) {	String v= null;	boolean retval= def;	if (m_parsedCommands.containsKey(name)) {	    v= (String) m_parsedCommands.get(name); 	    if (v.equals("+") || v.equalsIgnoreCase("true") || v.equals("")) {		retval= true;	    } else if (v.equals("-") || v.equalsIgnoreCase("false")) {		retval= false;	    } else if (Monitor.logLevel > 3) {		Monitor.log("Inappropriate command argument " + v + " received with option "			    + name);	    }	} else {	    m_unSpecified += name + ",";	}	return retval;    }    /**     * returns the array of Strings corresponding to an option name or the def     * value if parsing fails or the option is not found     *      * @param name of the configuration parameter     * @param def default value to use     * @param retval the value of the configuration parameter     */    public String[] getStringArray(String name, String[] def) {	String v= null;    	if (m_parsedCommands.containsKey(name)) {	    v= (String) m_parsedCommands.get(name);	    try {		StringTokenizer st= new StringTokenizer(v, ",");		int tokCnt= st.countTokens();		if (tokCnt != 0) {		    String[] retval= new String[tokCnt];		    int i= 0;		    while (st.hasMoreTokens()) {			retval[i]= st.nextToken();			i++;		    }		    // return the tokenized String array		    return (retval);		}	    } catch (NumberFormatException e) {		if (Monitor.logLevel > 3)		    Monitor.log("Error Parsing Option: " + v);        	    }	} else {	    m_unSpecified += name + ",";	}	return (def);    }    /**     * returns the array of integers corresponding to an option name or the def     * value if parsing fails or the option is not found     *      * @param name of the configuration parameter     * @param def default value to use     * @param retval the value of the configuration parameter     */    public int[] getIntArray(String name, int[] def) {	String v= null;	if (m_parsedCommands.containsKey(name)) {	    v= (String) m_parsedCommands.get(name);	    try {		StringTokenizer st= new StringTokenizer(v, ",");		int tokCnt= st.countTokens();		if (tokCnt != 0) {		    int[] retval= new int[tokCnt];		    int i= 0;		    while (st.hasMoreTokens()) {			retval[i]= Integer.parseInt(st.nextToken());			i++;		    }		    // return the tokenized int array		    return (retval);		}	    } catch (NumberFormatException e) {		if (Monitor.logLevel > 3)		    Monitor.log("Error Parsing Option: " + v);        	    }	} else {	    m_unSpecified += name + ",";	}	return (def);    }       /**     * returns the array of doubles corresponding to an option name or the def     * value if parsing fails or the option is not found     *      * @param name of the configuration parameter     * @param def default value to use     * @param retval the value of the configuration parameter     */    public double[] getDoubleArray(String name, double[] def) {	String v= null;	if (m_parsedCommands.containsKey(name)) {	    v= (String) m_parsedCommands.get(name);	    try {		StringTokenizer st= new StringTokenizer(v, ",");		int tokCnt= st.countTokens();		if (tokCnt != 0) {		    double[] retval= new double[tokCnt];		    int i= 0;		    while (st.hasMoreTokens()) {			retval[i]= Double.parseDouble(st.nextToken());			i++;		    }		    // return the tokenized double array		    return (retval);		}	    } catch (NumberFormatException e) {		if (Monitor.logLevel > 3)		    Monitor.log("Error Parsing Option: " + v);        	    }	} else {	    m_unSpecified += name + ",";	}	return (def);    }      /**     * Add an option directly     *      * @param n name of option     * @param v value for option     */    public void addOption(String n, String v) {	m_parsedCommands.put(n, v);    }    /**     * Remove the named option from the list of options     * @param name     */    public void removeOption(String name) {	m_parsedCommands.remove(name);    }      /** Adds an option but checks to see if it is valid first */    public void safeAddOption(String n, String v) throws Exception {	if (isValid(n))	    m_parsedCommands.put(n,v);	else	    throw (new Exception("Invalid option " + n));    }    /**     * Add a valid option this will be added to a list of valid options which can     * be used to check if the input is reasonable     */    public void addValid(String n) {	m_validCommands.add(n);    }    /**      * Checks to see if a name is in the valid list      *  @param name of the command     *  @return true if the name is contained in the list of valid commands      */    public boolean isValid(String n) {	int s= m_validCommands.size();	int i;	String command= null;	for (i= 0; i < s; i++) {	    command= (String) m_validCommands.get(i);	    if (command.equals(n)) {		return true;	    }	}	return false;    }    /** Searches the list of options for one with the given name 	private Command findName(String n) {	int s= m_parsedCommands.size();	int i;	Command tmp= null;	for (i= 0; i < s; i++) {	tmp= (Command) m_parsedCommands.get(i);	if (tmp.equals(n))        return (tmp);	}	return (null);	}*/    /**     * Return the list of unspecified options     * @return list of unspecified options     */    public String getUnSpecified() {	if (m_unSpecified != null) {	    return m_unSpecified.substring(0, m_unSpecified.length() - 1);	} else {	    return null;	}    }    /**     *  Yields a string containing all the configuration options not used      *      */    public String unused() {	String retval= new String();	/*    Command tmp= null;	      int i= 0;	      for (i= 0; i < m_parsedCommands.size(); i++) {	      tmp= (Command) m_parsedCommands.get(i);	      if (tmp.getCount() == 0)	      retval += tmp + ",";	      }	      if (retval.length() > 0)	      retval= retval.substring(0, retval.length() - 1);	      else	      retval= null;	      return (retval);	      }*/	return retval;    }}/** * This class implements a single option storing its name and value */class Command {    String name;    String value;    int checkCount= 0;    public boolean equals(Command c) {	return (name.equals(c.name));    }    public boolean equals(String n) {	return (name.equals(n));    }    public Command(String n, String v) {	name= n;	value= v;    }    public String getValue() {	checkCount++;	return (value);    }    public int getCount() {	return (checkCount);    }    public String toString() {	String retval= new String("-");	retval += name + " " + value;	return (retval);    }}

⌨️ 快捷键说明

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