Class Undepender

java.lang.Object
de.tomatengames.util.Undepender

@Deprecated public class Undepender extends Object
Deprecated.
Since TomatenUtil 1.9. Use Injector instead.
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 Details

    • set

      @Deprecated public static void set(String key, Object value)
      Deprecated.
      Since TomatenUtil 1.9. Use Injector instead.
      Associates the specified value with the key.
      Parameters:
      key - The key. Not null.
      value - The value. If null, no value will be associated to the key.
    • get

      @Deprecated public static <T> T get(String key)
      Deprecated.
      Since TomatenUtil 1.9. Use Injector instead.
      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. Not null.
      Returns:
      The value associated with the key. If no such value exists, null is returned. The return value is auto-casted to the requested type.