Selector and Group Object Duplicate Validation
Change-Id: I0872bb26b245b38294bfeae9d886108477310de4
diff --git a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Group.java b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Group.java
index fd11a1f..12dac2a 100644
--- a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Group.java
+++ b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Group.java
@@ -23,6 +23,7 @@
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* Immutable class representing a Group with fields and an action.
@@ -61,6 +62,39 @@
return action;
}
+ /**
+ * Checks if this Group is equal to another object.
+ * The result is true if and only if the argument is not null and is a Group object with same fields and action.
+ *
+ * @param obj the object to compare this Group against
+ * @return true if the given object represents a Group equivalent to this Group, false otherwise
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ Group group = (Group) obj;
+ return Objects.equals(fields, group.fields) && Objects.equals(action, group.action);
+ }
+
+ /**
+ * Returns a hash code value for the Group.
+ * This method is supported for the benefit of hash tables such as those provided by HashMap.
+ *
+ * @return a hash code value for this Group
+ */
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 59 * result + (fields != null ? fields.hashCode() : 0);
+ result = 59 * result + (action != null ? action.hashCode() : 0);
+ return result;
+ }
+
/**
* Static method to create a new Builder instance.
*
diff --git a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Selector.java b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Selector.java
index c1fdebc..4e65699 100644
--- a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Selector.java
+++ b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Selector.java
@@ -23,6 +23,7 @@
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* Immutable class representing a Selector with fields and an action.
@@ -62,6 +63,40 @@
}
/**
+ * Checks if this Selector is equal to another object.
+ * The result is true if and only if the argument is not null and is a Selector object with same fields and action.
+ *
+ * @param obj the object to compare this Selector against
+ * @return true if the given object represents a Selector equivalent to this Selector, false otherwise
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ Selector selector = (Selector) obj;
+ return Objects.equals(fields, selector.fields) &&
+ Objects.equals(action, selector.action);
+ }
+
+ /**
+ * Returns a hash code value for the Selector.
+ * This method is supported for the benefit of hash tables such as those provided by HashMap.
+ *
+ * @return a hash code value for this Selector
+ */
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 59 * result + (fields != null ? fields.hashCode() : 0);
+ result = 59 * result + (action != null ? action.hashCode() : 0);
+ return result;
+ }
+
+ /**
* Static method to create a new Builder instance.
*
* @return A new Builder for creating a Selector instance.