Skip to content

Commit

Permalink
add long value support
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <[email protected]>
  • Loading branch information
Kavindu-Dodan authored and toddbaert committed Jun 7, 2023
1 parent 7e54a26 commit e78fed7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/dev/openfeature/sdk/FlagMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public Integer getInteger(final String key) {
return getValue(key, Integer.class);
}

/**
* Retrieve a {@link Long} value for the given key. A {@code null} value is returned if the key does not exist
* or if the value is of a different type.
*
* @param key flag metadata key to retrieve
*/
public Long getLong(final String key) {
return getValue(key, Long.class);
}

/**
* Retrieve a {@link Float} value for the given key. A {@code null} value is returned if the key does not exist
* or if the value is of a different type.
Expand Down Expand Up @@ -123,6 +133,17 @@ public FlagMetadataBuilder addInteger(final String key, final Integer value) {
return this;
}

/**
* Add Long value to the metadata.
*
* @param key flag metadata key to add
* @param value flag metadata value to add
*/
public FlagMetadataBuilder addLong(final String key, final Long value) {
metadata.put(key, value);
return this;
}

/**
* Add Float value to the metadata.
*
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/dev/openfeature/sdk/FlagMetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void builder_validation() {
FlagMetadata flagMetadata = FlagMetadata.builder()
.addString("string", "string")
.addInteger("integer", 1)
.addLong("long", 1L)
.addFloat("float", 1.5f)
.addDouble("double", Double.MAX_VALUE)
.addBoolean("boolean", Boolean.FALSE)
Expand All @@ -22,6 +23,7 @@ public void builder_validation() {
// then
assertThat(flagMetadata.getString("string")).isEqualTo("string");
assertThat(flagMetadata.getInteger("integer")).isEqualTo(1);
assertThat(flagMetadata.getLong("long")).isEqualTo(1L);
assertThat(flagMetadata.getFloat("float")).isEqualTo(1.5f);
assertThat(flagMetadata.getDouble("double")).isEqualTo(Double.MAX_VALUE);
assertThat(flagMetadata.getBoolean("boolean")).isEqualTo(Boolean.FALSE);
Expand Down

0 comments on commit e78fed7

Please sign in to comment.