package sds.assemble.controlflow;

import static sds.assemble.controlflow.CFEdgeType.Normal;
import static sds.assemble.controlflow.CFEdgeType.JumpCatch;
import static sds.assemble.controlflow.CFEdgeType.JumpFinally;

/**
 * This class is for edge of control flow graph.
 * @author inagaki
 */
public class CFEdge {
	private CFNode dest;
	private CFNode source;
	private CFEdgeType type;

	/**
	 * constructor.
	 * @param source source node
	 * @param dest destination node
	 */
	public CFEdge(CFNode source, CFNode dest) {
		this(source, dest, Normal);
	}

	/**
	 * constructor.
	 * @param source source node
	 * @param dest destination node
	 * @param type edge type
	 */
	public CFEdge(CFNode source, CFNode dest, CFEdgeType type) {
		this.source = source;
		this.dest = dest;
		this.type = type;
	}

	/**
	 * returns destination node of this edge.
	 * @return destination node
	 */
	public CFNode getDest() {
		return dest;
	}

	/**
	 * returns source node of this edge.
	 * @return source node
	 */
	public CFNode getSource() {
		return source;
	}

	@Override
	public int hashCode() {
		return source.hashCode() + dest.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof CFEdge)) {
			return false;
		}
		CFEdge edge = (CFEdge)obj;
		CFNode s = edge.getSource();
		CFNode d = edge.getDest();
		return source.getStart().getPc() == s.getStart().getPc()
			&& source.getEnd().getPc()   == s.getEnd().getPc()
			&& dest.getStart().getPc()   == d.getStart().getPc()
			&& dest.getEnd().getPc()     == d.getEnd().getPc();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(dest.getStart().getPc())
			.append("-").append(dest.getEnd().getPc())
			.append("(").append(type).append(")");
		return sb.toString();
	}
}
@@ -1043,24 +1043,134 @@
 source;%0A%09%7D%0A%0A
+%09/**%0A%09 * returns this edge type.%0A%09 * @return edge type%0A%09 */%0A%09public CFEdgeType getType() %7B%0A%09%09return type;%0A%09%7D%0A%0A
 %09@Override%0A%09

add method for returing edge type.