aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCameron Fieber <cameron@fieber.ca>2019-12-04 04:00:11 -0800
committerDecebal Suiu <decebal.suiu@gmail.com>2019-12-04 14:00:11 +0200
commita80ea7adcfc86a7042ec0cf772c8821a36967127 (patch)
tree2f1b3f4bfd92149962fea1c3854840c4dd921018
parentdda9f38cd059472444dd432be09df73a31cd8db5 (diff)
downloadpf4j-a80ea7adcfc86a7042ec0cf772c8821a36967127.tar.gz
pf4j-a80ea7adcfc86a7042ec0cf772c8821a36967127.zip
adds equals/hashCode to some data classes (#352)
-rw-r--r--pf4j/src/main/java/org/pf4j/DefaultPluginDescriptor.java20
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginClasspath.java14
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginDependency.java16
-rw-r--r--pf4j/src/test/java/org/pf4j/PluginDependencyTest.java12
4 files changed, 62 insertions, 0 deletions
diff --git a/pf4j/src/main/java/org/pf4j/DefaultPluginDescriptor.java b/pf4j/src/main/java/org/pf4j/DefaultPluginDescriptor.java
index b899a17..5903662 100644
--- a/pf4j/src/main/java/org/pf4j/DefaultPluginDescriptor.java
+++ b/pf4j/src/main/java/org/pf4j/DefaultPluginDescriptor.java
@@ -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);
+ }
}
diff --git a/pf4j/src/main/java/org/pf4j/PluginClasspath.java b/pf4j/src/main/java/org/pf4j/PluginClasspath.java
index 757740c..62a2f90 100644
--- a/pf4j/src/main/java/org/pf4j/PluginClasspath.java
+++ b/pf4j/src/main/java/org/pf4j/PluginClasspath.java
@@ -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);
+ }
}
diff --git a/pf4j/src/main/java/org/pf4j/PluginDependency.java b/pf4j/src/main/java/org/pf4j/PluginDependency.java
index 85d3c22..fbb081d 100644
--- a/pf4j/src/main/java/org/pf4j/PluginDependency.java
+++ b/pf4j/src/main/java/org/pf4j/PluginDependency.java
@@ -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);
+ }
}
diff --git a/pf4j/src/test/java/org/pf4j/PluginDependencyTest.java b/pf4j/src/test/java/org/pf4j/PluginDependencyTest.java
index a351c4b..c605d23 100644
--- a/pf4j/src/test/java/org/pf4j/PluginDependencyTest.java
+++ b/pf4j/src/test/java/org/pf4j/PluginDependencyTest.java
@@ -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());