?? configuration.java
字號:
* 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)
{
Object value = get(key);
if (value instanceof Short)
{
return (Short) value;
}
else if (value instanceof String)
{
Short s = new Short((String) value);
put(key, s);
return s;
}
else if (value == null)
{
if (defaults != null)
{
return defaults.getShort(key, defaultValue);
}
else
{
return defaultValue;
}
}
else
{
throw new ClassCastException(
'\'' + key + "' doesn't map to a Short object");
}
}
/**
* The purpose of this method is to get the configuration resource
* with the given name as an integer.
*
* @param name The resource name.
* @return The value of the resource as an integer.
*/
public int getInt(String name)
{
return getInteger(name);
}
/**
* The purpose of this method is to get the configuration resource
* with the given name as an integer, or a default value.
*
* @param name The resource name
* @param def The default value of the resource.
* @return The value of the resource as an integer.
*/
public int getInt(String name,
int def)
{
return getInteger(name, def);
}
/**
* 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 getInteger(String key)
{
Integer i = getInteger(key, null);
if (i != null)
{
return i.intValue();
}
else
{
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
}
}
/**
* 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 getInteger(String key,
int defaultValue)
{
Integer i = getInteger(key, null);
if (i == null)
{
return defaultValue;
}
return i.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)
{
Object value = get(key);
if (value instanceof Integer)
{
return (Integer) value;
}
else if (value instanceof String)
{
Integer i = new Integer((String) value);
put(key, i);
return i;
}
else if (value == null)
{
if (defaults != null)
{
return defaults.getInteger(key, defaultValue);
}
else
{
return defaultValue;
}
}
else
{
throw new ClassCastException(
'\'' + key + "' doesn't map to a Integer object");
}
}
/**
* 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)
{
Long l = getLong(key, null);
if (l != null)
{
return l.longValue();
}
else
{
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
}
}
/**
* 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)
{
Object value = get(key);
if (value instanceof Long)
{
return (Long) value;
}
else if (value instanceof String)
{
Long l = new Long((String) value);
put(key, l);
return l;
}
else if (value == null)
{
if (defaults != null)
{
return defaults.getLong(key, defaultValue);
}
else
{
return defaultValue;
}
}
else
{
throw new ClassCastException(
'\'' + key + "' doesn't map to a Long object");
}
}
/**
* Get a float associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated float.
* @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 Float.
* @exception NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public float getFloat(String key)
{
Float f = getFloat(key, null);
if (f != null)
{
return f.floatValue();
}
else
{
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
}
}
/**
* 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)
{
Object value = get(key);
if (value instanceof Float)
{
return (Float) value;
}
else if (value instanceof String)
{
Float f = new Float((String) value);
put(key, f);
return f;
}
else if (value == null)
{
if (defaults != null)
{
return defaults.getFloat(key, defaultValue);
}
else
{
return defaultValue;
}
}
else
{
throw new ClassCastException(
'\'' + key + "' doesn't map to a Float object");
}
}
/**
* 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)
{
Double d = getDouble(key, null);
if (d != null)
{
return d.doubleValue();
}
else
{
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
}
}
/**
* 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)
{
Object value = get(key);
if (value instanceof Double)
{
return (Double) value;
}
else if (value instanceof String)
{
Double d = new Double((String) value);
put(key, d);
return d;
}
else if (value == null)
{
if (defaults != null)
{
return defaults.getDouble(key, defaultValue);
}
else
{
return defaultValue;
}
}
else
{
throw new ClassCastException(
'\'' + key + "' doesn't map to a Double object");
}
}
/**
* Convert a standard properties class into a configuration
* class.
*
* @param Properties properties object to convert into
* a Configuration object.
*
* @return Configuration configuration created from the
* properties object.
*/
public static Configuration convertProperties(Properties p)
{
Configuration c = new Configuration();
for (Enumeration e = p.keys(); e.hasMoreElements() ; )
{
String s = (String) e.nextElement();
c.setProperty(s, p.getProperty(s));
}
return c;
}
/**
* <p>
* Routine intended for deprecation period only
* as we switch from using the Configuration
* class in Velocity to the Jakarta Commons
* ExtendedProperties
* </p>
* <p>
* Do not use this for general use. It will disappear
* </p>
* @return ExtendedProperties containing data of Configuration
*
* @deprecated Do not use. For deprecation assistance only.
*/
public ExtendedProperties getExtendedProperties()
{
return deprecationCrutch;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -