private static DependencyNode buildDependencyNode(
    DependencyResult dependency,
    Map<Object, DependencyNode> added,
    IdGenerator idGenerator
  ) {
    if (dependency instanceof ResolvedDependencyResult) {
      return buildResolvedDependencyNode((ResolvedDependencyResult)dependency, added, idGenerator);
    }
    else if (dependency instanceof UnresolvedDependencyResult) {
      return buildUnresolvedDependencyNode((UnresolvedDependencyResult)dependency, added, idGenerator);
    }
    else {
      throw new IllegalStateException("Unsupported dependency result type: " + dependency);
    }
  }
private static DependencyNode buildDependencyNode(
    DependencyResult dependency,
    Map<Object, DependencyNode> added,
    IdGenerator idGenerator
  )