commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1145512 - in /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph: shortestpath/AStar.java shortestpath/Dijkstra.java spanning/Kruskal.java spanning/Prim.java
Date Tue, 12 Jul 2011 09:33:08 GMT
Author: simonetripodi
Date: Tue Jul 12 09:33:08 2011
New Revision: 1145512

URL: http://svn.apache.org/viewvc?rev=1145512&view=rev
Log:
used java.util.Queue methods that throw exception by contract, rather than methods that return
special values

Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java?rev=1145512&r1=1145511&r2=1145512&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/AStar.java
Tue Jul 12 09:33:08 2011
@@ -73,7 +73,7 @@ public final class AStar
 
         // The set of tentative nodes to be evaluated.
         final PriorityQueue<V> openSet = new PriorityQueue<V>( graph.getOrder(),
fScores );
-        openSet.offer( start );
+        openSet.add( start );
 
         // The of navigated nodes
         final PredecessorsList<V, WE> predecessors = new PredecessorsList<V, WE>(
graph );
@@ -81,7 +81,7 @@ public final class AStar
         // extract the node in openset having the lowest f_score[] value
         while ( !openSet.isEmpty() )
         {
-            V current = openSet.poll();
+            V current = openSet.remove();
 
             // destination reached, stop and build the path
             if ( goal.equals( current ) )
@@ -101,7 +101,7 @@ public final class AStar
                     WE edge = graph.getEdge( current, v );
                     Double tentativeGScore = gScores.getWeight( current ) + edge.getWeight();
 
-                    if ( openSet.offer( v ) || tentativeGScore.compareTo( gScores.getWeight(
v ) ) < 0 )
+                    if ( openSet.add( v ) || tentativeGScore.compareTo( gScores.getWeight(
v ) ) < 0 )
                     {
                         predecessors.addPredecessor( v, current );
                         gScores.setWeight( v, tentativeGScore );

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java?rev=1145512&r1=1145511&r2=1145512&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/shortestpath/Dijkstra.java
Tue Jul 12 09:33:08 2011
@@ -62,7 +62,7 @@ public final class Dijkstra
         shortestDistances.setWeight( source, 0D );
 
         final PriorityQueue<V> unsettledNodes = new PriorityQueue<V>( graph.getOrder(),
shortestDistances );
-        unsettledNodes.offer( source );
+        unsettledNodes.add( source );
 
         final Set<V> settledNodes = new HashSet<V>();
 
@@ -71,7 +71,7 @@ public final class Dijkstra
         // extract the node with the shortest distance
         while ( !unsettledNodes.isEmpty() )
         {
-            V vertex = unsettledNodes.poll();
+            V vertex = unsettledNodes.remove();
 
             // destination reached, stop and build the path
             if ( target.equals( vertex ) )
@@ -93,7 +93,7 @@ public final class Dijkstra
                     {
                         // assign new shortest distance and mark unsettled
                         shortestDistances.setWeight( v, shortDist );
-                        unsettledNodes.offer( v );
+                        unsettledNodes.add( v );
 
                         // assign predecessor in shortest path
                         predecessors.addPredecessor( v, vertex );

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java?rev=1145512&r1=1145511&r2=1145512&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Kruskal.java
Tue Jul 12 09:33:08 2011
@@ -63,7 +63,7 @@ public final class Kruskal
 
         while ( settledNodes.size() < graph.getOrder() )
         {
-            WE edge = orderedEdges.poll();
+            WE edge = orderedEdges.remove();
 
             VertexPair<V> vertices = graph.getVertices( edge );
             V head = vertices.getHead();

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java?rev=1145512&r1=1145511&r2=1145512&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/spanning/Prim.java
Tue Jul 12 09:33:08 2011
@@ -66,14 +66,14 @@ public final class Prim
         final ShortestEdges<V, WE> shortesEdges = new ShortestEdges<V, WE>( graph,
source );
 
         final PriorityQueue<V> unsettledNodes = new PriorityQueue<V>( graph.getOrder(),
shortesEdges );
-        unsettledNodes.offer( source );
+        unsettledNodes.add( source );
 
         final Set<WE> settledEdges = new HashSet<WE>();
 
         // extract the node with the shortest distance
         while ( !unsettledNodes.isEmpty() )
         {
-            V vertex = unsettledNodes.poll();
+            V vertex = unsettledNodes.remove();
 
             for ( V v : graph.getConnectedVertices( vertex ) )
             {
@@ -84,7 +84,7 @@ public final class Prim
                 {
                     if ( !unsettledNodes.contains( v ) )
                     {
-                        unsettledNodes.offer( v );
+                        unsettledNodes.add( v );
                     }
 
                     shortesEdges.addPredecessor( v, edge );



Mime
View raw message