class Layer2Topology {

  public static @Nonnull Layer2Topology fromDomains(Collection<Set<Layer2Node>> domains) {
    return new Layer2Topology(
        domains.stream()
            .flatMap(
                domain -> {
                  if (domain.isEmpty()) {
                    return Stream.of();
                  }
                  Layer2Node repr = domain.stream().max(Layer2Node::compareTo).get();
                  return domain.stream().map(node -> Maps.immutableEntry(node, repr));
                })
            .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue)));
  }

  private  Layer2Topology(Map<Layer2Node, Layer2Node> representativeByNode);

}