All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.jhipster.lite.module.domain.javadependency.ProjectJavaDependenciesVersions Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
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.module.domain.javabuild.VersionSlug;
import tech.jhipster.lite.shared.error.domain.Assert;

public class ProjectJavaDependenciesVersions {

  public static final ProjectJavaDependenciesVersions EMPTY = new ProjectJavaDependenciesVersions(null);

  private final Map versions;

  public ProjectJavaDependenciesVersions(Collection versions) {
    this.versions = buildVersions(versions);
  }

  private Map buildVersions(Collection versions) {
    if (versions == null) {
      return Map.of();
    }

    return versions.stream().collect(Collectors.toUnmodifiableMap(version -> version.slug().propertyName(), Function.identity()));
  }

  public Optional get(VersionSlug slug) {
    Assert.notNull("slug", slug);

    return Optional.ofNullable(versions.get(slug.propertyName()));
  }

  public ProjectJavaDependenciesVersions merge(ProjectJavaDependenciesVersions other) {
    Assert.notNull("other", other);

    Collection mergedVersions = new ArrayList<>(other.versions.values());
    mergedVersions.addAll(versions.values());

    return new ProjectJavaDependenciesVersions(mergedVersions);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy