You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2008/03/03 18:27:55 UTC

svn commit: r633189 - /maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java

Author: carlos
Date: Mon Mar  3 09:27:54 2008
New Revision: 633189

URL: http://svn.apache.org/viewvc?rev=633189&view=rev
Log:
Add equals and hashCode. Partially merged 614706 from trunk

Modified:
    maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java

Modified: maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java?rev=633189&r1=633188&r2=633189&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java Mon Mar  3 09:27:54 2008
@@ -96,6 +96,86 @@
         return true;
     }
 
+
+    public int hashCode()
+    {
+        int result = 13;
+
+        if ( lowerBound == null )
+        {
+            result += 1;
+        }
+        else
+        {
+            result += lowerBound.hashCode();
+        }
+
+        result *= lowerBoundInclusive ? 1 : 2;
+
+        if ( upperBound == null )
+        {
+            result -= 3;
+        }
+        else
+        {
+            result -= upperBound.hashCode();
+        }
+
+        result *= upperBoundInclusive ? 2 : 3;
+
+        return result;
+    }
+
+    public boolean equals( Object other )
+    {
+        if ( this == other )
+        {
+            return true;
+        }
+
+        if ( !(other instanceof Restriction ) )
+        {
+            return false;
+        }
+
+        Restriction restriction = (Restriction) other;
+        if ( lowerBound != null )
+        {
+            if ( !lowerBound.equals( restriction.lowerBound ) )
+            {
+                return false;
+            }
+        }
+        else if ( restriction.lowerBound != null )
+        {
+            return false;
+        }
+
+        if ( lowerBoundInclusive != restriction.lowerBoundInclusive )
+        {
+            return false;
+        }
+
+        if ( upperBound != null )
+        {
+            if ( !upperBound.equals( restriction.upperBound ) )
+            {
+                return false;
+            }
+        }
+        else if ( restriction.upperBound != null )
+        {
+            return false;
+        }
+
+        if ( upperBoundInclusive != restriction.upperBoundInclusive )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
     public String toString()
     {
         StringBuffer buf = new StringBuffer();