sphinxproperties.java

来自「It is the Speech recognition software. 」· Java 代码 · 共 611 行 · 第 1/2 页

JAVA
611
字号
     * Returns true if this SphinxProperties contains the given     * property.     *     * @return true if it has the given property, false otherwise     */    public boolean contains(String propertyName) {	String value = System.getProperty(propertyName);	if (value == null) {	    return props.contains(propertyName);	} else {	    return true;	}    }    /**     * Searches for and returns the value of the given property.     *     * @param propertyName the property to search for     *     * @return the value of the property, or null if the property     *    does not exists     */    private String getString(String propertyName) {	String value = System.getProperty(propertyName);	if (value == null) {	    value = props.getProperty(propertyName);	}	return value;    }    /**     * Searches for the property with the specified name.     *     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     */    public String getString(String propertyName, String defaultValue) {	String value = getString(propertyName);	if (value == null) {	    warnNoProperty(propertyName, defaultValue);	    value = defaultValue;	}	if (value != null) {            value = value.trim();	    shadowProps.setProperty(propertyName, value);	}	return value;    }    /**     * Searches for the property with the specified name of a     * particular instance.  This is a conveniance method, since many      * property accesses are built by concatenating the instance name     * and the property name, this method is provided to make it     * easier.       *     * @param instanceName the name of the particular instance     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     */    public String getString(String instanceName,			    String propertyName, String defaultValue) {        String value = getString(instanceName + ";" + propertyName);        if (value == null) {            value = getString(propertyName, defaultValue);        } else {            shadowProps.setProperty(instanceName + ";" + propertyName, value);        }	if (value != null) {	    value = value.trim();	}	return value;    }    /**     * Searches for the property with the specified name.     *     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     *     * @throws NumberFormatException if the property cannot be     * 	converted to the number format     */    public float getFloat(String propertyName, float defaultValue)     		throws NumberFormatException {	float value = defaultValue;	String svalue = getString(propertyName, String.valueOf(defaultValue));       	if (svalue != null) {	    value = Float.parseFloat(svalue);	}	return value;    }    /**     * Searches for the property with the specified name of a     * particular instance.  This is a conveniance method, since many      * property accesses are built by concatenating the instance name     * and the property name, this method is provided to make it     * easier.       *     * @param instanceName the name of the particular instance     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     * @throws NumberFormatException if the property cannot be     * 	converted to the number format     */    public float getFloat(String instanceName,                           String propertyName, float defaultValue)     		throws NumberFormatException {        return Float.parseFloat(getString(instanceName, propertyName,                                          String.valueOf(defaultValue)));    }    /**     * Searches for the property with the specified name.     *     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     *     * @throws NumberFormatException if the property cannot be     * 	converted to the number format     */    public double getDouble(String propertyName, double defaultValue)     		throws NumberFormatException {	double value = defaultValue;	String svalue = getString(propertyName, String.valueOf(defaultValue));	if (svalue != null) {	    value = Double.parseDouble(svalue);	}	return value;    }    /**     * Searches for the property with the specified name of a     * particular instance.  This is a conveniance method, since many      * property accesses are built by concatenating the instance name     * and the property name, this method is provided to make it     * easier.       *     * @param instanceName the name of the particular instance     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     * @throws NumberFormatException if the property cannot be     * 	converted to the number format     */    public double getDouble(String instanceName,                             String propertyName, double defaultValue)         throws NumberFormatException {        return Double.parseDouble(getString(instanceName, propertyName,                                            String.valueOf(defaultValue)));    }    /**     * Searches for the property with the specified name.     *     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     *     * @throws NumberFormatException if the property cannot be     * 	converted to the number format     */    public int getInt(String propertyName, int defaultValue)         throws NumberFormatException {	int value = defaultValue;	String svalue = getString(propertyName, String.valueOf(defaultValue));	if (svalue != null) {	    value = Integer.parseInt(svalue);	}	return value;    }    /**     * Searches for the property with the specified name of a     * particular instance.  This is a conveniance method, since many      * property accesses are built by concatenating the instance name     * and the property name, this method is provided to make it     * easier.       *     * @param instanceName the name of the particular instance     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     * @throws NumberFormatException if the property cannot be     * 	converted to the number format     */    public int getInt(String instanceName,                       String propertyName, int defaultValue)         throws NumberFormatException {        return Integer.parseInt(getString(instanceName, propertyName,                                          String.valueOf(defaultValue)));    }    /**     * Searches for the property with the specified name. The string     * values: true, on, 1 and enabled all correspond to true,     * anything else is considered false.     *     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     *     */    public boolean getBoolean(String propertyName, boolean defaultValue) {	boolean value = defaultValue;	String svalue = getString(propertyName, String.valueOf(defaultValue));	if (svalue != null) {	    value = isTrue(svalue);	}	return value;    }    /**     * Searches for the property with the specified name of a     * particular instance.  This is a conveniance method, since many      * property accesses are built by concatenating the instance name     * and the property name, this method is provided to make it     * easier.       *     * @param instanceName the name of the particular instance     * @param propertyName the name of the property to search for     * @param defaultValue the value to return if the property is not     *    found     *     * @return the value of the property     * @throws NumberFormatException if the property cannot be     * 	converted to the number format     */    public boolean getBoolean(String instanceName, 	    		String propertyName, boolean defaultValue) {        return isTrue(getString(instanceName, propertyName,                                String.valueOf(defaultValue)));    }    /**     * Returns true if the given string is either "true", "on", "1", or     * "enabled" (case ignored).     *     * @param booleanString the string to inspect     *     * @return true if the string represents true, false otherwise     */    private boolean isTrue(String booleanString) {        return (booleanString.equalsIgnoreCase("true") ||                booleanString.equalsIgnoreCase("on") ||                booleanString.equalsIgnoreCase("1") ||                booleanString.equalsIgnoreCase("enabled"));    }    /**     * Prints out a warning to System.out saying that the given     * property does not exist and is using the given default value.     *     * @param propertyName the name of the property     * @param defaultValue the default value used     */    private void warnNoProperty(String propertyName, String defaultValue) {	// print out the warning only if the property has never been	// searched for	if (warnIfNoProperty && !shadowProps.containsKey(propertyName)) {	    System.out.println("WARNING: no property, "                     + propertyName + "\n"                     + "         using the default value "                     + defaultValue);	}    }}

⌨️ 快捷键说明

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