diff --git a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java index 54f47061..9c617f2f 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java @@ -135,6 +135,17 @@ public interface KeyValue { */ int getInt(String key); + /** + * Searches for the {@code int} property with the specified key in this {@code KeyValue} object. If the key is not + * found in this property list, the default value argument is returned. + * + * @param key the property key + * @param defaultValue a default value + * @return the value in this {@code KeyValue} object with the specified key value + * @see #put(String, int) + */ + int getInt(String key, int defaultValue); + /** * Searches for the {@code long} property with the specified key in this {@code KeyValue} object. If the key is not * found in this property list, zero is returned. @@ -166,6 +177,17 @@ public interface KeyValue { */ double getDouble(String key); + /** + * Searches for the {@code double} property with the specified key in this {@code KeyValue} object. If the key is + * not found in this property list, the default value argument is returned. + * + * @param key the property key + * @param defaultValue a default value + * @return the value in this {@code KeyValue} object with the specified key value + * @see #put(String, double) + */ + double getDouble(String key, double defaultValue); + /** * Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is * not found in this property list, {@code null} is returned. @@ -176,6 +198,17 @@ public interface KeyValue { */ String getString(String key); + /** + * Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is + * not found in this property list, the default value argument is returned. + * + * @param key the property key + * @param defaultValue a default value + * @return the value in this {@code KeyValue} object with the specified key value + * @see #put(String, String) + */ + String getString(String key, String defaultValue); + /** * Returns a {@link Set} view of the keys contained in this {@code KeyValue} object. *
diff --git a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java
index 67eb0b96..952e17c6 100644
--- a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java
+++ b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java
@@ -105,6 +105,11 @@ public int getInt(String key) {
return Integer.valueOf(properties.get(key));
}
+ @Override
+ public int getInt(final String key, final int defaultValue) {
+ return properties.containsKey(key) ? getInt(key) : defaultValue;
+ }
+
@Override
public long getLong(String key) {
if (!properties.containsKey(key)) {
@@ -126,11 +131,21 @@ public double getDouble(String key) {
return Double.valueOf(properties.get(key));
}
+ @Override
+ public double getDouble(final String key, final double defaultValue) {
+ return properties.containsKey(key) ? getDouble(key) : defaultValue;
+ }
+
@Override
public String getString(String key) {
return properties.get(key);
}
+ @Override
+ public String getString(final String key, final String defaultValue) {
+ return properties.containsKey(key) ? getString(key) : defaultValue;
+ }
+
@Override
public Set