diff --git a/src/main/java/conflux/Ctx.java b/src/main/java/conflux/Ctx.java index cbbb441..eba3769 100644 --- a/src/main/java/conflux/Ctx.java +++ b/src/main/java/conflux/Ctx.java @@ -34,169 +34,133 @@ */ package conflux; -import java.lang.ref.WeakReference; -import java.util.List; import java.util.Map; -import java.util.Objects; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; /** - * A globally accessible, type-safe context for sharing data between independent - * parts of an application. Supports listeners that are notified whenever a - * registered key's value changes. - * - * This implementation guarantees: - *
- * Key<Integer> COUNT = Key.of("count", Integer.class);
- * Ctx.INSTANCE.put(COUNT, 42);
- * int v = Ctx.INSTANCE.get(COUNT);
- *
+ * This enum serves as both:
+ * - * The {@link conflux.Ctx} class acts as a central, generic context storage - * supporting key-based put/get operations. Each {@link conflux.Key} defines a - * unique, strongly typed entry in the context, ensuring type consistency and - * preventing misuse. {@link conflux.Listener} interfaces allow clients to - * observe value changes for specific keys. Listeners are held with weak - * references to avoid memory leaks. - *
- * Typical usage involves defining {@link conflux.Key} instances with explicit - * types, storing values through {@code Ctx.INSTANCE.put()}, and retrieving them - * with {@code Ctx.INSTANCE.get()}. Listeners can be attached via - * {@code Ctx.INSTANCE.addListener()} to react to context changes in a decoupled - * and thread-safe manner. Values and listeners can be removed individually or - * the entire context can be cleared. - *
- * Best Practices: + * + * The {@link conflux.Ctx} enum serves as a central, generic context storage, + * supporting key-based put/get operations. Each {@link conflux.Key} instance + * defines a unique, strongly typed entry in the context, ensuring type + * consistency and preventing misuse. + * + * The {@link conflux.Listener} interface allows clients to observe value + * changes for specific keys. Listeners are weakly referenced to prevent memory + * leaks. + * + * Typical usage: + *