?? compositeconfiguration.java
字號:
* Get a byte associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated byte if key is found and has valid format, default
* value otherwise.
* @exception ClassCastException is thrown if the key maps to an object that
* is not a Byte.
* @exception NumberFormatException is thrown if the value mapped by the key
* has not a valid number format.
*/
public Byte getByte(String key, Byte defaultValue)
{
try
{
return getFirstMatchingConfig(key).getByte(key, defaultValue);
}
catch (NoSuchElementException nsee)
{
return defaultValue;
}
}
/**
* Get a double associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated double.
* @exception NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Double.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public double getDouble(String key)
{
return getFirstMatchingConfig(key).getDouble(key);
}
/**
* Get a double associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated double.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Double.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public double getDouble(String key, double defaultValue)
{
return getDouble(key, new Double(defaultValue)).doubleValue();
}
/**
* Get a double associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated double if key is found and has valid
* format, default value otherwise.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Double.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Double getDouble(String key, Double defaultValue)
{
try
{
return getFirstMatchingConfig(key).getDouble(key, defaultValue);
}
catch (NoSuchElementException nsee)
{
return defaultValue;
}
}
/**
* Get a float associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated float.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Float.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public float getFloat(String key, float defaultValue)
{
return getFloat(key, new Float(defaultValue)).floatValue();
}
/**
* Get a float associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated float if key is found and has valid
* format, default value otherwise.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Float.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Float getFloat(String key, Float defaultValue)
{
try
{
return getFirstMatchingConfig(key).getFloat(key, defaultValue);
}
catch (NoSuchElementException nsee)
{
return defaultValue;
}
}
/**
* Get a int associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated int.
* @exception NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Integer.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public int getInt(String key)
{
return getFirstMatchingConfig(key).getInt(key);
}
/**
* Get a int associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated int.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Integer.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public int getInt(String key, int defaultValue)
{
return getInteger(key, new Integer(defaultValue)).intValue();
}
/**
* Get a int associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated int if key is found and has valid format, default
* value otherwise.
* @exception ClassCastException is thrown if the key maps to an object that
* is not a Integer.
* @exception NumberFormatException is thrown if the value mapped by the key
* has not a valid number format.
*/
public Integer getInteger(String key, Integer defaultValue)
{
try
{
return getFirstMatchingConfig(key).getInteger(key, defaultValue);
}
catch (NoSuchElementException nsee)
{
return defaultValue;
}
}
/**
* Get a long associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated long.
* @exception NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Long.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public long getLong(String key)
{
return getFirstMatchingConfig(key).getLong(key);
}
/**
* Get a long associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated long.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Long.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public long getLong(String key, long defaultValue)
{
return getLong(key, new Long(defaultValue)).longValue();
}
/**
* Get a long associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated long if key is found and has valid
* format, default value otherwise.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Long.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Long getLong(String key, Long defaultValue)
{
try
{
return getFirstMatchingConfig(key).getLong(key, defaultValue);
}
catch (NoSuchElementException nsee)
{
return defaultValue;
}
}
/**
* Get a short associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated short.
* @exception NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Short.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public short getShort(String key)
{
return getFirstMatchingConfig(key).getShort(key);
}
/**
* Get a short associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated short.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Short.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public short getShort(String key, short defaultValue)
{
return getShort(key, new Short(defaultValue)).shortValue();
}
/**
* Get a short associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated short if key is found and has valid
* format, default value otherwise.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Short.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public Short getShort(String key, Short defaultValue)
{
try
{
return getFirstMatchingConfig(key).getShort(key, defaultValue);
}
catch (NoSuchElementException nsee)
{
return defaultValue;
}
}
/**
* Get a string associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated string.
* @exception ClassCastException is thrown if the key maps to an object that
* is not a String.
*/
public String getString(String key)
{
return getString(key, null);
}
/**
* Get a string associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated string if key is found, default value otherwise.
* @exception ClassCastException is thrown if the key maps to an object that
* is not a String.
*/
public String getString(String key, String defaultValue)
{
try
{
return getFirstMatchingConfig(key).getString(key, defaultValue);
}
catch (NoSuchElementException nsee)
{
return defaultValue;
}
}
/**
* Get an array of strings associated with the given configuration
* key.
*
* @param key The configuration key.
* @return The associated string array if key is found.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a String/Vector of Strings.
*/
public String[] getStringArray(String key)
{
Vector v = getVector(key);
return (String []) v.toArray(new String [0]);
}
/**
* Get a Vector of strings associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated Vector.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Vector.
*/
public Vector getVector(String key)
{
Vector v = new Vector();
for (ListIterator li = configList.listIterator(); li.hasNext();)
{
Configuration config = (Configuration) li.next();
if (config.containsKey(key))
{
v.addAll(config.getVector(key));
}
}
return v;
}
/**
* Get a Vector of strings associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated Vector.
* @exception ClassCastException is thrown if the key maps to an
* object that is not a Vector.
*/
public Vector getVector(String key, Vector defaultValue)
{
Vector v = getVector(key);
return (v.size() == 0) ? defaultValue : v;
}
private Configuration getFirstMatchingConfig(String key)
{
for (ListIterator i = configList.listIterator(); i.hasNext();)
{
Configuration config = (Configuration) i.next();
if (config.containsKey(key))
{
return config;
}
}
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
}
public Configuration getConfiguration(int index)
{
return (Configuration) configList.get(index);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -