]> source.dussan.org Git - pf4j.git/commitdiff
adds equals/hashCode to some data classes (#352)
authorCameron Fieber <cameron@fieber.ca>
Wed, 4 Dec 2019 12:00:11 +0000 (04:00 -0800)
committerDecebal Suiu <decebal.suiu@gmail.com>
Wed, 4 Dec 2019 12:00:11 +0000 (14:00 +0200)
pf4j/src/main/java/org/pf4j/DefaultPluginDescriptor.java
pf4j/src/main/java/org/pf4j/PluginClasspath.java
pf4j/src/main/java/org/pf4j/PluginDependency.java
pf4j/src/test/java/org/pf4j/PluginDependencyTest.java

index b899a171a0fe722b55e48c125f3292dc94898ab5..59036620877b08ebc3fd587b9b01e8125ae57023 100644 (file)
@@ -18,6 +18,7 @@ package org.pf4j;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * @author Decebal Suiu
@@ -196,4 +197,23 @@ public class DefaultPluginDescriptor implements PluginDescriptor {
         return this;
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof DefaultPluginDescriptor)) return false;
+        DefaultPluginDescriptor that = (DefaultPluginDescriptor) o;
+        return Objects.equals(pluginId, that.pluginId) &&
+            Objects.equals(pluginDescription, that.pluginDescription) &&
+            Objects.equals(pluginClass, that.pluginClass) &&
+            Objects.equals(version, that.version) &&
+            Objects.equals(requires, that.requires) &&
+            Objects.equals(provider, that.provider) &&
+            dependencies.equals(that.dependencies) &&
+            Objects.equals(license, that.license);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(pluginId, pluginDescription, pluginClass, version, requires, provider, dependencies, license);
+    }
 }
index 757740ce389752adb92aa33e5d83845ac28d7583..62a2f90e1e4cc3a38cd6b4d61f6968078f92a350 100644 (file)
@@ -18,6 +18,7 @@ package org.pf4j;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Objects;
 import java.util.Set;
 
 /**
@@ -60,4 +61,17 @@ public class PluginClasspath {
         return this;
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof PluginClasspath)) return false;
+        PluginClasspath that = (PluginClasspath) o;
+        return classesDirectories.equals(that.classesDirectories) &&
+            jarsDirectories.equals(that.jarsDirectories);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(classesDirectories, jarsDirectories);
+    }
 }
index 85d3c226916b35e4105a3489bad442d23c5194bf..fbb081d9f7e632b2cd70724da3bff61f11ff164d 100644 (file)
@@ -15,6 +15,8 @@
  */
 package org.pf4j;
 
+import java.util.Objects;
+
 /**
  * @author Decebal Suiu
  */
@@ -61,4 +63,18 @@ public class PluginDependency {
             + optional + "]";
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof PluginDependency)) return false;
+        PluginDependency that = (PluginDependency) o;
+        return optional == that.optional &&
+            pluginId.equals(that.pluginId) &&
+            pluginVersionSupport.equals(that.pluginVersionSupport);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(pluginId, pluginVersionSupport, optional);
+    }
 }
index a351c4b983f9b68d14ffb0d28b8abca807274187..c605d237e44e103b0f79388eef8cefbb6d1934d5 100644 (file)
@@ -33,32 +33,44 @@ public class PluginDependencyTest {
     @Test
     public void testPluginDependecy() {
         PluginDependency instance = new PluginDependency("test");
+        PluginDependency instance2 = new PluginDependency("test");
+        assertEquals(instance, instance2);
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
         assertFalse(instance.isOptional());
 
         instance = new PluginDependency("test@");
+        instance2 = new PluginDependency("test@");
+        assertEquals(instance, instance2);
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
         assertFalse(instance.isOptional());
 
         instance = new PluginDependency("test?");
+        instance2 = new PluginDependency("test?");
+        assertEquals(instance, instance2);
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
         assertTrue(instance.isOptional());
 
         instance = new PluginDependency("test?@");
+        instance2 = new PluginDependency("test?@");
+        assertEquals(instance, instance2);
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
         assertTrue(instance.isOptional());
 
         instance = new PluginDependency("test@1.0");
+        instance2 = new PluginDependency("test@1.0");
+        assertEquals(instance, instance2);
         assertEquals("test", instance.getPluginId());
         assertEquals("1.0", instance.getPluginVersionSupport());
         assertFalse(instance.isOptional());
         assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=false]", instance.toString());
 
         instance = new PluginDependency("test?@1.0");
+        instance2 = new PluginDependency("test?@1.0");
+        assertEquals(instance, instance2);
         assertEquals("test", instance.getPluginId());
         assertEquals("1.0", instance.getPluginVersionSupport());
         assertTrue(instance.isOptional());