Replace the override priority enum with an int
This commit is contained in:
+5
-3
@@ -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. <br>
|
||||
* For most developers this can be left at the default.
|
||||
*/
|
||||
default EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.PRIMARY; }
|
||||
@Override
|
||||
default EDhApiOverridePriority getPriority() { return EDhApiOverridePriority.PRIMARY; }
|
||||
|
||||
}
|
||||
|
||||
Vendored
+20
@@ -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. <br>
|
||||
* For most developers this can be left at the default.
|
||||
*/
|
||||
default int getPriority() { return OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY; }
|
||||
|
||||
}
|
||||
-31
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
core/src/main/java/com/seibel/lod/core/api/external/items/enums/override/EDhApiOverridePriority.java
Vendored
-34
@@ -1,34 +0,0 @@
|
||||
package com.seibel.lod.core.api.external.items.enums.override;
|
||||
|
||||
/**
|
||||
* PRIMARY, <br>
|
||||
* SECONDARY, <br>
|
||||
* CORE, <br>
|
||||
*
|
||||
* @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. <br>
|
||||
* The highest priority.
|
||||
*/
|
||||
PRIMARY,
|
||||
|
||||
/**
|
||||
* Overrides with this priority are only used if there isn't
|
||||
* an override with PRIMARY priority. <br>
|
||||
* 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. <br>
|
||||
* This is the lowest priority and will be overridden by all other priorities.
|
||||
*/
|
||||
CORE,
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.seibel.lod.core.enums.override;
|
||||
|
||||
/**
|
||||
* PRIMARY, <br>
|
||||
* SECONDARY, <br>
|
||||
* CORE, <br>
|
||||
*
|
||||
* @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. <br>
|
||||
* The highest priority.
|
||||
*/
|
||||
PRIMARY,
|
||||
|
||||
/**
|
||||
* Overrides with this priority are only used if there isn't
|
||||
* an override with PRIMARY priority. <br>
|
||||
* 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. <br>
|
||||
* This is the lowest priority and will be overridden by all other priorities.
|
||||
*/
|
||||
CORE,
|
||||
}
|
||||
+70
-58
@@ -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. <Br>
|
||||
* 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<BindableType extends IDhApiOverrideable>
|
||||
public class OverrideInjector
|
||||
{
|
||||
public static final OverrideInjector<IDhApiOverrideable> INSTANCE = new OverrideInjector<>();
|
||||
public static final OverrideInjector INSTANCE = new OverrideInjector();
|
||||
|
||||
private final HashMap<Class<? extends ICoreDhApiOverrideable>, OverridePriorityListContainer> overrideContainerByInterface = new HashMap<>();
|
||||
|
||||
private final DependencyInjector<IDhApiOverrideable> primaryInjector = new DependencyInjector<>(IDhApiOverrideable.class, false);
|
||||
private final DependencyInjector<IDhApiOverrideable> secondaryInjector = new DependencyInjector<>(IDhApiOverrideable.class, false);
|
||||
private final DependencyInjector<IDhApiOverrideable> coreInjector = new DependencyInjector<>(IDhApiOverrideable.class, false);
|
||||
|
||||
private static final GenericEnumConverter<EOverridePriority, EDhApiOverridePriority> ENUM_CONVERTER = new GenericEnumConverter<>(EOverridePriority.class, EDhApiOverridePriority.class);
|
||||
/**
|
||||
* All core overrides should have this priority. <Br>
|
||||
* 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<BindableType extends IDhApiOverrideable>
|
||||
}
|
||||
|
||||
/** 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<BindableType extends IDhApiOverrideable>
|
||||
*
|
||||
* @see DependencyInjector#get(Class, boolean)
|
||||
*/
|
||||
public <T extends BindableType> T get(Class<T> interfaceClass) throws ClassCastException
|
||||
public <T extends ICoreDhApiOverrideable> T get(Class<T> 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<BindableType extends IDhApiOverrideable>
|
||||
*
|
||||
* @see DependencyInjector#get(Class, boolean)
|
||||
*/
|
||||
public <T extends BindableType> T get(Class<T> interfaceClass, EOverridePriority overridePriority) throws ClassCastException
|
||||
public <T extends ICoreDhApiOverrideable> T get(Class<T> 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<BindableType extends IDhApiOverrideable>
|
||||
/** 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<BindableType extends IDhApiOverrideable>
|
||||
|
||||
|
||||
|
||||
/** Small helper method so we don't have to use DhApi enums. */
|
||||
private EOverridePriority getCorePriorityEnum(IDhApiOverrideable override)
|
||||
{
|
||||
return ENUM_CONVERTER.convertToCoreType(override.getOverrideType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+115
@@ -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<OverridePriorityPair> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
-43
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<IDhApiOverrideable> TEST_INJECTOR = new OverrideInjector<>(OverrideTestAssembly.getPackagePath(2));
|
||||
OverrideInjector<IDhApiOverrideable> 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);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user