tech.jhipster.lite.module.domain.javadependency.JavaDependencies Maven / Gradle / Ivy
package tech.jhipster.lite.module.domain.javadependency;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import tech.jhipster.lite.shared.error.domain.Assert;
public class JavaDependencies {
public static final JavaDependencies EMPTY = new JavaDependencies(null);
private final Map dependencies;
public JavaDependencies(Collection dependencies) {
this.dependencies = buildDependencies(dependencies);
}
private Map buildDependencies(Collection dependencies) {
if (dependencies == null) {
return Map.of();
}
return dependencies.stream().collect(Collectors.toUnmodifiableMap(JavaDependency::id, Function.identity()));
}
public Optional get(DependencyId id) {
Assert.notNull("id", id);
return Optional.ofNullable(dependencies.get(id));
}
public JavaDependencies merge(JavaDependencies other) {
Assert.notNull("other", other);
Collection mergedDependencies = new ArrayList<>(other.dependencies.values());
mergedDependencies.addAll(dependencies.values());
return new JavaDependencies(mergedDependencies);
}
}