@Test public void testJacksonSerialization() { Layer2Topology topology = Layer2Topology.fromDomains( ImmutableSet.of( ImmutableSet.of(new Layer2Node("a", "b", 1), new Layer2Node("c", "d", 1)), ImmutableSet.of(new Layer2Node("e", "f", 1), new Layer2Node("g", "h", 1)))); assertEquals(topology, BatfishObjectMapper.clone(topology, Layer2Topology.class)); }
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))); }
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))); } }
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); }
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); static Builder builder(); static @Nonnull Layer2Topology fromDomains(Collection<Set<Layer2Node>> domains); @Nonnull Optional<Layer2Node> getBroadcastDomainRepresentative(Layer2Node layer2Node); @Nonnull Optional<Layer2Node> getBroadcastDomainRepresentative(
      String hostname, String interfaceName); boolean inSameBroadcastDomain(Layer2Node n1, Layer2Node n2); boolean inSameBroadcastDomain(NodeInterfacePair i1, NodeInterfacePair i2); boolean inSameBroadcastDomain(String host1, String iface1, String host2, String iface2); @JsonIgnore boolean isEmpty(); @Override boolean equals(@Nullable Object obj); @Override int hashCode(); }
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); static Builder builder(); static @Nonnull Layer2Topology fromDomains(Collection<Set<Layer2Node>> domains); @Nonnull Optional<Layer2Node> getBroadcastDomainRepresentative(Layer2Node layer2Node); @Nonnull Optional<Layer2Node> getBroadcastDomainRepresentative(
      String hostname, String interfaceName); boolean inSameBroadcastDomain(Layer2Node n1, Layer2Node n2); boolean inSameBroadcastDomain(NodeInterfacePair i1, NodeInterfacePair i2); boolean inSameBroadcastDomain(String host1, String iface1, String host2, String iface2); @JsonIgnore boolean isEmpty(); @Override boolean equals(@Nullable Object obj); @Override int hashCode(); static final Layer2Topology EMPTY; }