|
6 | 6 | import com.azure.core.annotation.Immutable; |
7 | 7 | import com.azure.core.util.logging.ClientLogger; |
8 | 8 |
|
| 9 | +import java.util.Collections; |
9 | 10 | import java.util.HashMap; |
10 | 11 | import java.util.Map; |
11 | 12 | import java.util.Objects; |
|
21 | 22 | */ |
22 | 23 | @Immutable |
23 | 24 | public class Context { |
24 | | - private final ClientLogger logger = new ClientLogger(Context.class); |
| 25 | + private static final ClientLogger LOGGER = new ClientLogger(Context.class); |
25 | 26 |
|
26 | 27 | // All fields must be immutable. |
27 | 28 | // |
28 | 29 | /** |
29 | 30 | * Signifies that no data needs to be passed to the pipeline. |
30 | 31 | */ |
31 | | - public static final Context NONE = new Context(null, null, null); |
| 32 | + public static final Context NONE = new Context(null, null, null) { |
| 33 | + @Override |
| 34 | + public Optional<Object> getData(Object key) { |
| 35 | + if (key == null) { |
| 36 | + throw LOGGER.logExceptionAsError(new IllegalArgumentException("key cannot be null")); |
| 37 | + } |
| 38 | + |
| 39 | + return Optional.empty(); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public Map<Object, Object> getValues() { |
| 44 | + return Collections.emptyMap(); |
| 45 | + } |
| 46 | + }; |
32 | 47 |
|
33 | 48 | private final Context parent; |
34 | 49 | private final Object key; |
@@ -72,7 +87,7 @@ private Context(Context parent, Object key, Object value) { |
72 | 87 | */ |
73 | 88 | public Context addData(Object key, Object value) { |
74 | 89 | if (key == null) { |
75 | | - throw logger.logExceptionAsError(new IllegalArgumentException("key cannot be null")); |
| 90 | + throw LOGGER.logExceptionAsError(new IllegalArgumentException("key cannot be null")); |
76 | 91 | } |
77 | 92 | return new Context(this, key, value); |
78 | 93 | } |
@@ -119,7 +134,7 @@ public static Context of(Map<Object, Object> keyValues) { |
119 | 134 | */ |
120 | 135 | public Optional<Object> getData(Object key) { |
121 | 136 | if (key == null) { |
122 | | - throw logger.logExceptionAsError(new IllegalArgumentException("key cannot be null")); |
| 137 | + throw LOGGER.logExceptionAsError(new IllegalArgumentException("key cannot be null")); |
123 | 138 | } |
124 | 139 | for (Context c = this; c != null; c = c.parent) { |
125 | 140 | if (key.equals(c.key)) { |
|
0 commit comments