From e8f0cdf4826ce2042bc6bf9df3a9e36983397c9b Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Tue, 26 Feb 2019 14:58:39 +0800 Subject: [PATCH 1/3] extend KeyValue --- .../main/java/io/openmessaging/KeyValue.java | 30 +++++++++++++++++++ .../internal/DefaultKeyValue.java | 19 ++++++++++++ 2 files changed, 49 insertions(+) diff --git a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java index d521bb6e..2730047a 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java @@ -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 key + */ + KeyValue put(String key, boolean value); + /** * Inserts or replaces {@code short} value for the specified key. * @@ -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. 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 e2f6477b..bf0e836c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java @@ -31,6 +31,25 @@ public class DefaultKeyValue implements KeyValue { private Map 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 int getShort(String key) { return 0; From fe5e4ada61ba56ea6c8b3bbbb0438454281925cd Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Thu, 28 Feb 2019 10:38:53 +0800 Subject: [PATCH 2/3] merge --- .../main/java/io/openmessaging/KeyValue.java | 29 ------------------- .../internal/DefaultKeyValue.java | 19 ------------ 2 files changed, 48 deletions(-) diff --git a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java index 2730047a..80b38c82 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java @@ -35,14 +35,6 @@ */ 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 key - */ - KeyValue put(String key, boolean value); - /** * Inserts or replaces {@code short} value for the specified key. * @@ -83,27 +75,6 @@ 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. 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 bf0e836c..e2f6477b 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java @@ -31,25 +31,6 @@ public class DefaultKeyValue implements KeyValue { private Map 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 int getShort(String key) { return 0; From 81eb092fcb52e4336287e5a870087644207602cd Mon Sep 17 00:00:00 2001 From: gaohaoxiang Date: Thu, 28 Feb 2019 10:43:41 +0800 Subject: [PATCH 3/3] Add boolean type to KeyValue --- .../main/java/io/openmessaging/KeyValue.java | 29 +++++++++++++++++++ .../internal/DefaultKeyValue.java | 19 ++++++++++++ 2 files changed, 48 insertions(+) diff --git a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java index 53f5b52f..2cfb650a 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java @@ -35,6 +35,14 @@ */ 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 key + */ + KeyValue put(String key, boolean value); + /** * Inserts or replaces {@code short} value for the specified key. * @@ -75,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. 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 be121b9b..952e17c6 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java +++ b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java @@ -31,6 +31,25 @@ public class DefaultKeyValue implements KeyValue { private Map 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)) {