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
30 changes: 30 additions & 0 deletions openmessaging-api/src/main/java/io/openmessaging/KeyValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
* @since OMS 1.0.0
*/
public interface KeyValue {

/**
* Inserts or replaces {@code boolean} value for the specified key.
*
* @param key the key to be placed into this {@code KeyValue} object
* @param value the value corresponding to <tt>key</tt>
*/
KeyValue put(String key, boolean value);

/**
* Inserts or replaces {@code short} value for the specified key.
*
Expand Down Expand Up @@ -74,6 +83,27 @@ public interface KeyValue {
*/
KeyValue put(String key, String value);

/**
* Searches for the {@code boolean} property with the specified key in this {@code KeyValue} object. If the key is not
* found in this property list, false is returned.
*
* @param key the property key
* @return the value in this {@code KeyValue} object with the specified key value
* @see #put(String, boolean)
*/
boolean getBoolean(String key);

/**
* Searches for the {@code boolean} property with the specified key in this {@code KeyValue} object. If the key is not
* found in this property list, false 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, boolean)
*/
boolean getBoolean(String key, boolean defaultValue);

/**
* Searches for the {@code short} 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@
public class DefaultKeyValue implements KeyValue {
private Map<String, String> properties;

@Override
public KeyValue put(String key, boolean value) {
properties.put(key, String.valueOf(value));
return this;
}

@Override
public boolean getBoolean(String key) {
if (!properties.containsKey(key)) {
return false;
}
return Boolean.valueOf(properties.get(key));
}

@Override
public boolean getBoolean(String key, boolean defaultValue) {
return properties.containsKey(key) ? getBoolean(key) : defaultValue;
}

@Override
public short getShort(String key) {
if (!properties.containsKey(key)) {
Expand Down