@Test public void testEquals() { UTGraph<String, String> g1 = new MapUTGraph<String, String>(); g1.add("a"); g1.add("b"); g1.add("c"); g1.add("d"); 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"); g1.node("c").connect(g1.node("d"), "1"); g1.node("c").connect(g1.node("d"), "2"); g1.node("d").connect(g1.node("c"), "2"); UTGraph<String, String> g2 = new MapUTGraph<String, String>(); g2.add("a"); g2.add("b"); g2.add("c"); g2.add("d"); 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"); g2.node("c").connect(g2.node("d"), "2"); g2.node("c").connect(g2.node("d"), "1"); g2.node("d").connect(g2.node("c"), "2"); assertEquals(g1, g2); g2.node("a").connect(g2.node("b"), "2"); assertFalse(g1.equals(g2)); }
@Override public boolean equals(Object other) { if(!(other instanceof DTGraph<?, ?>)) return false; DTGraph<Object, Object> otherGraph = (DTGraph<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(DTNode<L, T> node : nodes()) { if(! Functions.equals(node.label(), otherGraph.get(node.index()).label())) return false; for(DTNode<L, T> neighbor : node.neighbors()) { Collection<? extends DTLink<L, T>> links = node.linksOut(neighbor); Collection<? extends DTLink<Object, Object>> otherLinks = otherGraph.get(node.index()) .linksOut(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(DTLink<L, T> link : links) model.add(link.tag()); for(DTLink<Object, Object> otherLink : otherLinks) otherModel.add(otherLink.tag()); if(! model.tokens().equals(otherModel.tokens())) return false; for(T token : model.tokens()) if(otherModel.frequency(token) != model.frequency(token)) return false; } } } return true; }
MapDTGraph implements DTGraph<L, T>, HasPersistentNodes, HasPersistentLinks { @Override public boolean equals(Object other) { if(!(other instanceof DTGraph<?, ?>)) return false; DTGraph<Object, Object> otherGraph = (DTGraph<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(DTNode<L, T> node : nodes()) { if(! Functions.equals(node.label(), otherGraph.get(node.index()).label())) return false; for(DTNode<L, T> neighbor : node.neighbors()) { Collection<? extends DTLink<L, T>> links = node.linksOut(neighbor); Collection<? extends DTLink<Object, Object>> otherLinks = otherGraph.get(node.index()) .linksOut(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(DTLink<L, T> link : links) model.add(link.tag()); for(DTLink<Object, Object> otherLink : otherLinks) otherModel.add(otherLink.tag()); if(! model.tokens().equals(otherModel.tokens())) return false; for(T token : model.tokens()) if(otherModel.frequency(token) != model.frequency(token)) return false; } } } return true; } }
MapDTGraph implements DTGraph<L, T>, HasPersistentNodes, HasPersistentLinks { @Override public boolean equals(Object other) { if(!(other instanceof DTGraph<?, ?>)) return false; DTGraph<Object, Object> otherGraph = (DTGraph<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(DTNode<L, T> node : nodes()) { if(! Functions.equals(node.label(), otherGraph.get(node.index()).label())) return false; for(DTNode<L, T> neighbor : node.neighbors()) { Collection<? extends DTLink<L, T>> links = node.linksOut(neighbor); Collection<? extends DTLink<Object, Object>> otherLinks = otherGraph.get(node.index()) .linksOut(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(DTLink<L, T> link : links) model.add(link.tag()); for(DTLink<Object, Object> otherLink : otherLinks) otherModel.add(otherLink.tag()); if(! model.tokens().equals(otherModel.tokens())) return false; for(T token : model.tokens()) if(otherModel.frequency(token) != model.frequency(token)) return false; } } } return true; } MapDTGraph(); }
MapDTGraph implements DTGraph<L, T>, HasPersistentNodes, HasPersistentLinks { @Override public boolean equals(Object other) { if(!(other instanceof DTGraph<?, ?>)) return false; DTGraph<Object, Object> otherGraph = (DTGraph<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(DTNode<L, T> node : nodes()) { if(! Functions.equals(node.label(), otherGraph.get(node.index()).label())) return false; for(DTNode<L, T> neighbor : node.neighbors()) { Collection<? extends DTLink<L, T>> links = node.linksOut(neighbor); Collection<? extends DTLink<Object, Object>> otherLinks = otherGraph.get(node.index()) .linksOut(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(DTLink<L, T> link : links) model.add(link.tag()); for(DTLink<Object, Object> otherLink : otherLinks) otherModel.add(otherLink.tag()); if(! model.tokens().equals(otherModel.tokens())) return false; for(T token : model.tokens()) if(otherModel.frequency(token) != model.frequency(token)) return false; } } } return true; } MapDTGraph(); static MapDTGraph<L, T> copy(DTGraph<L, T> graph); static MapDTGraph<L, Object> copy(DGraph<L> graph); @Override DTNode<L, T> node(L label); int size(); @Override Set<? extends DTNode<L, T>> nodes(L label); @Override DTNode<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 DTNode<L, T>> nodes(); @Override Iterable<MapDTLink> links(); @Override Set<T> tags(); @Override DTNode<L, T> get(int i); @Override int hashCode(); @Override boolean equals(Object other); @Override Class<? extends DTGraph<L, T>> level(); }
MapDTGraph implements DTGraph<L, T>, HasPersistentNodes, HasPersistentLinks { @Override public boolean equals(Object other) { if(!(other instanceof DTGraph<?, ?>)) return false; DTGraph<Object, Object> otherGraph = (DTGraph<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(DTNode<L, T> node : nodes()) { if(! Functions.equals(node.label(), otherGraph.get(node.index()).label())) return false; for(DTNode<L, T> neighbor : node.neighbors()) { Collection<? extends DTLink<L, T>> links = node.linksOut(neighbor); Collection<? extends DTLink<Object, Object>> otherLinks = otherGraph.get(node.index()) .linksOut(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(DTLink<L, T> link : links) model.add(link.tag()); for(DTLink<Object, Object> otherLink : otherLinks) otherModel.add(otherLink.tag()); if(! model.tokens().equals(otherModel.tokens())) return false; for(T token : model.tokens()) if(otherModel.frequency(token) != model.frequency(token)) return false; } } } return true; } MapDTGraph(); static MapDTGraph<L, T> copy(DTGraph<L, T> graph); static MapDTGraph<L, Object> copy(DGraph<L> graph); @Override DTNode<L, T> node(L label); int size(); @Override Set<? extends DTNode<L, T>> nodes(L label); @Override DTNode<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 DTNode<L, T>> nodes(); @Override Iterable<MapDTLink> links(); @Override Set<T> tags(); @Override DTNode<L, T> get(int i); @Override int hashCode(); @Override boolean equals(Object other); @Override Class<? extends DTGraph<L, T>> level();  }