From d7f8b9da39f268a8004dd3702c3a209237eb58f0 Mon Sep 17 00:00:00 2001 From: Damian G Date: Tue, 2 Jan 2024 18:33:26 -0600 Subject: [PATCH] feat: Add default name for namespace objects. Thanks pixel. --- .../team/unnamed/commandflow/Namespace.java | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/team/unnamed/commandflow/Namespace.java b/api/src/main/java/team/unnamed/commandflow/Namespace.java index cc0221c9..a8908315 100644 --- a/api/src/main/java/team/unnamed/commandflow/Namespace.java +++ b/api/src/main/java/team/unnamed/commandflow/Namespace.java @@ -2,28 +2,52 @@ public interface Namespace { + String DEFAULT_NAMESPACE_NAME = "__"; + /** * Gets an injected object from the backing Map * * @param clazz The class type of the Object to get - * @param name The name of the Object to get - * @param The type of the Object to get - * + * @param name The name of the Object to get + * @param The type of the Object to get * @return A nullable instance of T contained in the backing map with the specified name */ T getObject(Class clazz, String name); + /** + * Gets an injected object from the backing Map, with the default namespace name. + * + * @param clazz The class type of the Object to get + * @param The type of the Object to get + * @return A nullable instance of T contained in the backing map with the default namespace name + */ + default T getObject(Class clazz) { + return getObject(clazz, DEFAULT_NAMESPACE_NAME); + } + /** * Sets an Object of Type T with a specified name into the backing Map - * If an object with the same name and type is already on the map, it will be override + * If an object with the same name and type is already on the map, it will be overridden * - * @param clazz The class type of the Object to set - * @param name The name of the object to set + * @param clazz The class type of the Object to set + * @param name The name of the object to set * @param object The Object to set into the backing map - * @param The Type of the object to set + * @param The Type of the object to set */ void setObject(Class clazz, String name, T object); + /** + * Sets an Object of Type T with the default name into the backing Map + * If an object with the same type and without a specified name is already on the map, it will be overridden + * + * @param clazz The class type of the Object to set + * @param object The Object to set into the backing map + * @param The Type of the object to set + */ + default void setObject(Class clazz, T object) { + setObject(clazz, DEFAULT_NAMESPACE_NAME, object); + } + static Namespace create() { return new NamespaceImpl(); }