From 2230c4018a9ea25bb97408471a5da81df520cf9f Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 8 Jul 2024 13:57:25 +0200 Subject: [PATCH] Update DependencyResolver a bit --- .../base/utility/DependencyResolver.java | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java b/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java index 80ae351d..64fb5a5c 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java @@ -21,21 +21,17 @@ package de.staropensource.sosengine.base.utility; import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException; import de.staropensource.sosengine.base.exceptions.UnmetDependenciesException; -import de.staropensource.sosengine.base.types.dependency.DependencyResolvedDependencyVector; import de.staropensource.sosengine.base.types.dependency.DependencyVector; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Resolves dependency vectors. * * @since 1-alpha1 */ -@SuppressWarnings({ "unused" }) +@SuppressWarnings({ "unused", "UnusedReturnValue" }) public final class DependencyResolver { /** * A list of {@link DependencyVector}s. @@ -55,8 +51,42 @@ public final class DependencyResolver { * @param vector dependency vector to add * @since 1-alpha1 */ - public void addVector(@NotNull DependencyVector vector) { + public DependencyResolver addVector(@NotNull DependencyVector vector) { vectors.add(vector); + return this; + } + + /** + * Adds multiple dependency vectors. + * + * @param vectors dependency vectors to add + * @since 1-alpha1 + */ + public DependencyResolver addVectors(@NotNull Collection<@NotNull DependencyVector> vectors) { + this.vectors.addAll(vectors); + return this; + } + + /** + * Adds multiple dependency vectors. + * + * @param vectors dependency vectors to add + * @since 1-alpha1 + */ + public DependencyResolver addVectors(@NotNull List<@NotNull DependencyVector> vectors) { + this.vectors = vectors; + return this; + } + + /** + * Adds multiple dependency vectors. + * + * @param vectors dependency vectors to add + * @since 1-alpha1 + */ + public DependencyResolver addVectors(@NotNull Set<@NotNull DependencyVector> vectors) { + this.vectors.addAll(vectors); + return this; } /** @@ -65,8 +95,8 @@ public final class DependencyResolver { * * @since 1-alpha1 */ - public void resolve() throws UnmetDependenciesException, UnexpectedThrowableException { - List resolvedDependencyVectors = new ArrayList<>(); + @SuppressWarnings("JavaReflectionInvocation") + public DependencyResolver resolve() throws UnmetDependenciesException, UnexpectedThrowableException { Map unmetDependencies = new HashMap<>(); try { @@ -143,10 +173,14 @@ public final class DependencyResolver { } } } catch (Exception exception) { + // Throw UnexpectedThrowableException when something horribly fails throw new UnexpectedThrowableException(exception); } + // Check for any unmet dependencies if (!unmetDependencies.isEmpty()) throw new UnmetDependenciesException(unmetDependencies); + + return this; } }