-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add flag evaluation metadata to evaluation details #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
android/src/main/java/dev/openfeature/sdk/FlagEvaluationMetadata.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package dev.openfeature.sdk | ||
|
|
||
| class EvaluationMetadata internal constructor(private val values: Map<String, Any>) { | ||
|
|
||
| fun getString(key: String): String? = values[key] as? String | ||
|
|
||
| fun getBoolean(key: String): Boolean? = values[key] as? Boolean | ||
|
|
||
| fun getInt(key: String): Int? = values[key] as? Int | ||
|
|
||
| fun getDouble(key: String): Double? = values[key] as? Double | ||
|
|
||
| fun getAny(key: String): Any? = values[key] | ||
|
|
||
| companion object { | ||
| fun builder(): Builder { | ||
| return Builder() | ||
| } | ||
|
|
||
| val EMPTY = EvaluationMetadata(emptyMap()) | ||
| } | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) return true | ||
| if (javaClass != other?.javaClass) return false | ||
|
|
||
| other as EvaluationMetadata | ||
|
|
||
| return values == other.values | ||
| } | ||
|
|
||
| override fun hashCode(): Int { | ||
| return values.hashCode() | ||
| } | ||
| } | ||
|
|
||
| class Builder { | ||
| private val values: MutableMap<String, Any> = mutableMapOf() | ||
|
|
||
| fun putString(key: String, value: String): Builder { | ||
| values[key] = value | ||
| return this | ||
| } | ||
|
|
||
| fun putInt(key: String, value: Int): Builder { | ||
| values[key] = value | ||
| return this | ||
| } | ||
|
|
||
| fun putDouble(key: String, value: Double): Builder { | ||
| values[key] = value | ||
| return this | ||
| } | ||
|
|
||
| fun putBoolean(key: String, value: Boolean): Builder { | ||
| values[key] = value | ||
| return this | ||
| } | ||
|
|
||
| fun build(): EvaluationMetadata { | ||
| return EvaluationMetadata(values.toMap()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
android/src/test/java/dev/openfeature/sdk/EvaluationMetadataTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package dev.openfeature.sdk | ||
|
|
||
| import org.junit.Assert | ||
| import org.junit.Test | ||
|
|
||
| class EvaluationMetadataTest { | ||
|
|
||
| private val metadata = EvaluationMetadata.builder() | ||
| .putString("key1", "value1") | ||
| .putInt("key2", 42) | ||
| .putBoolean("key3", true) | ||
| .putDouble("key4", 2.71828) | ||
| .build() | ||
|
|
||
| @Test | ||
| fun testAddAndGet() { | ||
| Assert.assertEquals("value1", metadata.getString("key1")) | ||
| Assert.assertEquals(42, metadata.getInt("key2")) | ||
| Assert.assertEquals(true, metadata.getBoolean("key3")) | ||
| Assert.assertEquals(2.71828, metadata.getDouble("key4")) | ||
| } | ||
|
|
||
| @Test | ||
| fun testGetNonExistentKey() { | ||
| Assert.assertNull(metadata.getString("key5")) | ||
| } | ||
|
|
||
| @Test | ||
| fun testInvalidType() { | ||
| Assert.assertNull(metadata.getString("key2")) | ||
| Assert.assertNull(metadata.getInt("key3")) | ||
| Assert.assertNull(metadata.getBoolean("key4")) | ||
| Assert.assertNull(metadata.getDouble("key1")) | ||
| } | ||
|
|
||
| @Test | ||
| fun testGetAny() { | ||
| val any: Any? = metadata.getAny("key1") | ||
| Assert.assertEquals("value1", any as? String) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.