Skip to content

Commit fdbd753

Browse files
author
gaohaoxiang
committed
Fix KeyValue merge problem
1 parent 3509172 commit fdbd753

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

openmessaging-api/src/main/java/io/openmessaging/KeyValue.java

+33
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ public interface KeyValue {
135135
*/
136136
int getInt(String key);
137137

138+
/**
139+
* Searches for the {@code int} property with the specified key in this {@code KeyValue} object. If the key is not
140+
* found in this property list, the default value argument is returned.
141+
*
142+
* @param key the property key
143+
* @param defaultValue a default value
144+
* @return the value in this {@code KeyValue} object with the specified key value
145+
* @see #put(String, int)
146+
*/
147+
int getInt(String key, int defaultValue);
148+
138149
/**
139150
* Searches for the {@code long} property with the specified key in this {@code KeyValue} object. If the key is not
140151
* found in this property list, zero is returned.
@@ -166,6 +177,17 @@ public interface KeyValue {
166177
*/
167178
double getDouble(String key);
168179

180+
/**
181+
* Searches for the {@code double} property with the specified key in this {@code KeyValue} object. If the key is
182+
* not found in this property list, the default value argument is returned.
183+
*
184+
* @param key the property key
185+
* @param defaultValue a default value
186+
* @return the value in this {@code KeyValue} object with the specified key value
187+
* @see #put(String, double)
188+
*/
189+
double getDouble(String key, double defaultValue);
190+
169191
/**
170192
* Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is
171193
* not found in this property list, {@code null} is returned.
@@ -176,6 +198,17 @@ public interface KeyValue {
176198
*/
177199
String getString(String key);
178200

201+
/**
202+
* Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is
203+
* not found in this property list, the default value argument is returned.
204+
*
205+
* @param key the property key
206+
* @param defaultValue a default value
207+
* @return the value in this {@code KeyValue} object with the specified key value
208+
* @see #put(String, String)
209+
*/
210+
String getString(String key, String defaultValue);
211+
179212
/**
180213
* Returns a {@link Set} view of the keys contained in this {@code KeyValue} object.
181214
* <p>

openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java

+15
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ public int getInt(String key) {
105105
return Integer.valueOf(properties.get(key));
106106
}
107107

108+
@Override
109+
public int getInt(final String key, final int defaultValue) {
110+
return properties.containsKey(key) ? getInt(key) : defaultValue;
111+
}
112+
108113
@Override
109114
public long getLong(String key) {
110115
if (!properties.containsKey(key)) {
@@ -126,11 +131,21 @@ public double getDouble(String key) {
126131
return Double.valueOf(properties.get(key));
127132
}
128133

134+
@Override
135+
public double getDouble(final String key, final double defaultValue) {
136+
return properties.containsKey(key) ? getDouble(key) : defaultValue;
137+
}
138+
129139
@Override
130140
public String getString(String key) {
131141
return properties.get(key);
132142
}
133143

144+
@Override
145+
public String getString(final String key, final String defaultValue) {
146+
return properties.containsKey(key) ? getString(key) : defaultValue;
147+
}
148+
134149
@Override
135150
public Set<String> keySet() {
136151
return properties.keySet();

0 commit comments

Comments
 (0)