📄 extendedproperties.java
字号:
if (defaults != null) {
return defaults.getByte(key, defaultValue);
} else {
return defaultValue;
}
} else {
throw new ClassCastException('\'' + key + "' doesn't map to a Byte object");
}
}
/**
* Get a short associated with the given configuration key.
*
* @param key The configuration key.
* @return The associated short.
* @throws NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Short.
* @throws NumberFormatException is thrown if the value mapped
* by the key has not a valid number format.
*/
public short getShort(String key) {
Short s = getShort(key, null);
if (s != null) {
return s.shortValue();
} else {
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object");
}
}
/**
* Get a short associated with the given configuration key.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated short.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Short.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Short.
* @throws 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.
* @throws NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Integer.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Integer.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Integer.
* @throws 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.
* @throws NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Long.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Long.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Long.
* @throws 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.
* @throws NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Float.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Float.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Float.
* @throws 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.
* @throws NoSuchElementException is thrown if the key doesn't
* map to an existing object.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Double.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Double.
* @throws 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.
* @throws ClassCastException is thrown if the key maps to an
* object that is not a Double.
* @throws 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 props the properties object to convert
* @return new ExtendedProperties created from props
*/
public static ExtendedProperties convertProperties(Properties props) {
ExtendedProperties c = new ExtendedProperties();
for (Enumeration e = props.keys(); e.hasMoreElements();) {
String s = (String) e.nextElement();
c.setProperty(s, props.getProperty(s));
}
return c;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -