Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions openmessaging-api/src/main/java/io/openmessaging/KeyValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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<String> keySet() {
return properties.keySet();
Expand Down