commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1136925 - in /commons/sandbox/graph/trunk/src: main/java/org/apache/commons/graph/model/InMemoryPath.java main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
Date Fri, 17 Jun 2011 16:24:50 GMT
Author: simonetripodi
Date: Fri Jun 17 16:24:49 2011
New Revision: 1136925

URL: http://svn.apache.org/viewvc?rev=1136925&view=rev
Log:
splitted Path/WeightedPath implementations

Added:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
  (with props)
Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryPath.java
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryPath.java?rev=1136925&r1=1136924&r2=1136925&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryPath.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryPath.java
Fri Jun 17 16:24:49 2011
@@ -25,32 +25,30 @@ import static java.util.Collections.unmo
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Path;
 import org.apache.commons.graph.Vertex;
-import org.apache.commons.graph.WeightedEdge;
-import org.apache.commons.graph.WeightedPath;
 
 /**
- * Support {@link WeightedPath} implementation, optimized for algorithms (such Dijkstra's)
that need to rebuild the path
+ * Support {@link Path} implementation, optimized for algorithms (such Dijkstra's) that need
to rebuild the path
  * traversing the predecessor list bottom-up.
  *
  * @param <V> the Graph vertices type
- * @param <WE> the Graph weighted edges type
+ * @param <E> the Graph edges type
  */
-public class InMemoryPath<V extends Vertex, WE extends WeightedEdge<V>>
-    implements WeightedPath<V, WE>
+public class InMemoryPath<V extends Vertex, E extends Edge<V>>
+    implements Path<V, E>
 {
 
     private final V source;
 
     private final V target;
 
-    private final Double weigth;
-
     private final LinkedList<V> vertices = new LinkedList<V>();
 
-    private final LinkedList<WE> edges = new LinkedList<WE>();
+    private final LinkedList<E> edges = new LinkedList<E>();
 
-    public InMemoryPath( V start, V target, Double weigth )
+    public InMemoryPath( V start, V target )
     {
         if ( start == null )
         {
@@ -60,14 +58,9 @@ public class InMemoryPath<V extends Vert
         {
             throw new IllegalArgumentException( "Path target cannot be null" );
         }
-        if ( weigth == null )
-        {
-            throw new IllegalArgumentException( "Path weigth cannot be null" );
-        }
 
         this.source = start;
         this.target = target;
-        this.weigth = weigth;
     }
 
     /**
@@ -104,12 +97,12 @@ public class InMemoryPath<V extends Vert
         return unmodifiableList( vertices );
     }
 
-    public void addEdgeInHead( WE edge )
+    public void addEdgeInHead( E edge )
     {
         edges.addFirst( edge );
     }
 
-    public void addEdgeInTail( WE edge )
+    public void addEdgeInTail( E edge )
     {
         edges.addLast( edge );
     }
@@ -117,7 +110,7 @@ public class InMemoryPath<V extends Vert
     /**
      * {@inheritDoc}
      */
-    public List<WE> getEdges()
+    public List<E> getEdges()
     {
         return unmodifiableList( edges );
     }
@@ -133,14 +126,6 @@ public class InMemoryPath<V extends Vert
     /**
      * {@inheritDoc}
      */
-    public Double getWeight()
-    {
-        return weigth;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public int hashCode()
     {
@@ -150,7 +135,6 @@ public class InMemoryPath<V extends Vert
         result = prime * result + ( ( source == null ) ? 0 : source.hashCode() );
         result = prime * result + ( ( target == null ) ? 0 : target.hashCode() );
         result = prime * result + ( ( vertices == null ) ? 0 : vertices.hashCode() );
-        result = prime * result + ( ( weigth == null ) ? 0 : weigth.hashCode() );
         return result;
     }
 
@@ -196,11 +180,6 @@ public class InMemoryPath<V extends Vert
             return false;
         }
 
-        if ( !weigth.equals( other.getWeight() ) )
-        {
-            return false;
-        }
-
         return true;
     }
 
@@ -210,7 +189,7 @@ public class InMemoryPath<V extends Vert
     @Override
     public String toString()
     {
-        return format( "InMemoryPath [weigth=%s, vertices=%s, edges=%s]", weigth, vertices,
edges );
+        return format( "InMemoryPath [vertices=%s, edges=%s]", vertices, edges );
     }
 
 }

Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java?rev=1136925&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
(added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
Fri Jun 17 16:24:49 2011
@@ -0,0 +1,111 @@
+package org.apache.commons.graph.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.lang.String.format;
+
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.WeightedEdge;
+import org.apache.commons.graph.WeightedPath;
+
+/**
+ * Support {@link WeightedPath} implementation, optimized for algorithms (such Dijkstra's)
that need to rebuild the path
+ * traversing the predecessor list bottom-up.
+ *
+ * @param <V> the Graph vertices type
+ * @param <WE> the Graph weighted edges type
+ */
+public final class InMemoryWeightedPath<V extends Vertex, WE extends WeightedEdge<V>>
+    extends InMemoryPath<V, WE>
+    implements WeightedPath<V, WE>
+{
+
+    private final Double weigth;
+
+    public InMemoryWeightedPath( V start, V target, Double weigth )
+    {
+        super( start, target );
+
+        if ( weigth == null )
+        {
+            throw new IllegalArgumentException( "Path weigth cannot be null" );
+        }
+        this.weigth = weigth;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Double getWeight()
+    {
+        return weigth;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ( ( weigth == null ) ? 0 : weigth.hashCode() );
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+
+        if ( !super.equals( obj ) )
+        {
+            return false;
+        }
+
+        if ( getClass() != obj.getClass() )
+        {
+            return false;
+        }
+
+        InMemoryWeightedPath other = (InMemoryWeightedPath) obj;
+        if ( !weigth.equals( other.getWeight() ) )
+        {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString()
+    {
+        return format( "InMemoryPath [weigth=%s, vertices=%s, edges=%s]", weigth, getVertices(),
getEdges() );
+    }
+
+}

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/InMemoryWeightedPath.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java?rev=1136925&r1=1136924&r2=1136925&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
(original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/shortestpath/DijkstraTestCase.java
Fri Jun 17 16:24:49 2011
@@ -1,34 +1,15 @@
 package org.apache.commons.graph.shortestpath;
 
+import static junit.framework.Assert.assertEquals;
+import static org.apache.commons.graph.shortestpath.Dijkstra.findShortestPath;
+
 import org.apache.commons.graph.Path;
 import org.apache.commons.graph.model.BaseLabeledVertex;
 import org.apache.commons.graph.model.BaseLabeledWeightedEdge;
 import org.apache.commons.graph.model.DirectedMutableWeightedGraph;
-import org.apache.commons.graph.model.InMemoryPath;
+import org.apache.commons.graph.model.InMemoryWeightedPath;
 import org.junit.Test;
 
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.apache.commons.graph.shortestpath.Dijkstra.findShortestPath;
-import static junit.framework.Assert.assertEquals;
-
 public final class DijkstraTestCase
 {
 
@@ -75,8 +56,8 @@ public final class DijkstraTestCase
 
         Path<BaseLabeledVertex, BaseLabeledWeightedEdge> actual = findShortestPath(
testGraph, one, five );
 
-        InMemoryPath<BaseLabeledVertex, BaseLabeledWeightedEdge> expected =
-            new InMemoryPath<BaseLabeledVertex, BaseLabeledWeightedEdge>( one, five,
20D );
+        InMemoryWeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge> expected =
+            new InMemoryWeightedPath<BaseLabeledVertex, BaseLabeledWeightedEdge>( one,
five, 20D );
 
         expected.addVertexInTail( three );
         expected.addVertexInTail( six );



Mime
View raw message