diff --git a/api/src/main/java/com/seibel/lod/api/items/interfaces/override/IDhApiOverrideable.java b/api/src/main/java/com/seibel/lod/api/items/interfaces/override/IDhApiOverrideable.java
index c05a03502..2aba1483a 100644
--- a/api/src/main/java/com/seibel/lod/api/items/interfaces/override/IDhApiOverrideable.java
+++ b/api/src/main/java/com/seibel/lod/api/items/interfaces/override/IDhApiOverrideable.java
@@ -1,5 +1,6 @@
package com.seibel.lod.api.items.interfaces.override;
+import com.seibel.lod.core.api.external.coreInterfaces.ICoreDhApiOverrideable;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
import com.seibel.lod.core.handlers.dependencyInjection.IBindable;
@@ -7,14 +8,15 @@ import com.seibel.lod.core.handlers.dependencyInjection.IBindable;
* Implemented by all DhApi objects that can be overridden.
*
* @author James Seibel
- * @version 2022-7-18
+ * @version 2022-9-5
*/
-public interface IDhApiOverrideable extends IBindable
+public interface IDhApiOverrideable extends ICoreDhApiOverrideable, IBindable
{
/**
* Returns when this Override should be used.
* For most developers this can be left at the default.
*/
- default EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.PRIMARY; }
+ @Override
+ default EDhApiOverridePriority getPriority() { return EDhApiOverridePriority.PRIMARY; }
}
diff --git a/core/src/main/java/com/seibel/lod/core/api/external/coreInterfaces/ICoreDhApiOverrideable.java b/core/src/main/java/com/seibel/lod/core/api/external/coreInterfaces/ICoreDhApiOverrideable.java
new file mode 100644
index 000000000..de3752681
--- /dev/null
+++ b/core/src/main/java/com/seibel/lod/core/api/external/coreInterfaces/ICoreDhApiOverrideable.java
@@ -0,0 +1,20 @@
+package com.seibel.lod.core.api.external.coreInterfaces;
+
+import com.seibel.lod.core.handlers.dependencyInjection.IBindable;
+import com.seibel.lod.core.handlers.dependencyInjection.OverrideInjector;
+
+/**
+ * Implemented by all DhApi objects that can be overridden.
+ *
+ * @author James Seibel
+ * @version 2022-9-5
+ */
+public interface ICoreDhApiOverrideable extends IBindable
+{
+ /**
+ * Returns when this Override should be used.
+ * For most developers this can be left at the default.
+ */
+ default int getPriority() { return OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY; }
+
+}
diff --git a/core/src/main/java/com/seibel/lod/core/api/external/items/enums/override/DhApiOverrideEnumAssembly.java b/core/src/main/java/com/seibel/lod/core/api/external/items/enums/override/DhApiOverrideEnumAssembly.java
deleted file mode 100644
index d6763a75d..000000000
--- a/core/src/main/java/com/seibel/lod/core/api/external/items/enums/override/DhApiOverrideEnumAssembly.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod (formerly the LOD Mod),
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020-2022 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.lod.core.api.external.items.enums.override;
-
-/**
- * Assembly classes are used to reference the package they are in.
- *
- * @author James Seibel
- * @version 2022-7-16
- */
-public class DhApiOverrideEnumAssembly
-{
-
-}
diff --git a/core/src/main/java/com/seibel/lod/core/api/external/items/enums/override/EDhApiOverridePriority.java b/core/src/main/java/com/seibel/lod/core/api/external/items/enums/override/EDhApiOverridePriority.java
deleted file mode 100644
index 12af4da0b..000000000
--- a/core/src/main/java/com/seibel/lod/core/api/external/items/enums/override/EDhApiOverridePriority.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.seibel.lod.core.api.external.items.enums.override;
-
-/**
- * PRIMARY,
- * SECONDARY,
- * CORE,
- *
- * @author James Seibel
- * @version 2022-7-18
- */
-public enum EDhApiOverridePriority
-{
- /**
- * The default Override priority and the one generally suggested
- * for developers who want to create an override.
- * The highest priority.
- */
- PRIMARY,
-
- /**
- * Overrides with this priority are only used if there isn't
- * an override with PRIMARY priority.
- * Could be used to allow creating overrides that other mod developers
- * could override.
- */
- SECONDARY,
-
- /**
- * Only Distant Horizons classes should use the CORE priority,
- * attempting to set an override with CORE priority will result in an error.
- * This is the lowest priority and will be overridden by all other priorities.
- */
- CORE,
-}
diff --git a/core/src/main/java/com/seibel/lod/core/enums/override/CoreOverrideEnumAssembly.java b/core/src/main/java/com/seibel/lod/core/enums/override/CoreOverrideEnumAssembly.java
deleted file mode 100644
index 4122126ee..000000000
--- a/core/src/main/java/com/seibel/lod/core/enums/override/CoreOverrideEnumAssembly.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod (formerly the LOD Mod),
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020-2022 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.lod.core.enums.override;
-
-/**
- * Assembly classes are used to reference the package they are in.
- *
- * @author James Seibel
- * @version 2022-7-18
- */
-public class CoreOverrideEnumAssembly
-{
-
-}
diff --git a/core/src/main/java/com/seibel/lod/core/enums/override/EOverridePriority.java b/core/src/main/java/com/seibel/lod/core/enums/override/EOverridePriority.java
deleted file mode 100644
index 8f363b55d..000000000
--- a/core/src/main/java/com/seibel/lod/core/enums/override/EOverridePriority.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.seibel.lod.core.enums.override;
-
-/**
- * PRIMARY,
- * SECONDARY,
- * CORE,
- *
- * @author James Seibel
- * @version 2022-7-18
- */
-public enum EOverridePriority
-{
- // TODO rename this to EApiOverridePriority,
- // this will require a option in the enum checker to have different prefixes,
- // since the DhApi object is named DhApiOverride...
-
-
- /**
- * The default Override priority and the one generally suggested
- * for developers who want to create an override.
- * The highest priority.
- */
- PRIMARY,
-
- /**
- * Overrides with this priority are only used if there isn't
- * an override with PRIMARY priority.
- * Could be used to allow creating overrides that other mod developers
- * could override.
- */
- SECONDARY,
-
- /**
- * Only Distant Horizons classes should use the CORE priority,
- * attempting to set an override with CORE priority will result in an error.
- * This is the lowest priority and will be overridden by all other priorities.
- */
- CORE,
-}
diff --git a/core/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/OverrideInjector.java b/core/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/OverrideInjector.java
index 8ec7a73fc..336291940 100644
--- a/core/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/OverrideInjector.java
+++ b/core/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/OverrideInjector.java
@@ -19,28 +19,38 @@
package com.seibel.lod.core.handlers.dependencyInjection;
-import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
-import com.seibel.lod.api.items.interfaces.override.IDhApiOverrideable;
-import com.seibel.lod.core.api.implementation.objects.GenericEnumConverter;
-import com.seibel.lod.core.enums.override.EOverridePriority;
+import com.seibel.lod.core.api.external.coreInterfaces.ICoreDhApiOverrideable;
import com.seibel.lod.core.util.StringUtil;
+import java.util.ArrayList;
+import java.util.HashMap;
+
/**
* This class takes care of dependency injection for overridable objects.
* This is done so other mods can override our methods to improve features down the line.
*
* @author James Seibel
- * @version 2022-8-15
+ * @version 2022-9-5
*/
-public class OverrideInjector
+public class OverrideInjector
{
- public static final OverrideInjector INSTANCE = new OverrideInjector<>();
+ public static final OverrideInjector INSTANCE = new OverrideInjector();
+
+ private final HashMap, OverridePriorityListContainer> overrideContainerByInterface = new HashMap<>();
- private final DependencyInjector primaryInjector = new DependencyInjector<>(IDhApiOverrideable.class, false);
- private final DependencyInjector secondaryInjector = new DependencyInjector<>(IDhApiOverrideable.class, false);
- private final DependencyInjector coreInjector = new DependencyInjector<>(IDhApiOverrideable.class, false);
- private static final GenericEnumConverter ENUM_CONVERTER = new GenericEnumConverter<>(EOverridePriority.class, EDhApiOverridePriority.class);
+ /**
+ * All core overrides should have this priority.
+ * Should be lower than MIN_OVERRIDE_PRIORITY.
+ */
+ public static final int CORE_PRIORITY = -1;
+ /**
+ * The lowest priority non-core overrides can have.
+ * Should be higher than CORE_PRIORITY.
+ */
+ public static final int MIN_NON_CORE_OVERRIDE_PRIORITY = 0;
+ /** The priority given to overrides that don't explicitly define a priority. */
+ public static final int DEFAULT_NON_CORE_OVERRIDE_PRIORITY = 10;
/**
* This is used to determine if an override is part of Distant Horizons'
@@ -60,41 +70,57 @@ public class OverrideInjector
}
/** This constructor should only be used for testing different corePackagePaths. */
- public OverrideInjector(String newCorePackagePath)
- {
- this.corePackagePath = newCorePackagePath;
- }
+ public OverrideInjector(String newCorePackagePath) { this.corePackagePath = newCorePackagePath; }
/**
* See {@link DependencyInjector#bind(Class, IBindable) bind(Class, IBindable)} for full documentation.
*
- * @throws IllegalArgumentException if a non-Distant Horizons Override with the priority CORE is passed in
+ * @throws IllegalArgumentException if a non-Distant Horizons Override with the priority CORE is passed in or a invalid priority value.
+ * @throws IllegalStateException if another override with the given priority already has been bound.
* @see DependencyInjector#bind(Class, IBindable)
*/
- public void bind(Class extends BindableType> dependencyInterface, IDhApiOverrideable dependencyImplementation) throws IllegalStateException, IllegalArgumentException
+ public void bind(Class extends ICoreDhApiOverrideable> dependencyInterface, ICoreDhApiOverrideable dependencyImplementation) throws IllegalStateException, IllegalArgumentException
{
- if (getCorePriorityEnum(dependencyImplementation) == EOverridePriority.PRIMARY)
+ // make sure a override container exists
+ OverridePriorityListContainer overrideContainer = this.overrideContainerByInterface.get(dependencyInterface);
+ if (overrideContainer == null)
{
- primaryInjector.bind(dependencyInterface, dependencyImplementation);
+ overrideContainer = new OverridePriorityListContainer();
+ this.overrideContainerByInterface.put(dependencyInterface, overrideContainer);
}
- else if (getCorePriorityEnum(dependencyImplementation) == EOverridePriority.SECONDARY)
- {
- secondaryInjector.bind(dependencyInterface, dependencyImplementation);
- }
- else
+
+
+ // validate the new override //
+
+ // check if this override is a core override
+ if (dependencyImplementation.getPriority() == CORE_PRIORITY)
{
+ // this claims to be a core override, is that true?
String packageName = dependencyImplementation.getClass().getPackage().getName();
- if (packageName.startsWith(this.corePackagePath))
+ if (!packageName.startsWith(this.corePackagePath))
{
- coreInjector.bind(dependencyInterface, dependencyImplementation);
- }
- else
- {
- throw new IllegalArgumentException("Only Distant Horizons internal objects can use the Override Priority [" + EOverridePriority.CORE + "]. Please use [" + EOverridePriority.PRIMARY + "] or [" + EOverridePriority.SECONDARY + "] instead.");
+ throw new IllegalArgumentException("Only Distant Horizons internal objects can use the Override Priority [" + CORE_PRIORITY + "]. Please use a higher number.");
}
}
+
+ // make sure the override has a valid priority
+ if (dependencyImplementation.getPriority() < MIN_NON_CORE_OVERRIDE_PRIORITY)
+ {
+ throw new IllegalArgumentException("Invalid priority value [" + dependencyImplementation.getPriority() + "], override priorities must be [" + MIN_NON_CORE_OVERRIDE_PRIORITY + "] or greater.");
+ }
+
+ // check if a override already exists with this priority
+ ICoreDhApiOverrideable existingOverride = overrideContainer.getOverrideWithPriority(dependencyImplementation.getPriority());
+ if (existingOverride != null)
+ {
+ throw new IllegalStateException("An override already exists with the priority [" + dependencyImplementation.getPriority() + "].");
+ }
+
+
+ // bind the override
+ overrideContainer.addOverride(dependencyImplementation);
}
/**
@@ -103,19 +129,18 @@ public class OverrideInjector
*
* @see DependencyInjector#get(Class, boolean)
*/
- public T get(Class interfaceClass) throws ClassCastException
+ public T get(Class interfaceClass) throws ClassCastException
{
- T value = primaryInjector.get(interfaceClass);
- if (value == null)
+ OverridePriorityListContainer overrideContainer = this.overrideContainerByInterface.get(interfaceClass);
+ if (overrideContainer != null)
{
- value = secondaryInjector.get(interfaceClass);
+ // TODO make sure this works and potentially fix the warning
+ return (T) overrideContainer.getOverrideWithHighestPriority();
}
- if (value == null)
+ else
{
- value = coreInjector.get(interfaceClass);
+ return null;
}
-
- return value;
}
/**
@@ -126,23 +151,18 @@ public class OverrideInjector
*
* @see DependencyInjector#get(Class, boolean)
*/
- public T get(Class interfaceClass, EOverridePriority overridePriority) throws ClassCastException
+ public T get(Class interfaceClass, int priority) throws ClassCastException
{
- T value;
- if (overridePriority == EOverridePriority.PRIMARY)
+ OverridePriorityListContainer overrideContainer = this.overrideContainerByInterface.get(interfaceClass);
+ if (overrideContainer != null)
{
- value = primaryInjector.get(interfaceClass);
- }
- else if (overridePriority == EOverridePriority.SECONDARY)
- {
- value = secondaryInjector.get(interfaceClass);
+ // TODO make sure this works and potentially fix the warning
+ return (T) overrideContainer.getOverrideWithPriority(priority);
}
else
{
- value = coreInjector.get(interfaceClass);
+ return null;
}
-
- return value;
}
@@ -150,9 +170,7 @@ public class OverrideInjector
/** Removes all bound overrides. */
public void clear()
{
- this.primaryInjector.clear();
- this.secondaryInjector.clear();
- this.coreInjector.clear();
+ this.overrideContainerByInterface.clear();
}
@@ -160,10 +178,4 @@ public class OverrideInjector
- /** Small helper method so we don't have to use DhApi enums. */
- private EOverridePriority getCorePriorityEnum(IDhApiOverrideable override)
- {
- return ENUM_CONVERTER.convertToCoreType(override.getOverrideType());
- }
-
}
diff --git a/core/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/OverridePriorityListContainer.java b/core/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/OverridePriorityListContainer.java
new file mode 100644
index 000000000..a158a500a
--- /dev/null
+++ b/core/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/OverridePriorityListContainer.java
@@ -0,0 +1,115 @@
+package com.seibel.lod.core.handlers.dependencyInjection;
+
+import com.seibel.lod.core.api.external.coreInterfaces.ICoreDhApiOverrideable;
+
+import java.util.ArrayList;
+
+/**
+ * Contains a list of overrides and their priorities.
+ *
+ * @author James Seibel
+ * @version 2022-9-5
+ */
+public class OverridePriorityListContainer implements IBindable
+{
+ /** Sorted highest priority to lowest */
+ private final ArrayList overridePairList = new ArrayList<>();
+
+
+ /** Doesn't do any validation */
+ public void addOverride(ICoreDhApiOverrideable override)
+ {
+ OverridePriorityPair priorityPair = new OverridePriorityPair(override, override.getPriority());
+ this.overridePairList.add(priorityPair);
+
+ sortList();
+ }
+
+ /** @return true if the override was removed from the list, false otherwise. */
+ public boolean removeOverride(ICoreDhApiOverrideable override)
+ {
+ if (this.overridePairList.contains(override))
+ {
+ this.overridePairList.remove(override);
+ sortList();
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ // getters //
+
+ public ICoreDhApiOverrideable getOverrideWithLowestPriority()
+ {
+ if (this.overridePairList.size() == 0)
+ {
+ return null;
+ }
+ else
+ {
+ // last item should have the highest priority
+ return this.overridePairList.get(this.overridePairList.size() - 1).override;
+ }
+ }
+ public ICoreDhApiOverrideable getOverrideWithHighestPriority()
+ {
+ if (this.overridePairList.get(0) != null)
+ {
+ return this.overridePairList.get(0).override;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ public ICoreDhApiOverrideable getCoreOverride()
+ {
+ int lastIndex = this.overridePairList.size() - 1;
+ if (this.overridePairList.get(lastIndex) != null && this.overridePairList.get(lastIndex).priority == OverrideInjector.CORE_PRIORITY)
+ {
+ return this.overridePairList.get(lastIndex).override;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ /** Returns null if no override with the given priority is found */
+ public ICoreDhApiOverrideable getOverrideWithPriority(int priority)
+ {
+ for (OverridePriorityPair pair : this.overridePairList)
+ {
+ if (pair.priority == priority)
+ {
+ return pair.override;
+ }
+ }
+
+ return null;
+ }
+
+
+ // utils //
+
+ /** sort the list so the lowest priority item is first in the list */
+ private void sortList() { this.overridePairList.sort((x,y) -> Integer.compare(x.priority, y.priority)); }
+
+
+
+ private class OverridePriorityPair
+ {
+ public final ICoreDhApiOverrideable override;
+ public int priority;
+
+ public OverridePriorityPair(ICoreDhApiOverrideable newOverride, int newPriority)
+ {
+ this.override = newOverride;
+ this.priority = newPriority;
+ }
+ }
+}
diff --git a/core/src/test/java/testItems/overrideInjection/interfaces/IOverrideTest.java b/core/src/test/java/testItems/overrideInjection/interfaces/IOverrideTest.java
index df5847564..1221b2966 100644
--- a/core/src/test/java/testItems/overrideInjection/interfaces/IOverrideTest.java
+++ b/core/src/test/java/testItems/overrideInjection/interfaces/IOverrideTest.java
@@ -1,14 +1,14 @@
package testItems.overrideInjection.interfaces;
-import com.seibel.lod.api.items.interfaces.override.IDhApiOverrideable;
+import com.seibel.lod.core.api.external.coreInterfaces.ICoreDhApiOverrideable;
/**
* Dummy override test interface for dependency unit tests.
*
* @author James Seibel
- * @version 2022-7-19
+ * @version 2022-9-5
*/
-public interface IOverrideTest extends IDhApiOverrideable
+public interface IOverrideTest extends ICoreDhApiOverrideable
{
public int getValue();
diff --git a/core/src/test/java/testItems/overrideInjection/objects/OverrideTestCore.java b/core/src/test/java/testItems/overrideInjection/objects/OverrideTestCore.java
index ae0d02714..16a4ae9dd 100644
--- a/core/src/test/java/testItems/overrideInjection/objects/OverrideTestCore.java
+++ b/core/src/test/java/testItems/overrideInjection/objects/OverrideTestCore.java
@@ -1,13 +1,14 @@
package testItems.overrideInjection.objects;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
+import com.seibel.lod.core.handlers.dependencyInjection.OverrideInjector;
import testItems.overrideInjection.interfaces.IOverrideTest;
/**
* Dummy test implementation object for dependency injection unit tests.
*
* @author James Seibel
- * @version 2022-7-19
+ * @version 2022-9-5
*/
public class OverrideTestCore implements IOverrideTest
{
@@ -18,6 +19,6 @@ public class OverrideTestCore implements IOverrideTest
public int getValue() { return VALUE; }
@Override
- public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.CORE; }
+ public int getPriority() { return OverrideInjector.CORE_PRIORITY; }
}
diff --git a/core/src/test/java/testItems/overrideInjection/objects/OverrideTestPrimary.java b/core/src/test/java/testItems/overrideInjection/objects/OverrideTestPrimary.java
index a96964f03..a2e1a9fe6 100644
--- a/core/src/test/java/testItems/overrideInjection/objects/OverrideTestPrimary.java
+++ b/core/src/test/java/testItems/overrideInjection/objects/OverrideTestPrimary.java
@@ -1,13 +1,14 @@
package testItems.overrideInjection.objects;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
+import com.seibel.lod.core.handlers.dependencyInjection.OverrideInjector;
import testItems.overrideInjection.interfaces.IOverrideTest;
/**
* Dummy test implementation object for dependency injection unit tests.
*
* @author James Seibel
- * @version 2022-7-19
+ * @version 2022-9-5
*/
public class OverrideTestPrimary implements IOverrideTest
{
@@ -18,6 +19,6 @@ public class OverrideTestPrimary implements IOverrideTest
public int getValue() { return VALUE; }
@Override
- public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.PRIMARY; }
+ public int getPriority() { return OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY; }
}
diff --git a/core/src/test/java/testItems/overrideInjection/objects/OverrideTestSecondary.java b/core/src/test/java/testItems/overrideInjection/objects/OverrideTestSecondary.java
deleted file mode 100644
index 75a89fdcb..000000000
--- a/core/src/test/java/testItems/overrideInjection/objects/OverrideTestSecondary.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package testItems.overrideInjection.objects;
-
-import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
-import testItems.overrideInjection.interfaces.IOverrideTest;
-
-/**
- * Dummy test implementation object for dependency injection unit tests.
- *
- * @author James Seibel
- * @version 2022-7-19
- */
-public class OverrideTestSecondary implements IOverrideTest
-{
- public static int VALUE = 2;
-
-
- @Override
- public int getValue() { return VALUE; }
-
- @Override
- public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.SECONDARY; }
-
-}
diff --git a/core/src/test/java/testItems/worldGeneratorInjection/objects/WorldGeneratorTestSecondary.java b/core/src/test/java/testItems/worldGeneratorInjection/objects/WorldGeneratorTestSecondary.java
deleted file mode 100644
index 2722beb47..000000000
--- a/core/src/test/java/testItems/worldGeneratorInjection/objects/WorldGeneratorTestSecondary.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package testItems.worldGeneratorInjection.objects;
-
-import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
-import com.seibel.lod.core.api.external.items.enums.worldGeneration.EDhApiWorldGenThreadMode;
-import com.seibel.lod.core.api.external.items.enums.worldGeneration.EDhApiWorldGenerationStep;
-import com.seibel.lod.api.items.interfaces.override.IDhApiWorldGenerator;
-import com.seibel.lod.api.items.interfaces.world.IDhApiChunkWrapper;
-import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
-
-/**
- * Dummy test implementation object for world generator injection unit tests.
- *
- * @author James Seibel
- * @version 2022-7-26
- */
-public class WorldGeneratorTestSecondary implements IDhApiWorldGenerator
-{
- public static EDhApiWorldGenThreadMode THREAD_MODE = EDhApiWorldGenThreadMode.SINGLE_THREADED;
-
-
- //==============//
- // IOverridable //
- //==============//
-
- @Override
- public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.SECONDARY; }
-
-
-
- //======================//
- // IDhApiWorldGenerator //
- //======================//
-
- @Override
- public EDhApiWorldGenThreadMode getThreadingMode() { return THREAD_MODE; }
-
- @Override
- public IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate)
- {
- // not necessary for testing
- return null;
- }
-}
diff --git a/core/src/test/java/tests/DependencyInjectorTest.java b/core/src/test/java/tests/DependencyInjectorTest.java
index 4e671c056..4f591ed4e 100644
--- a/core/src/test/java/tests/DependencyInjectorTest.java
+++ b/core/src/test/java/tests/DependencyInjectorTest.java
@@ -4,7 +4,6 @@ import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePrior
import com.seibel.lod.api.items.interfaces.override.IDhApiOverrideable;
import com.seibel.lod.api.items.interfaces.override.IDhApiWorldGenerator;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
-import com.seibel.lod.core.enums.override.EOverridePriority;
import com.seibel.lod.core.handlers.dependencyInjection.*;
import org.junit.Assert;
@@ -13,7 +12,6 @@ import testItems.eventInjection.objects.DhTestEvent;
import testItems.eventInjection.objects.DhTestEventAlt;
import testItems.overrideInjection.objects.OverrideTestCore;
import testItems.overrideInjection.objects.OverrideTestPrimary;
-import testItems.overrideInjection.objects.OverrideTestSecondary;
import testItems.singletonInjection.interfaces.ISingletonTestOne;
import testItems.singletonInjection.interfaces.ISingletonTestTwo;
import testItems.singletonInjection.objects.ConcreteSingletonTestBoth;
@@ -29,7 +27,7 @@ import java.util.ArrayList;
/**
* @author James Seibel
- * @version 2022-7-27
+ * @version 2022-9-5
*/
public class DependencyInjectorTest
{
@@ -163,8 +161,8 @@ public class DependencyInjectorTest
@Test
public void testOverrideInjection()
{
- OverrideInjector TEST_INJECTOR = new OverrideInjector<>(OverrideTestAssembly.getPackagePath(2));
- OverrideInjector CORE_INJECTOR = new OverrideInjector<>();
+ OverrideInjector TEST_INJECTOR = new OverrideInjector(OverrideTestAssembly.getPackagePath(2));
+ OverrideInjector CORE_INJECTOR = new OverrideInjector();
// pre-dependency setup
@@ -175,7 +173,6 @@ public class DependencyInjectorTest
// variables to use later
IOverrideTest override;
OverrideTestCore coreOverride = new OverrideTestCore();
- OverrideTestSecondary secondaryOverride = new OverrideTestSecondary();
OverrideTestPrimary primaryOverride = new OverrideTestPrimary();
@@ -194,38 +191,23 @@ public class DependencyInjectorTest
Assert.assertNotNull("Test injector should've bound core override.", TEST_INJECTOR.get(IOverrideTest.class));
Assert.assertNull("Core injector should not have bound core override.", CORE_INJECTOR.get(IOverrideTest.class));
// priority gets
- Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.CORE));
- Assert.assertNull("Secondary override should not be bound yet.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.SECONDARY));
- Assert.assertNull("Primary override should not be bound yet.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.PRIMARY));
+ Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
+ Assert.assertNull("Non-core override should not be bound yet.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
// standard get
override = TEST_INJECTOR.get(IOverrideTest.class);
- Assert.assertEquals("Override returned incorrect override type.", override.getOverrideType(), EDhApiOverridePriority.CORE);
+ Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideInjector.CORE_PRIORITY);
Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestCore.VALUE);
- // secondary override
- TEST_INJECTOR.bind(IOverrideTest.class, secondaryOverride);
- // priority gets
- Assert.assertNotNull("Test injector should've bound secondary override.", TEST_INJECTOR.get(IOverrideTest.class));
- Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.CORE));
- Assert.assertNotNull("Secondary override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.SECONDARY));
- Assert.assertNull("Primary override should not be bound yet.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.PRIMARY));
- // standard get
- override = TEST_INJECTOR.get(IOverrideTest.class);
- Assert.assertEquals("Override returned incorrect override type.", override.getOverrideType(), EDhApiOverridePriority.SECONDARY);
- Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestSecondary.VALUE);
-
-
- // primary override
+ // default override
TEST_INJECTOR.bind(IOverrideTest.class, primaryOverride);
// priority gets
- Assert.assertNotNull("Test injector should've bound primary override.", TEST_INJECTOR.get(IOverrideTest.class));
- Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.CORE));
- Assert.assertNotNull("Secondary override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.SECONDARY));
- Assert.assertNotNull("Primary override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, EOverridePriority.PRIMARY));
+ Assert.assertNotNull("Test injector should've bound secondary override.", TEST_INJECTOR.get(IOverrideTest.class));
+ Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
+ Assert.assertNotNull("Secondary override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY));
// standard get
override = TEST_INJECTOR.get(IOverrideTest.class);
- Assert.assertEquals("Override returned incorrect override type.", override.getOverrideType(), EDhApiOverridePriority.PRIMARY);
+ Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY);
Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestPrimary.VALUE);