mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
Merge pull request #504 from Catnies/dev-contextholder
contextholder添加get方法
This commit is contained in:
@@ -63,6 +63,11 @@ public class ContextHolder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T getOrNull(ContextKey<T> parameter) {
|
||||||
|
return (T) Optional.ofNullable(this.params.get(parameter)).map(Supplier::get).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T getOrThrow(ContextKey<T> parameter) {
|
public <T> T getOrThrow(ContextKey<T> parameter) {
|
||||||
Supplier<T> object = (Supplier<T>) this.params.get(parameter);
|
Supplier<T> object = (Supplier<T>) this.params.get(parameter);
|
||||||
|
|||||||
Reference in New Issue
Block a user