package com.hubspot.blazar.base;

import com.google.common.collect.SetMultimap;

import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;

public class DependencyGraph {
  private final SetMultimap<Integer, Integer> transitiveReduction;

  public DependencyGraph(SetMultimap<Integer, Integer> transitiveReduction) {
    this.transitiveReduction = transitiveReduction;
  }

  public Set<Integer> incomingVertices(int moduleId) {
    Set<Integer> incomingVertices = new HashSet<>();
    for (Entry<Integer, Integer> path : transitiveReduction.entries()) {
      if (path.getValue() == moduleId) {
        incomingVertices.add(path.getKey());
      }
    }

    return incomingVertices;
  }

  public Set<Integer> reachableVertices(int moduleId) {
    Set<Integer> reachableVertices = new HashSet<>();
    for (int vertex : outgoingVertices(moduleId)) {
      reachableVertices.add(vertex);
      reachableVertices.addAll(reachableVertices(vertex));
    }

    return reachableVertices;
  }

  public Set<Integer> outgoingVertices(int moduleId) {
    return transitiveReduction.get(moduleId);
  }

  @Override
  public String toString() {
    return transitiveReduction.toString();
  }
}

@@ -27,16 +27,123 @@
 .base;%0A%0A
+import com.fasterxml.jackson.annotation.JsonCreator;%0Aimport com.fasterxml.jackson.annotation.JsonProperty;%0A
 import c
@@ -180,16 +180,16 @@
 ltimap;%0A
-
 %0Aimport 
@@ -357,16 +357,31 @@
 ction;%0A%0A
+  @JsonCreator%0A
   public
@@ -397,16 +397,53 @@
 cyGraph(
+@JsonProperty(%22transitiveReduction%22) 
 SetMulti
@@ -540,24 +540,127 @@
 ction;%0A  %7D%0A%0A
+  public SetMultimap%3CInteger, Integer%3E getTransitiveReduction() %7B%0A    return transitiveReduction;%0A  %7D%0A%0A
   public Set

Make it work with Jackson