1
1
package dev .openfeature .sdk ;
2
2
3
- import dev .openfeature .sdk .exceptions .GeneralError ;
4
- import dev .openfeature .sdk .exceptions .ParseError ;
3
+ import lombok .extern .slf4j .Slf4j ;
5
4
6
5
import java .util .HashMap ;
7
6
import java .util .Map ;
10
9
* Immutable Flag Metadata representation. Implementation is backed by a {@link Map} and immutability is provided
11
10
* through builder and accessors.
12
11
*/
12
+ @ Slf4j
13
13
public class FlagMetadata {
14
14
private final Map <String , Object > metadata ;
15
15
@@ -18,8 +18,8 @@ private FlagMetadata(Map<String, Object> metadata) {
18
18
}
19
19
20
20
/**
21
- * Retrieve a {@link String} value for the given key. If a value is not found, {@link GeneralError} will be thrown.
22
- * If value exist but of another type, {@link ParseError} will be thrown .
21
+ * Retrieve a {@link String} value for the given key. A {@code null} value is returned if the key does not exist
22
+ * or if the value is of a different type .
23
23
*
24
24
* @param key flag metadata key to retrieve
25
25
*/
@@ -28,9 +28,8 @@ public String getString(final String key) {
28
28
}
29
29
30
30
/**
31
- * Retrieve an {@link Integer} value for the given key.
32
- * If a value is not found, {@link GeneralError} will be thrown.
33
- * If value exist but of another type, {@link ParseError} will be thrown.
31
+ * Retrieve a {@link Integer} value for the given key. A {@code null} value is returned if the key does not exist
32
+ * or if the value is of a different type.
34
33
*
35
34
* @param key flag metadata key to retrieve
36
35
*/
@@ -39,8 +38,8 @@ public Integer getInteger(final String key) {
39
38
}
40
39
41
40
/**
42
- * Retrieve a {@link Float} value for the given key. If a value is not found, {@link GeneralError} will be thrown.
43
- * If value exist but of another type, {@link ParseError} will be thrown .
41
+ * Retrieve a {@link Float} value for the given key. A {@code null} value is returned if the key does not exist
42
+ * or if the value is of a different type .
44
43
*
45
44
* @param key flag metadata key to retrieve
46
45
*/
@@ -49,9 +48,8 @@ public Float getFloat(final String key) {
49
48
}
50
49
51
50
/**
52
- * Retrieve a {@link Double} value for the given key.
53
- * If a value is not found, {@link GeneralError} will be thrown.
54
- * If value exist but of another type, {@link ParseError} will be thrown.
51
+ * Retrieve a {@link Double} value for the given key. A {@code null} value is returned if the key does not exist
52
+ * or if the value is of a different type.
55
53
*
56
54
* @param key flag metadata key to retrieve
57
55
*/
@@ -60,9 +58,8 @@ public Double getDouble(final String key) {
60
58
}
61
59
62
60
/**
63
- * Retrieve a {@link Boolean} value for the given key.
64
- * If a value is not found, {@link GeneralError} will be thrown.
65
- * If value exist but of another type, {@link ParseError} will be thrown.
61
+ * Retrieve a {@link Boolean} value for the given key. A {@code null} value is returned if the key does not exist
62
+ * or if the value is of a different type.
66
63
*
67
64
* @param key flag metadata key to retrieve
68
65
*/
@@ -74,15 +71,15 @@ private <T> T getValue(final String key, final Class<T> type) {
74
71
final Object o = metadata .get (key );
75
72
76
73
if (o == null ) {
77
- throw new GeneralError ("key " + key + " does not exist in metadata" );
74
+ log .debug ("Metadata key " + key + "does not exist" );
75
+ return null ;
78
76
}
79
77
80
78
try {
81
79
return type .cast (o );
82
80
} catch (ClassCastException e ) {
83
- throw new ParseError (
84
- "wrong type for key " + key
85
- + ". Expected" + type .getSimpleName () + "but got " + o .getClass ().getSimpleName (), e );
81
+ log .debug ("Error retrieving value for key " + key , e );
82
+ return null ;
86
83
}
87
84
}
88
85
0 commit comments