Sort and Condition Object Duplicate Validation
Change-Id: I8a116e38161234faa49ee3305ae4a8f3be4568b8
diff --git a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Condition.java b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Condition.java
index e734e1f..f7414d9 100644
--- a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Condition.java
+++ b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Condition.java
@@ -21,6 +21,7 @@
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
+import java.util.Objects;
/**
* Immutable class representing a condition with name, field, match, value, action, and aggregation.
@@ -104,6 +105,52 @@
}
/**
+ * Checks if this Condition is equal to another object.
+ * The result is true if and only if the argument is not null and is a Condition object that
+ * has the same values for all fields.
+ *
+ * @param obj the object to compare this Condition against
+ * @return true if the given object represents a Condition equivalent to this one, false otherwise
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Condition other = (Condition) obj;
+ return Objects.equals(name, other.name)
+ && Objects.equals(field, other.field)
+ && Objects.equals(match, other.match)
+ && Objects.equals(value, other.value)
+ && Objects.equals(action, other.action)
+ && Objects.equals(aggregation, other.aggregation);
+ }
+
+ /**
+ * Returns a hash code value for the Condition.
+ * This method is supported for the benefit of hash tables such as those provided by HashMap.
+ *
+ * @return a hash code value for this Condition
+ */
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 59 * result + (name != null ? name.hashCode() : 0);
+ result = 59 * result + (field != null ? field.hashCode() : 0);
+ result = 59 * result + (match != null ? match.hashCode() : 0);
+ result = 59 * result + (value != null ? value.hashCode() : 0);
+ result = 59 * result + (action != null ? action.hashCode() : 0);
+ result = 59 * result + (aggregation != null ? aggregation.hashCode() : 0);
+ return result;
+ }
+
+ /**
* Static method to create a new Builder instance.
*
* @return A new Builder for creating a Condition instance.
@@ -116,7 +163,6 @@
* Builder class for Condition.
*/
@JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
- @JsonIgnoreProperties(ignoreUnknown = true)
public static class Builder {
private String name;
private String field;
diff --git a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Sort.java b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Sort.java
index 585a6f8..fea91c9 100644
--- a/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Sort.java
+++ b/apps/aiplugin/api/src/main/java/org/onosproject/aiplugin/Sort.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 sorting criteria with fields and an order.
@@ -62,6 +63,39 @@
}
/**
+ * Checks if this Sort is equal to another object.
+ * The result is true if and only if the argument is not null and is a Sort object with same fields and order.
+ *
+ * @param obj the object to compare this Sort against
+ * @return true if the given object represents a Sort equivalent to this Sort, false otherwise
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ Sort selector = (Sort) obj;
+ return Objects.equals(fields, selector.fields) && Objects.equals(order, selector.order);
+ }
+
+ /**
+ * Returns a hash code value for the Sort.
+ * This method is supported for the benefit of hash tables such as those provided by HashMap.
+ *
+ * @return a hash code value for this Sort
+ */
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 59 * result + (fields != null ? fields.hashCode() : 0);
+ result = 59 * result + (order != null ? order.hashCode() : 0);
+ return result;
+ }
+
+ /**
* Static method to create a new Builder instance.
*
* @return A new Builder for creating a Sort instance.