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
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,21 @@
@Public
public class MetricConfig extends Properties {

/**
* Returns the value associated with the given key as a {@code String}.
*
* <p>If the value is not a {@link String}, its {@code toString()} representation is returned.
*
* @param key the hashtable key.
* @param defaultValue a default value.
* @return the value in this property list with the specified key value as a String.
*/
public String getString(String key, String defaultValue) {
return getProperty(key, defaultValue);
final Object value = get(key);
if (value == null) {
return defaultValue;
}
return value.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ private static Stream<Arguments> nativeTypeCases() {
123456789012345L),
Arguments.of(3.14f, (TypedGetter) (c, k) -> c.getFloat(k, 0.0f), 3.14f),
Arguments.of(2.718281828, (TypedGetter) (c, k) -> c.getDouble(k, 0.0), 2.718281828),
Arguments.of(true, (TypedGetter) (c, k) -> c.getBoolean(k, false), true));
Arguments.of(true, (TypedGetter) (c, k) -> c.getBoolean(k, false), true),
Arguments.of(42, (TypedGetter) (c, k) -> c.getString(k, "default"), "42"),
Arguments.of(
123456789012345L,
(TypedGetter) (c, k) -> c.getString(k, "default"),
"123456789012345"),
Arguments.of(3.14f, (TypedGetter) (c, k) -> c.getString(k, "default"), "3.14"),
Arguments.of(true, (TypedGetter) (c, k) -> c.getString(k, "default"), "true"));
}

private static Stream<Arguments> crossTypeCases() {
Expand Down