commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1136601 - /commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledEdge.java
Date Thu, 16 Jun 2011 18:59:11 GMT
Author: simonetripodi
Date: Thu Jun 16 18:59:10 2011
New Revision: 1136601

URL: http://svn.apache.org/viewvc?rev=1136601&view=rev
Log:
implemented equals/hashCode methods

Modified:
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledEdge.java

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledEdge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledEdge.java?rev=1136601&r1=1136600&r2=1136601&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledEdge.java
(original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseLabeledEdge.java
Thu Jun 16 18:59:10 2011
@@ -69,6 +69,83 @@ public class BaseLabeledEdge<V extends L
      * {@inheritDoc}
      */
     @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ( ( head == null ) ? 0 : head.hashCode() );
+        result = prime * result + ( ( label == null ) ? 0 : label.hashCode() );
+        result = prime * result + ( ( tail == null ) ? 0 : tail.hashCode() );
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+
+        if ( obj == null )
+        {
+            return false;
+        }
+
+        if ( getClass() != obj.getClass() )
+        {
+            return false;
+        }
+
+        @SuppressWarnings( "unchecked" ) // etherogeneous edges won't be tested
+        BaseLabeledEdge<V> other = (BaseLabeledEdge<V>) obj;
+
+        if ( head == null )
+        {
+            if ( other.getHead() != null )
+            {
+                return false;
+            }
+        }
+        else if ( !head.equals( other.getHead() ) )
+        {
+            return false;
+        }
+
+        if ( tail == null )
+        {
+            if ( other.getTail() != null )
+            {
+                return false;
+            }
+        }
+        else if ( !tail.equals( other.getTail() ) )
+        {
+            return false;
+        }
+
+        if ( label == null )
+        {
+            if ( other.getLabel() != null )
+            {
+                return false;
+            }
+        }
+        else if ( !label.equals( other.label ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public String toString()
     {
         return format( "Edge(label=%s, head=%s, tail=%s)", label, head.getLabel(), tail.getLabel()
);



Mime
View raw message