maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dion Gillard <dion.gill...@gmail.com>
Subject Re: cvs commit: maven-components/maven-artifact/src/main/java/org/apache/maven/artifact AbstractMavenArtifact.java
Date Sun, 20 Jun 2004 01:30:32 GMT
"If two objects are equal according to the equals(Object)  method,
then calling the hashCode method on each of the two objects must
produce the same integer result."

>From what I can tell if two artifacts have the same Id, this code
returns true for equals, but the two artifacts may have a different
version or type, and their hashcodes will not be equal.

AFAICT this is broken.

On 20 Jun 2004 01:07:05 -0000, trygvis@apache.org <trygvis@apache.org> wrote:
> 
> trygvis     2004/06/19 18:07:05
> 
>   Modified:    maven-artifact/src/main/java/org/apache/maven/artifact
>                         AbstractMavenArtifact.java
>   Log:
>   o Reimplemented equals(), it was erroneous.
>   o Implemented hashCode() which is required when overriding equals().
> 
>   Revision  Changes    Path
>   1.2       +15 -10    maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractMavenArtifact.java
> 
>   Index: AbstractMavenArtifact.java
>   ===================================================================
>   RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractMavenArtifact.java,v
>   retrieving revision 1.1
>   retrieving revision 1.2
>   diff -u -r1.1 -r1.2
>   --- AbstractMavenArtifact.java        11 Jun 2004 15:12:24 -0000      1.1
>   +++ AbstractMavenArtifact.java        20 Jun 2004 01:07:05 -0000      1.2
>   @@ -161,17 +161,22 @@
>        {
>            return dependency.getType();
>        }
>   -
>   +
>        public boolean equals( Object obj )
>        {
>   -        MavenArtifact other = ( MavenArtifact ) obj;
>   -
>   -        Dependency otherDependency = other.getDependency();
>   -
>   -        //if paths are the same artifats are the same
>   -        boolean retValue = getPath().equals( other.getPath() );
>   -
>   -        return retValue;
>   -
>   +        if( !( obj instanceof MavenArtifact) )
>   +            return false;
>   +
>   +        MavenArtifact other = (MavenArtifact) obj;
>   +
>   +        return dependency.getId() == other.getDependency().getId();
>   +    }
>   +
>   +    public long hashCode()
>   +    {
>   +        return dependency.getGroupId().hashCode() +
>   +               dependency.getArtifactId().hashCode() +
>   +               dependency.getVersion().hashCode() +
>   +               dependency.getType().hashCode();
>        }
>    }
> 
>

Mime
View raw message