test_class.file: bots/topological/src/test/java/org/openjdk/skara/bots/topological/TopologicalSortTest.java
test_class.identifier: TopologicalSortTest
test_case.body: @Test
      void testTrivial() {
          var branches = TopologicalSort.sort(List.of(edge("A", "B")));
          assertEquals(brancheList("A", "B"), branches);
      }
test_case.class_method_signature: TopologicalSortTest.testTrivial()
test_case.full_signature: @Test void testTrivial()
test_case.identifier: testTrivial
test_case.invocations: sort of edge assertEquals brancheList
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void testTrivial()
focal_class.file: bots/topological/src/main/java/org/openjdk/skara/bots/topological/TopologicalSort.java
focal_class.identifier: TopologicalSort
focal_class.class_method_signature: TopologicalSort.sort(List<Edge> edges)
focal_class.full_signature: static List<Branch> sort(List<Edge> edges)
focal_class.identifier: sort
focal_class.modifiers: static
focal_class.parameters: (List<Edge> edges)
focal_class.return: List<Branch>
focal_class.signature: List<Branch> sort(List<Edge> edges)
focal_method.body: static List<Branch> sort(List<Edge> edges) {
          List<Edge> eCopy = new ArrayList<>(edges);
          List<Branch> result = new ArrayList<>();
          while (!eCopy.isEmpty()) {
              Set<Branch> orphans = eCopy.stream()
                      .map(e -> e.from)
                      .filter(f -> eCopy.stream().map(e -> e.to).noneMatch(f::equals))
                      .collect(Collectors.toSet());
              if (orphans.isEmpty()) {
                  throw new IllegalStateException("Detected a cycle! " + edges);
              }
              orphans.forEach(o -> {
                  result.add(o);
                  eCopy.removeIf(e -> o.equals(e.from));
              });
          }
  
          // add all leaves
          edges.stream()
              .map(e -> e.to)
              .filter(f -> edges.stream().map(e -> e.from).noneMatch(f::equals))
              .forEach(result::add);
  
          return result;
      }
focal_method.class_method_signature: TopologicalSort.sort(List<Edge> edges)
focal_method.full_signature: static List<Branch> sort(List<Edge> edges)
focal_method.identifier: sort
focal_method.invocations: isEmpty collect filter map stream noneMatch map stream toSet isEmpty forEach add removeIf equals forEach filter map stream noneMatch map stream
focal_method.modifiers: static
focal_method.parameters: (List<Edge> edges)
focal_method.return: List<Branch>
focal_method.signature: List<Branch> sort(List<Edge> edges)