commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1298166 - in /commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning: ShortestEdges.java WeightedEdgesComparator.java
Date Wed, 07 Mar 2012 22:23:05 GMT
Author: simonetripodi
Date: Wed Mar  7 22:23:04 2012
New Revision: 1298166

URL: http://svn.apache.org/viewvc?rev=1298166&view=rev
Log:
weights no longer retrieved from edges

Modified:
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/WeightedEdgesComparator.java

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java?rev=1298166&r1=1298165&r2=1298166&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
(original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/ShortestEdges.java
Wed Mar  7 22:23:04 2012
@@ -25,6 +25,7 @@ import java.util.Map;
 
 import org.apache.commons.graph.Graph;
 import org.apache.commons.graph.GraphException;
+import org.apache.commons.graph.Mapper;
 import org.apache.commons.graph.SpanningTree;
 import org.apache.commons.graph.VertexPair;
 import org.apache.commons.graph.model.MutableSpanningTree;
@@ -45,16 +46,19 @@ final class ShortestEdges<V, WE, W>
     private final Map<V, WE> predecessors = new HashMap<V, WE>();
 
     private final OrderedMonoid<W> weightOperations;
-    
+
+    private final Mapper<WE, W> weightedEdges;
+
     private final Graph<V, WE> graph;
 
     private final V source;
 
-    public ShortestEdges(Graph<V, WE> graph, V source, OrderedMonoid<W> weightOperations
)
+    public ShortestEdges( Graph<V, WE> graph, V source, OrderedMonoid<W> weightOperations,
Mapper<WE, W> weightedEdges )
     {
         this.graph = graph;
         this.source = source;
         this.weightOperations = weightOperations;
+        this.weightedEdges = weightedEdges;
     }
 
     /**
@@ -93,8 +97,7 @@ final class ShortestEdges<V, WE, W>
         return spanningTree;
     }
 
-    private static <V, WE, W> void addEdgeIgnoringExceptions( V vertex,
-                                                                                        
              MutableSpanningTree<V, WE, W> spanningTree )
+    private static <V, WE, W> void addEdgeIgnoringExceptions( V vertex, MutableSpanningTree<V,
WE, W> spanningTree )
     {
         try
         {
@@ -118,7 +121,7 @@ final class ShortestEdges<V, WE, W>
 
     /**
      * Returns the distance related to input vertex, or null if it does not exist.
-     * 
+     *
      * <b>NOTE</b>: the method {@link hasWeight} should be used first to check
if
      * the input vertex has an assiged weight.
      *
@@ -139,9 +142,9 @@ final class ShortestEdges<V, WE, W>
             return null;
         }
 
-        return edge.getWeight();
+        return weightedEdges.map( edge );
     }
-    
+
     /**
      * Checks if there is a weight related to the input {@code Vertex}.
      *

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/WeightedEdgesComparator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/WeightedEdgesComparator.java?rev=1298166&r1=1298165&r2=1298166&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/WeightedEdgesComparator.java
(original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/spanning/WeightedEdgesComparator.java
Wed Mar  7 22:23:04 2012
@@ -21,6 +21,8 @@ package org.apache.commons.graph.spannin
 
 import java.util.Comparator;
 
+import org.apache.commons.graph.Mapper;
+
 /**
  *
  * @param <W>
@@ -32,14 +34,17 @@ public class WeightedEdgesComparator<W, 
 
     private final Comparator<W> weightComparator;
 
-    public WeightedEdgesComparator( Comparator<W> weightComparator )
+    private final Mapper<WE, W> weightedEdges;
+
+    public WeightedEdgesComparator( Comparator<W> weightComparator, Mapper<WE, W>
weightedEdges )
     {
         this.weightComparator = weightComparator;
+        this.weightedEdges = weightedEdges;
     }
 
     public int compare( WE o1, WE o2 )
     {
-        return weightComparator.compare( o1.getWeight(), o2.getWeight() );
+        return weightComparator.compare( weightedEdges.map( o1 ), weightedEdges.map( o2 )
);
     }
 
 }



Mime
View raw message