diff --git a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java index 9b7b18b64..918737e42 100644 --- a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java +++ b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java @@ -28,7 +28,7 @@ import java.util.Map; * * @param extends IBindable and defines what interfaces this dependency handler can deal with. * @author James Seibel - * @version 2022-7-16 + * @version 2022-7-18 */ public class DependencyInjector { @@ -60,10 +60,10 @@ public class DependencyInjector * * @param dependencyInterface The interface (or parent class) the implementation object should implement. * @param dependencyImplementation An object that implements the dependencyInterface interface. - * @throws IllegalStateException if the implementation object doesn't implement - * the interface or the interface has already been bound. + * @throws IllegalStateException if the interface has already been bound and {@link DependencyInjector#allowDuplicateBindings} is false + * @throws IllegalArgumentException if the implementation object doesn't implement the interface */ - public void bind(Class dependencyInterface, BindableType dependencyImplementation) throws IllegalStateException + public void bind(Class dependencyInterface, BindableType dependencyImplementation) throws IllegalStateException, IllegalArgumentException { // duplicate check if requested if (dependencies.containsKey(dependencyInterface) && !this.allowDuplicateBindings) @@ -80,11 +80,11 @@ public class DependencyInjector // display any errors if (!implementsInterface) { - throw new IllegalStateException("The dependency [" + dependencyImplementation.getClass().getSimpleName() + "] doesn't implement or extend: [" + dependencyInterface.getSimpleName() + "]."); + throw new IllegalArgumentException("The dependency [" + dependencyImplementation.getClass().getSimpleName() + "] doesn't implement or extend: [" + dependencyInterface.getSimpleName() + "]."); } if (!implementsBindable) { - throw new IllegalStateException("The dependency [" + dependencyImplementation.getClass().getSimpleName() + "] doesn't implement the interface: [" + IBindable.class.getSimpleName() + "]."); + throw new IllegalArgumentException("The dependency [" + dependencyImplementation.getClass().getSimpleName() + "] doesn't implement the interface: [" + IBindable.class.getSimpleName() + "]."); } @@ -147,7 +147,7 @@ public class DependencyInjector * @see #get(Class, boolean) */ @SuppressWarnings("unchecked") - public T get(Class interfaceClass) throws ClassCastException + public T get(Class interfaceClass) throws ClassCastException { return (T) getInternalLogic(interfaceClass, false).get(0); } @@ -163,7 +163,7 @@ public class DependencyInjector * @throws ClassCastException If the dependency isn't able to be cast to type T. * (this shouldn't normally happen, unless the bound object changed somehow) */ - public ArrayList getAll(Class interfaceClass) throws ClassCastException + public ArrayList getAll(Class interfaceClass) throws ClassCastException { return getInternalLogic(interfaceClass, false); } @@ -175,7 +175,7 @@ public class DependencyInjector * If the handler's {@link #allowDuplicateBindings} is true this returns the first bound dependency. * * @param class of the dependency - * (inferred from the objectClass parameter) + * (inferred from the interfaceClass parameter) * @param interfaceClass Interface of the dependency * @param allowIncompleteDependencies If true this method will also return dependencies that haven't completed their delayed setup. * @return the dependency of type T @@ -183,7 +183,7 @@ public class DependencyInjector * (this shouldn't normally happen, unless the bound object changed somehow) */ @SuppressWarnings("unchecked") - public T get(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException + public T get(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException { return (T) getInternalLogic(interfaceClass, allowIncompleteDependencies).get(0); } @@ -193,7 +193,7 @@ public class DependencyInjector * if no dependencies have been bound the list will contain null. */ @SuppressWarnings("unchecked") - private ArrayList getInternalLogic(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException + private ArrayList getInternalLogic(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException { ArrayList dependencyList = dependencies.get(interfaceClass); if (dependencyList != null && dependencyList.size() != 0) @@ -224,7 +224,7 @@ public class DependencyInjector /** Runs delayed setup for any dependencies that require it. */ public void runDelayedSetup() { - for (Class interfaceKey : dependencies.keySet()) + for (Class interfaceKey : dependencies.keySet()) { IBindable concreteObject = get(interfaceKey, true); if (!concreteObject.getDelayedSetupComplete()) diff --git a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DhApiEventInjector.java b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DhApiEventInjector.java index 6978c026e..71e2d5150 100644 --- a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DhApiEventInjector.java +++ b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DhApiEventInjector.java @@ -32,7 +32,7 @@ import java.util.ArrayList; * * @author James Seibel * @author Leetom - * @version 2022-7-16 + * @version 2022-7-18 */ public class DhApiEventInjector extends DependencyInjector { @@ -48,24 +48,24 @@ public class DhApiEventInjector extends DependencyInjector /** * Unlinks the given event handler, preventing the handler from being called in the future. * - * @param dependencyInterface The interface the event handler implements. + * @throws IllegalArgumentException if the implementation object doesn't implement the interface * @return true if the handler was unbound, false if the handler wasn't bound. */ - public boolean unbind(Class dependencyInterface, Class dependencyClassToRemove) + public boolean unbind(Class dependencyInterface, Class dependencyClassToRemove) throws IllegalArgumentException { // make sure the given dependency implements the necessary interfaces boolean implementsInterface = checkIfClassImplements(dependencyClassToRemove, dependencyInterface) - || checkIfClassExtends(dependencyClassToRemove, dependencyInterface); + || checkIfClassExtends(dependencyClassToRemove, dependencyInterface); boolean implementsBindable = checkIfClassImplements(dependencyClassToRemove, this.bindableInterface); // display any errors if (!implementsInterface) { - throw new IllegalStateException("The event handler [" + dependencyClassToRemove.getSimpleName() + "] doesn't implement or extend: [" + dependencyInterface.getSimpleName() + "]."); + throw new IllegalArgumentException("The event handler [" + dependencyClassToRemove.getSimpleName() + "] doesn't implement or extend: [" + dependencyInterface.getSimpleName() + "]."); } if (!implementsBindable) { - throw new IllegalStateException("The event handler [" + dependencyClassToRemove.getSimpleName() + "] doesn't implement the interface: [" + IBindable.class.getSimpleName() + "]."); + throw new IllegalArgumentException("The event handler [" + dependencyClassToRemove.getSimpleName() + "] doesn't implement the interface: [" + IBindable.class.getSimpleName() + "]."); } diff --git a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/ModAccessorInjector.java b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/ModAccessorInjector.java index 04d63fe5f..95d001927 100644 --- a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/ModAccessorInjector.java +++ b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/ModAccessorInjector.java @@ -34,7 +34,7 @@ import java.lang.invoke.MethodHandles; * * @author James Seibel * @author Leetom - * @version 2022-7-16 + * @version 2022-7-18 */ public class ModAccessorInjector extends DependencyInjector { @@ -53,8 +53,9 @@ public class ModAccessorInjector extends DependencyInjector * Go to {@link DependencyInjector#bind(Class, IBindable)} DependencyHandler.bind()} * for this method's javadocs. */ + @Override public void bind(Class interfaceClass, IModAccessor modAccessor) - throws IllegalStateException + throws IllegalStateException, IllegalArgumentException { super.bind(interfaceClass, modAccessor); LOGGER.info("Registered mod compatibility accessor for: [" + modAccessor.getModName() + "]."); diff --git a/src/main/java/com/seibel/lod/core/util/SingletonHandler.java b/src/main/java/com/seibel/lod/core/util/SingletonHandler.java deleted file mode 100644 index e69de29bb..000000000