Commit bc8fe4b7 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Work: simplify equals and make id final.

parent 0299a6b7
Loading
Loading
Loading
Loading
+8 −20
Original line number Diff line number Diff line
/*
 * EDG, a library to generate and slice Expression Dependence Graphs.
 * Copyright (c) 2021. David Insa, Sergio Pérez, Josep Silva, Salvador Tamarit.
 * Copyright (c) 2021-2023. David Insa, Carlos Galindo, Sergio Pérez, Josep Silva, Salvador Tamarit.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
@@ -28,16 +28,12 @@ public class EdgeWork extends Work
{
	private final Edge currentEdge;

	public EdgeWork(EDG edg, Node initialNode, Edge currentEdge, EdgeList traversed, Constraints constraints)
	{
		super(initialNode, constraints, traversed);

		this.id = edg.getEdgeSource(currentEdge).getId() + "->" + edg.getEdgeTarget(currentEdge).getId();
	public EdgeWork(EDG edg, Node initialNode, Edge currentEdge, EdgeList traversed, Constraints constraints) {
		super(initialNode, constraints, traversed, edg.getEdgeSource(currentEdge).getId() + "->" + edg.getEdgeTarget(currentEdge).getId());
		this.currentEdge = currentEdge;
	}

	public EdgeWork(EDG edg, Node initialNode, Edge currentEdge, Constraints constraints)
	{
	public EdgeWork(EDG edg, Node initialNode, Edge currentEdge, Constraints constraints) {
		this(edg, initialNode, currentEdge, EdgeList.emptyList(), constraints);
	}

@@ -46,19 +42,11 @@ public class EdgeWork extends Work
		return this.currentEdge;
	}

	public boolean equals(Object object)
	{
	public boolean equals(Object object) {
		if (object == this)
			return true;
		if (!(object instanceof EdgeWork))
			return false;

		final EdgeWork edgeWork = (EdgeWork) object;

		if (!super.equals(edgeWork))
			return false;
		if (this.currentEdge != edgeWork.currentEdge)
			return false;
		return true;
		return object instanceof EdgeWork
				&& super.equals(object)
				&& this.currentEdge == ((EdgeWork) object).currentEdge;
	}
}
 No newline at end of file
+5 −13
Original line number Diff line number Diff line
/*
 * EDG, a library to generate and slice Expression Dependence Graphs.
 * Copyright (c) 2021. David Insa, Sergio Pérez, Josep Silva, Salvador Tamarit.
 * Copyright (c) 2021-2023. David Insa, Carlos Galindo, Sergio Pérez, Josep Silva, Salvador Tamarit.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
@@ -31,9 +31,7 @@ public class NodeWork extends Work

	public NodeWork(Node initialNode, Node currentNode, EdgeList traversed, Constraints constraints, Edge.Type type)
	{
		super(initialNode, constraints, traversed);

		this.id = String.valueOf(currentNode.getId());
		super(initialNode, constraints, traversed, String.valueOf(currentNode.getId()));
		this.currentNode = currentNode;
		this.previousEdgeType = type;
	}
@@ -59,14 +57,8 @@ public class NodeWork extends Work
	{
		if (object == this)
			return true;
		if (!(object instanceof NodeWork))
			return false;

		final NodeWork nodeWork = (NodeWork) object;

		if (!super.equals(nodeWork))
			return false;
		return this.currentNode == nodeWork.currentNode &&
				previousEdgeType == nodeWork.previousEdgeType;
		return object instanceof NodeWork && super.equals(object)
				&& currentNode == ((NodeWork) object).currentNode
				&& previousEdgeType == ((NodeWork) object).previousEdgeType;
	}
}
 No newline at end of file
+8 −25
Original line number Diff line number Diff line
/*
 * EDG, a library to generate and slice Expression Dependence Graphs.
 * Copyright (c) 2021. David Insa, Sergio Pérez, Josep Silva, Salvador Tamarit.
 * Copyright (c) 2021-2023. David Insa, Carlos Galindo, Sergio Pérez, Josep Silva, Salvador Tamarit.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
@@ -28,21 +28,17 @@ import java.util.List;

public abstract class Work
{
	protected String id;
	protected final String id;
	protected final Node initialNode;
	protected final Constraints constraints;
	protected final EdgeList traversedEdges; // Use LinkedHashSet
	protected final EdgeList traversedEdges;

	public Work(Node initialNode, Constraints constraints, EdgeList traversedEdges)
	public Work(Node initialNode, Constraints constraints, EdgeList traversedEdges, String id)
	{
		this.initialNode = initialNode;
		this.constraints = constraints;
		this.traversedEdges = traversedEdges;
	}

	public Work(Node initialNode, Constraints constraints)
	{
		this(initialNode, constraints, EdgeList.emptyList());
		this.id = id;
	}

	public String getId()
@@ -74,23 +70,10 @@ public abstract class Work
		return lastLoop;
	}


	public boolean equals(Object object)
	{
		if (object == this)
			return true;
		if (!(object instanceof Work))
			return false;

		final Work work = (Work) object;

		// I think the formal out is not important
//		if (this.initialNode != work.initialNode)
//			return false;
		if (!this.constraints.equals(work.constraints))
			return false;
		return true;
	public boolean equals(Object object) {
		return object instanceof Work && this.constraints.equals(((Work) object).constraints);
	}

	public int hashCode()
	{
		return this.id.hashCode() + this.constraints.hashCode();