Skip to content

Commit 52c7f99

Browse files
feat: add hook data support (#1620)
* feat: add hook data support Signed-off-by: Alexandra Oberaigner <[email protected]> * feat: gemini suggestions Signed-off-by: Alexandra Oberaigner <[email protected]> * feat: hook executor impl (WIP) Signed-off-by: Alexandra Oberaigner <[email protected]> * Use shared hook context Signed-off-by: Guido Breitenhuber <[email protected]> * Split HookData interface and implementation Signed-off-by: Guido Breitenhuber <[email protected]> * Atopted tests Signed-off-by: Guido Breitenhuber <[email protected]> * Remove obsolete test Signed-off-by: Guido Breitenhuber <[email protected]> * HookSupport improvements: rename back to old name, move code from static factory method to ctor Signed-off-by: Alexandra Oberaigner <[email protected]> * PR suggestion: use concrete hooks Signed-off-by: Alexandra Oberaigner <[email protected]> * PR suggestions: DefaultHookData access modifier, no star imports Signed-off-by: Alexandra Oberaigner <[email protected]> * feat: separate hook support data from logic, PR suggestions Signed-off-by: Alexandra Oberaigner <[email protected]> * Update DefaultHookDataTest.java spotless Signed-off-by: Alexandra Oberaigner <[email protected]> * fix tests, spotless apply Signed-off-by: Alexandra Oberaigner <[email protected]> * exclude lombok generated functions from codecov Signed-off-by: Alexandra Oberaigner <[email protected]> * replace init function with setters Signed-off-by: Alexandra Oberaigner <[email protected]> * pr suggestion: replace Generated annotation with more descriptive ExcludeFromGeneratedCoverageReport, replace delomboked functions with lombok annotations Signed-off-by: Alexandra Oberaigner <[email protected]> * PR suggestion: make HookSupportData a real POJO Signed-off-by: Alexandra Oberaigner <[email protected]> * gemini suggestions Signed-off-by: Alexandra Oberaigner <[email protected]> * PR suggestion: call hooks as early as possible Signed-off-by: Alexandra Oberaigner <[email protected]> * PR suggestions: integration test hook data usage in client, set pair value Signed-off-by: Alexandra Oberaigner <[email protected]> * add hook data spec test Signed-off-by: Alexandra Oberaigner <[email protected]> --------- Signed-off-by: Alexandra Oberaigner <[email protected]> Signed-off-by: Guido Breitenhuber <[email protected]> Co-authored-by: Guido Breitenhuber <[email protected]>
1 parent 71dfb08 commit 52c7f99

17 files changed

+926
-159
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dev.openfeature.sdk;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* Default implementation of HookData.
8+
*/
9+
public class DefaultHookData implements HookData {
10+
private Map<String, Object> data;
11+
12+
@Override
13+
public void set(String key, Object value) {
14+
if (data == null) {
15+
data = new HashMap<>();
16+
}
17+
data.put(key, value);
18+
}
19+
20+
@Override
21+
public Object get(String key) {
22+
if (data == null) {
23+
return null;
24+
}
25+
return data.get(key);
26+
}
27+
28+
@Override
29+
public <T> T get(String key, Class<T> type) {
30+
Object value = get(key);
31+
if (value == null) {
32+
return null;
33+
}
34+
if (!type.isInstance(value)) {
35+
throw new ClassCastException("Value for key '" + key + "' is not of type " + type.getName());
36+
}
37+
return type.cast(value);
38+
}
39+
}

0 commit comments

Comments
 (0)