Skip to content
Snippets Groups Projects
Vertex.java 1.19 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 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.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
}