package org.datadog.jenkins.plugins.datadog.clients;

import java.util.Collections;
import java.util.List;

public class DatadogMetric {
    private String name = null;
    private double value;
    private String hostname = null;
    private List<String> tags = null;

    DatadogMetric(String name, double value, String hostname, List<String> tags) {
        this.name = name;
        this.value = value;
        this.hostname = hostname;
        this.tags = tags;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof DatadogMetric)) return false;

        DatadogMetric that = (DatadogMetric) o;

        if (Double.compare(that.value, value) != 0) return false;
        return this.same(that);
    }

    public boolean same(DatadogMetric o) {
        if (name != null ? !name.equals(o.name) : o.name != null) return false;
        if (hostname != null ? !hostname.equals(o.hostname) : o.hostname != null) return false;
        Collections.sort(tags);
        Collections.sort(o.tags);
        return tags != null ? tags.toString().equals(o.tags.toString()) : o.tags == null;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = name != null ? name.hashCode() : 0;
        temp = Double.doubleToLongBits(value);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (hostname != null ? hostname.hashCode() : 0);
        result = 31 * result + (tags != null ? tags.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Metric{" +
                "name='" + name + '\'' +
                ", value=" + value +
                ", hostname='" + hostname + '\'' +
                ", tags=" + tags +
                '}';
    }

    public String getName() {
        return name;
    }

    public double getValue() {
        return value;
    }

    public String getHostname() {
        return hostname;
    }

    public List<String> getTags() {
        return tags;
    }
}

@@ -759,32 +759,292 @@
 e(that);%0A    %7D%0A%0A
+    /**%0A     * This method check that this object and the one passed as parameter are equal to the exception of the value field.%0A     * @param m DatadogMetric object to compare to.%0A     * @return true is both DatadogMetric are the same otherwise false%0A     */%0A
     public boole
@@ -1065,21 +1065,94 @@
 gMetric 
-o
+m
 ) %7B%0A
+        if (this == m) return true;%0A        if (m == null) return false;%0A
         
@@ -1183,17 +1183,17 @@
 .equals(
-o
+m
 .name) :
@@ -1193,17 +1193,17 @@
 name) : 
-o
+m
 .name !=
@@ -1271,17 +1271,17 @@
 .equals(
-o
+m
 .hostnam
@@ -1285,17 +1285,17 @@
 name) : 
-o
+m
 .hostnam
@@ -1311,32 +1311,90 @@
 ) return false;%0A
+        if (tags != null && m.tags == null) return false;%0A
         Collecti
@@ -1434,17 +1434,17 @@
 ns.sort(
-o
+m
 .tags);%0A
@@ -1496,17 +1496,17 @@
 .equals(
-o
+m
 .tags.to
@@ -1517,17 +1517,17 @@
 ng()) : 
-o
+m
 .tags ==

clean up