Groovy web console

subscribe to the feed Subscribe
to this
site

Module

Published 2 months ago by Not me
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
enum Module {
  SFE_COMMONS('sfe-commons', SAA_FRONT_END),
  SAA_FRONT_END('saa-front-end', SFE_COMMONS);

  private final String path
  private final Set dependencies

  Module(String path, Module... dependencies) {
    this.path = path
    this.dependencies = dependencies as Set
  }

  String getPath() {
    path
  }

  Set getDependencies() {
    dependencies
  }

  // Returns the set of everything that depends on this module, including this module itself.
  Set resolveDependents() {
    Set allDependents = [this]
    for (Module mod in values()) {
      Set dependencies = mod.getDependencies().toSet()
      if (mod.getDependencies().contains(this)) {
        allDependents.addAll(mod.resolveDependents())
      }
    }
    return allDependents
  }
}

println "front-end dependents: " + Module.SAA_FRONT_END.resolveDependents()
println "sfe-commons dependents: " + Module.SFE_COMMONS.resolveDependents()