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

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

There is a newer version: 1.22.0
Show newest version
package tech.jhipster.lite.module.domain.javadependency;

import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import tech.jhipster.lite.module.domain.javabuild.command.AddDirectJavaDependency;
import tech.jhipster.lite.module.domain.javabuild.command.AddJavaDependencyManagement;
import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommand;
import tech.jhipster.lite.module.domain.javabuild.command.RemoveDirectJavaDependency;
import tech.jhipster.lite.module.domain.javabuild.command.RemoveJavaDependencyManagement;
import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId;

final class DependenciesCommandsFactory {

  public static final DependenciesCommandsFactory MANAGEMENT = new DependenciesCommandsFactory(
    AddJavaDependencyManagement::new,
    AddJavaDependencyManagement::new,
    RemoveJavaDependencyManagement::new,
    RemoveJavaDependencyManagement::new
  );
  public static final DependenciesCommandsFactory DIRECT = new DependenciesCommandsFactory(
    AddDirectJavaDependency::new,
    AddDirectJavaDependency::new,
    RemoveDirectJavaDependency::new,
    RemoveDirectJavaDependency::new
  );

  private final Function addDependency;
  private final BiFunction addDependencyToProfile;
  private final Function removeDependency;
  private final BiFunction removeDependencyToProfile;

  private DependenciesCommandsFactory(
    Function addDependency,
    BiFunction addDependencyToProfile,
    Function removeDependency,
    BiFunction removeDependencyToProfile
  ) {
    this.addDependency = addDependency;
    this.addDependencyToProfile = addDependencyToProfile;
    this.removeDependency = removeDependency;
    this.removeDependencyToProfile = removeDependencyToProfile;
  }

  public JavaBuildCommand addDependency(JavaDependency javaDependency, Optional buildProfile) {
    if (buildProfile.isPresent()) {
      return addDependencyToProfile.apply(javaDependency, buildProfile.orElseThrow());
    }
    return addDependency.apply(javaDependency);
  }

  public JavaBuildCommand removeDependency(DependencyId id, Optional buildProfile) {
    if (buildProfile.isPresent()) {
      return removeDependencyToProfile.apply(id, buildProfile.orElseThrow());
    }
    return removeDependency.apply(id);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy