Exemplo n.º 1
0
  public static List<ModuleBuilder> sortWithContext(
      final SchemaContext context, final ModuleBuilder... builders) {
    List<ModuleOrModuleBuilder> all =
        ModuleOrModuleBuilder.fromAll(context.getModules(), asList(builders));

    List<TopologicalSort.Node> sorted = sortInternal(all);
    // Cast to ModuleBuilder from Node if possible and return
    return Lists.transform(
        sorted,
        new Function<TopologicalSort.Node, ModuleBuilder>() {

          @Override
          public ModuleBuilder apply(final TopologicalSort.Node input) {
            if (input == null) {
              return null;
            }
            ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
            if (moduleOrModuleBuilder.isModuleBuilder()) {
              return moduleOrModuleBuilder.getModuleBuilder();
            } else {
              return null;
            }
          }
        });
  }
Exemplo n.º 2
0
 /**
  * Topological sort of module dependency graph.
  *
  * @return Sorted list of Modules. Modules can be further processed in returned order.
  */
 public static List<Module> sort(final Module... modules) {
   List<TopologicalSort.Node> sorted =
       sortInternal(
           ModuleOrModuleBuilder.fromAll(asList(modules), Collections.<ModuleBuilder>emptyList()));
   // Cast to Module from Node and return
   return Lists.transform(sorted, TOPOLOGY_FUNCTION);
 }
Exemplo n.º 3
0
 public static List<ModuleBuilder> sort(final Collection<ModuleBuilder> builders) {
   List<TopologicalSort.Node> sorted =
       sortInternal(ModuleOrModuleBuilder.fromAll(Collections.<Module>emptySet(), builders));
   return Lists.transform(sorted, NODE_TO_MODULEBUILDER);
 }