Class Undepender
java.lang.Object
de.tomatengames.util.Undepender
Deprecated.
Undepender provides a shared storage that can be accessed by all classes running in the current JVM
using the
set(String, Object) and get(String) methods.
The storage operations are thread-safe.
The storage can be used to communicate between subsystems without the need that these subsystems have been built against each other.
For example, assume two subsystems A.jar and B.jar where A.jar is a soft-dependency of B.jar.
A.jar defines an operation A.a() that should be called by B.jar only if A.jar is present.
Traditionally, A.jar would be required in the class-path of B.jar,
making it a mandatory compile and runtime dependency.
With Undepender, A.jar could set a function into the shared storage to provide the operation.
Undepender.set("A.a", (Function<String, String>) param -> { /* operation */ });
Then B.jar can get and call "A.a" if it exists. It does not exist if A.jar is not installed.
Function<String, String> a = Undepender.get("A.a");
if (a != null) {
a.apply(param);
}
- Since:
- 1.6
-
Method Summary
-
Method Details
-
set
Deprecated.Since TomatenUtil 1.9. UseInjectorinstead.Associates the specified value with the key.- Parameters:
key- The key. Notnull.value- The value. Ifnull, no value will be associated to the key.
-
get
Deprecated.Since TomatenUtil 1.9. UseInjectorinstead.Returns the value associated with the specified key.Note that the return value is auto-casted to the requested type. This is an unchecked cast. It must be ensured that the requested type is compatible with the value.
- Type Parameters:
T- The requested type of the value. The return value is auto-casted to this type.- Parameters:
key- The key. Notnull.- Returns:
- The value associated with the key. If no such value exists,
nullis returned. The return value is auto-casted to the requested type.
-
Injectorinstead.