### Question:
MapUTGraph implements UTGraph<L, T>, HasPersistentNodes, HasPersistentLinks { @Override public boolean equals(Object other) { if(!(other instanceof UTGraph<?, ?>)) return false; UTGraph<Object, Object> otherGraph = (UTGraph<Object, Object>) other; if(! otherGraph.level().equals(level())) return false; if(size() != otherGraph.size()) return false; if(numLinks() != otherGraph.numLinks()) return false; if(labels().size() != otherGraph.labels().size()) return false; for(UTNode<L, T> node : nodes()) { if(! Functions.equals(node.label(), otherGraph.get(node.index()).label())) return false; for(UTNode<L, T> neighbor : node.neighbors()) { Collection<? extends UTLink<L, T>> links = node.links(neighbor); Collection<? extends UTLink<Object, Object>> otherLinks = otherGraph.get(node.index()) .links(otherGraph.get(neighbor.index())); if(links.size() != otherLinks.size()) return false; if(links.size() == 1) { T tag = links.iterator().next().tag(); Object otherTag = otherLinks.iterator().next().tag(); if(! Functions.equals(tag, otherTag)) return false; } else { FrequencyModel<T> model = new FrequencyModel<T>(); FrequencyModel<Object> otherModel = new FrequencyModel<Object>(); for(UTLink<L, T> link : links) model.add(link.tag()); for(UTLink<Object, Object> otherLink : otherLinks) otherModel.add(otherLink.tag()); for(T token : model.tokens()) if(otherModel.frequency(token) != model.frequency(token)) return false; } } } return true; } MapUTGraph(); static MapUTGraph<L, T> copy(UTGraph<L, T> graph); static MapUTGraph<L,T> copy(UGraph<L> graph); @Override UTNode<L, T> node(L label); int size(); @Override Set<? extends UTNode<L, T>> nodes(L label); @Override UTNode<L, T> add(L label); boolean uniqueLabels(); String toString(); @Override boolean connected(L first, L second); @Override Set<L> labels(); @Override long numLinks(); @Override long state(); @Override List<? extends UTNode<L, T>> nodes(); @Override Iterable<MapUTLink> links(); @Override Set<T> tags(); @Override int hashCode(); @Override boolean equals(Object other); @Override UTNode<L, T> get(int i); @Override Class<? extends UTGraph<L, T>> level();  }### Answer:
@Test public void testEquals() { UTGraph<String, String> g1 = new MapUTGraph<String, String>(); g1.add("a"); g1.add("b"); g1.add("c"); g1.node("a").connect(g1.node("b"), "1"); g1.node("a").connect(g1.node("b"), "2"); g1.node("a").connect(g1.node("b"), "2"); g1.node("b").connect(g1.node("c"), "1"); UTGraph<String, String> g2 = new MapUTGraph<String, String>(); g2.add("a"); g2.add("b"); g2.add("c"); g2.node("a").connect(g2.node("b"), "2"); g2.node("a").connect(g2.node("b"), "1"); g2.node("a").connect(g2.node("b"), "2"); g2.node("b").connect(g2.node("c"), "1"); assertEquals(g1, g2); g2.node("a").connect(g2.node("b"), "2"); assertFalse(g1.equals(g2)); }