diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-04 19:36:42 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-04 19:36:42 +0000 |
commit | 4e57d4dfb4e5ec8adb4f498499bbd54fac4d7a26 (patch) | |
tree | 6f229296ea3657b6da467dc048961b119a166827 /sca-java-2.x/trunk/modules | |
parent | 0171cc8e782f26b1d386ddcce9d750b1f6c76688 (diff) |
Fix for TUSCANY-3456 (only register direct transformer with lower weight)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@906613 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
2 files changed, 22 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java index 01916dfb96..44c42010ba 100644 --- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java +++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; /** * Directed, weighted graph @@ -37,6 +38,7 @@ import java.util.concurrent.ConcurrentHashMap; * @version $Rev$ $Date$ */ public class DirectedGraph<V, E> implements Cloneable { + private final static Logger logger = Logger.getLogger(DirectedGraph.class.getName()); private final Map<V, Vertex> vertices = new HashMap<V, Vertex>(); /** @@ -199,6 +201,21 @@ public class DirectedGraph<V, E> implements Cloneable { } public void addEdge(V source, V target, E edgeValue, int weight, boolean publicEdge) { + // Fix for TUSCANY-3456 + // First check if we already has an edge + Edge edge = getEdge(source, target); + if (edge != null) { + // An existing edge has higher weight, let's replace it + if (edge.weight > weight) { + logger.warning("An edge exists with higher weight: " + edge); + removeEdge(edge); + } else { + // Don't add this edge + logger.warning("An edge exists with lower weight: " + edge); + return; + } + } + Vertex s = getVertex(source); if (s == null) { s = new Vertex(source); @@ -209,7 +226,7 @@ public class DirectedGraph<V, E> implements Cloneable { t = new Vertex(target); vertices.put(target, t); } - Edge edge = new Edge(s, t, edgeValue, weight, publicEdge); + edge = new Edge(s, t, edgeValue, weight, publicEdge); s.outEdges.put(t, edge); t.inEdges.put(s, edge); } diff --git a/sca-java-2.x/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java b/sca-java-2.x/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java index d48711cd64..9ab2b51c95 100644 --- a/sca-java-2.x/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java +++ b/sca-java-2.x/trunk/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java @@ -44,7 +44,11 @@ public class DirectedGraphTestCase { @Test public void testGraph() { + graph.addEdge("a", "b", null, 4, true); + graph.addEdge("a", "b", null, 5, true); + Assert.assertEquals(4, graph.getEdge("a", "b").getWeight()); graph.addEdge("a", "b", null, 3, true); + Assert.assertEquals(3, graph.getEdge("a", "b").getWeight()); graph.addEdge("b", "c", null, 1, true); // graph.addEdge("a", "c", null, 8, true); graph.addEdge("a", "d", null, 3, true); |