Commit eca0b61b authored by Javier Costa's avatar Javier Costa
Browse files

Equals and hashCode in DataDependencyArc

parent 17af8cad
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import org.jgrapht.io.DefaultAttribute;
import tfm.arcs.Arc;

import java.util.Map;
import java.util.Objects;

/**
 * An arc used in the {@link tfm.graphs.PDG} and {@link tfm.graphs.SDG},
@@ -33,5 +34,27 @@ public class DataDependencyArc extends Arc {
        map.put("color", DefaultAttribute.createAttribute("red"));
        return map;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (!(o instanceof DataDependencyArc)) {
            return false;
        }

        DataDependencyArc other = (DataDependencyArc) o;

        return Objects.equals(variable, other.variable)
                && Objects.equals(getSource(), other.getSource())
                && Objects.equals(getTarget(), other.getTarget());
    }

    @Override
    public int hashCode() {
        return Objects.hash(variable, getSource(), getTarget());
    }
}