Update DependencyResolver a bit
This commit is contained in:
parent
3f7edd0968
commit
2230c4018a
1 changed files with 43 additions and 9 deletions
|
@ -21,21 +21,17 @@ package de.staropensource.sosengine.base.utility;
|
||||||
|
|
||||||
import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException;
|
import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException;
|
||||||
import de.staropensource.sosengine.base.exceptions.UnmetDependenciesException;
|
import de.staropensource.sosengine.base.exceptions.UnmetDependenciesException;
|
||||||
import de.staropensource.sosengine.base.types.dependency.DependencyResolvedDependencyVector;
|
|
||||||
import de.staropensource.sosengine.base.types.dependency.DependencyVector;
|
import de.staropensource.sosengine.base.types.dependency.DependencyVector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves dependency vectors.
|
* Resolves dependency vectors.
|
||||||
*
|
*
|
||||||
* @since 1-alpha1
|
* @since 1-alpha1
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unused" })
|
@SuppressWarnings({ "unused", "UnusedReturnValue" })
|
||||||
public final class DependencyResolver {
|
public final class DependencyResolver {
|
||||||
/**
|
/**
|
||||||
* A list of {@link DependencyVector}s.
|
* A list of {@link DependencyVector}s.
|
||||||
|
@ -55,8 +51,42 @@ public final class DependencyResolver {
|
||||||
* @param vector dependency vector to add
|
* @param vector dependency vector to add
|
||||||
* @since 1-alpha1
|
* @since 1-alpha1
|
||||||
*/
|
*/
|
||||||
public void addVector(@NotNull DependencyVector vector) {
|
public DependencyResolver addVector(@NotNull DependencyVector vector) {
|
||||||
vectors.add(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
|
* @since 1-alpha1
|
||||||
*/
|
*/
|
||||||
public void resolve() throws UnmetDependenciesException, UnexpectedThrowableException {
|
@SuppressWarnings("JavaReflectionInvocation")
|
||||||
List<DependencyResolvedDependencyVector> resolvedDependencyVectors = new ArrayList<>();
|
public DependencyResolver resolve() throws UnmetDependenciesException, UnexpectedThrowableException {
|
||||||
Map<DependencyVector, String> unmetDependencies = new HashMap<>();
|
Map<DependencyVector, String> unmetDependencies = new HashMap<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -143,10 +173,14 @@ public final class DependencyResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
|
// Throw UnexpectedThrowableException when something horribly fails
|
||||||
throw new UnexpectedThrowableException(exception);
|
throw new UnexpectedThrowableException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for any unmet dependencies
|
||||||
if (!unmetDependencies.isEmpty())
|
if (!unmetDependencies.isEmpty())
|
||||||
throw new UnmetDependenciesException(unmetDependencies);
|
throw new UnmetDependenciesException(unmetDependencies);
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue