diff --git a/pom.xml b/pom.xml
index 46299a8..ffd71b2 100755
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
lm-lib
de.extio
lm-lib
- 1.5.2
+ 1.5.3
21
diff --git a/src/main/java/de/extio/lmlib/agent/AgentContext.java b/src/main/java/de/extio/lmlib/agent/AgentContext.java
index 3aa8392..c4982bb 100755
--- a/src/main/java/de/extio/lmlib/agent/AgentContext.java
+++ b/src/main/java/de/extio/lmlib/agent/AgentContext.java
@@ -86,6 +86,27 @@ public final class AgentContext {
this.context.put(key, List.copyOf(value));
}
+ public T getValue(final String key, final Class type) {
+ final var values = this.context.get(key);
+ if (values == null || values.isEmpty()) {
+ return null;
+ }
+ final var firstValue = values.getFirst();
+ if (type.isInstance(firstValue)) {
+ return type.cast(firstValue);
+ }
+ throw new IllegalArgumentException("Value for key '" + key + "' is not of type " + type.getName());
+ }
+
+ public void setValue(final String key, final T value) {
+ if (value == null) {
+ this.context.remove(key);
+ }
+ else {
+ this.context.put(key, List.of(value));
+ }
+ }
+
public Map> getContext() {
return this.context;
}