You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/02/26 17:40:20 UTC

[GitHub] [maven-gpg-plugin] Syquel opened a new pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Syquel opened a new pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12


   Provides an implementation of GpgVersion#equals andGpgVersion#hashCode to address [MGPG-80](https://issues.apache.org/jira/projects/MGPG/issues/MGPG-80).
   "GpgVersion#equals" is implemented by utilizing "GpgVersion#compareTo".
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-gpg-plugin] elharo commented on pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Posted by GitBox <gi...@apache.org>.
elharo commented on pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12#issuecomment-788080959


   and it passed, will merge


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-gpg-plugin] elharo merged pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Posted by GitBox <gi...@apache.org>.
elharo merged pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-gpg-plugin] elharo commented on a change in pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Posted by GitBox <gi...@apache.org>.
elharo commented on a change in pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12#discussion_r583810993



##########
File path: src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java
##########
@@ -48,4 +50,22 @@ public void testOpposite()
         assertFalse( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" )
                 .isBefore( GpgVersion.parse( "2.0.26" ) ) );
     }
+
+    @Test
+    public void testEquality()
+    {
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ), GpgVersion.parse( "2.2.10" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ), GpgVersion.parse( "2.0.26" ) );
+
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ).hashCode(), GpgVersion.parse( "2.2.10" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ).hashCode(), GpgVersion.parse( "2.0.26" ).hashCode() );
+
+        assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.0" ) );

Review comment:
       can you also test that hashcodes are not equal here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-gpg-plugin] elharo commented on a change in pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Posted by GitBox <gi...@apache.org>.
elharo commented on a change in pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12#discussion_r583832637



##########
File path: src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java
##########
@@ -48,4 +50,22 @@ public void testOpposite()
         assertFalse( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" )
                 .isBefore( GpgVersion.parse( "2.0.26" ) ) );
     }
+
+    @Test
+    public void testEquality()
+    {
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ), GpgVersion.parse( "2.2.10" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ), GpgVersion.parse( "2.0.26" ) );
+
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ).hashCode(), GpgVersion.parse( "2.2.10" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ).hashCode(), GpgVersion.parse( "2.0.26" ).hashCode() );
+
+        assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.0" ) );

Review comment:
       It is indeed expected to a very high degree of probability, specifically one in 4.2 billion. It is also expected that hashcodes are deterministic and not random so if this case is not equal now it should not be equal on the next run. Finally it's expected that a good hash algorithm move nearby values far apart so this one should definitely be different. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-gpg-plugin] elharo commented on pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Posted by GitBox <gi...@apache.org>.
elharo commented on pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12#issuecomment-788063633


   running through jenkins: https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-gpg-plugin/job/MGPG-80/


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-gpg-plugin] Syquel commented on a change in pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Posted by GitBox <gi...@apache.org>.
Syquel commented on a change in pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12#discussion_r583828058



##########
File path: src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java
##########
@@ -48,4 +50,22 @@ public void testOpposite()
         assertFalse( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" )
                 .isBefore( GpgVersion.parse( "2.0.26" ) ) );
     }
+
+    @Test
+    public void testEquality()
+    {
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ), GpgVersion.parse( "2.2.10" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ), GpgVersion.parse( "2.0.26" ) );
+
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ).hashCode(), GpgVersion.parse( "2.2.10" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ).hashCode(), GpgVersion.parse( "2.0.26" ).hashCode() );
+
+        assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.0" ) );

Review comment:
       While objects which are equal must produce the same hash code it is neither required nor expected that unequal objects always produce different hash codes.
   `Arrays.hashCode` should already provide a reasonable implementation to minimize hash collisions.
   
   [Object#hashCode JavaDoc](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--):
   > Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.
   > The general contract of hashCode is:
   > [ ... ]
   > * 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.
   > * It is not required that if two objects are unequal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-gpg-plugin] Syquel commented on a change in pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Posted by GitBox <gi...@apache.org>.
Syquel commented on a change in pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12#discussion_r583937880



##########
File path: src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java
##########
@@ -48,4 +50,22 @@ public void testOpposite()
         assertFalse( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" )
                 .isBefore( GpgVersion.parse( "2.0.26" ) ) );
     }
+
+    @Test
+    public void testEquality()
+    {
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.1" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ), GpgVersion.parse( "2.2.10" ) );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ), GpgVersion.parse( "2.0.26" ) );
+
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "2.2.1" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ).hashCode(), GpgVersion.parse( "2.2.10" ).hashCode() );
+        assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ).hashCode(), GpgVersion.parse( "2.0.26" ).hashCode() );
+
+        assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.0" ) );

Review comment:
       I added test statements to assert that the hash codes are different.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org