Update DependencyResolver a bit

This commit is contained in:
JeremyStar™ 2024-07-08 13:57:25 +02:00
parent 3f7edd0968
commit 2230c4018a
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -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<DependencyResolvedDependencyVector> resolvedDependencyVectors = new ArrayList<>();
@SuppressWarnings("JavaReflectionInvocation")
public DependencyResolver resolve() throws UnmetDependenciesException, UnexpectedThrowableException {
Map<DependencyVector, String> 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;
}
}