Skip to content
Vertex.java 1.86 KiB
Newer Older
Javier Costa's avatar
Javier Costa committed
package tfm.nodes;
Javier Costa's avatar
Javier Costa committed

Javier Costa's avatar
Javier Costa committed
import com.sun.corba.se.spi.ior.ObjectKey;
Javier Costa's avatar
Javier Costa committed
import tfm.arcs.data.ArcData;
import tfm.graphs.Graph;
Javier Costa's avatar
Javier Costa committed

Javier Costa's avatar
Javier Costa committed
import java.util.Objects;
Javier Costa's avatar
Javier Costa committed
import java.util.stream.Collectors;

public class Vertex extends edg.graphlib.Vertex<String, ArcData> {

Javier Costa's avatar
Javier Costa committed
    private Integer fileLineNumber;
Javier Costa's avatar
Javier Costa committed
    public Vertex(Graph.VertexId id, String instruction) {
        this(id, instruction, null);
    }

    public Vertex(Graph.VertexId id, String instruction, Integer fileLineNumber) {
Javier Costa's avatar
Javier Costa committed
        super(id.toString(), instruction);
Javier Costa's avatar
Javier Costa committed
        this.fileLineNumber = fileLineNumber;
Javier Costa's avatar
Javier Costa committed
    }

    public int getId() {
        return Integer.parseInt(getName());
    }

    public String toString() {
        return String.format("Vertex{id: %s, data: '%s', in: %s, out: %s}",
                getName(),
                getData(),
                getIncomingArrows().stream().map(arrow -> arrow.getFrom().getName()).collect(Collectors.toList()),
                getOutgoingArrows().stream().map(arc -> arc.getTo().getName()).collect(Collectors.toList()));
    }

    public Optional<Integer> getFileLineNumber() {
Javier Costa's avatar
Javier Costa committed
        return Optional.ofNullable(fileLineNumber);
    }

    public void setFileLineNumber(Integer fileLineNumber) {
        this.fileLineNumber = fileLineNumber;
    }
Javier Costa's avatar
Javier Costa committed

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

        if (!(o instanceof Vertex))
            return false;

        Vertex other = (Vertex) o;

        return Objects.equals(getData(), other.getData())
                && Objects.equals(getIncomingArrows(), other.getIncomingArrows())
                && Objects.equals(getOutgoingArrows(), other.getOutgoingArrows())
                && Objects.equals(fileLineNumber, other.fileLineNumber);
                // && Objects.equals(getName(), other.getName()) ID IS ALWAYS UNIQUE, SO IT WILL NEVER BE THE SAME
    }
Javier Costa's avatar
Javier Costa committed
}