-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(context): Improve null handling and Javadoc
Improve Javadoc about usage and thread safety Improve null handling using defensive checks, and document parameters and results Improve tests to cover all context implementations
- Loading branch information
1 parent
37acd7b
commit c4da3f7
Showing
17 changed files
with
305 additions
and
141 deletions.
There are no files selected for viewing
This file contains 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
23 changes: 18 additions & 5 deletions
23
components/context/src/main/java/datadog/context/ContextBinder.java
This file contains 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 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 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 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
13 changes: 12 additions & 1 deletion
13
components/context/src/main/java/datadog/context/EmptyContext.java
This file contains 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 |
---|---|---|
@@ -1,16 +1,27 @@ | ||
package datadog.context; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
/** {@link Context} containing no values. */ | ||
@ParametersAreNonnullByDefault | ||
final class EmptyContext implements Context { | ||
static final Context INSTANCE = new EmptyContext(); | ||
|
||
@Override | ||
@Nullable | ||
public <T> T get(ContextKey<T> key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> Context with(ContextKey<T> key, T value) { | ||
public <T> Context with(ContextKey<T> key, @Nullable T value) { | ||
requireNonNull(key, "Context key cannot be null"); | ||
if (value == null) { | ||
return this; | ||
} | ||
return new SingletonContext(key.index, value); | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
components/context/src/main/java/datadog/context/ImplicitContextKeyed.java
This file contains 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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package datadog.context; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
/** {@link Context} value that has its own implicit {@link ContextKey}. */ | ||
@ParametersAreNonnullByDefault | ||
public interface ImplicitContextKeyed { | ||
|
||
/** | ||
* Creates a new context with this value under its chosen key. | ||
* | ||
* @return New context with the implicitly keyed value. | ||
* @param context the context to copy the original values from. | ||
* @return the new context with the implicitly keyed value. | ||
* @see Context#with(ImplicitContextKeyed) | ||
*/ | ||
Context storeInto(Context context); | ||
} |
This file contains 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
Oops, something went wrong.