graph.impl.DirectedAdjacencyListGraph Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of astra-compiler Show documentation
Show all versions of astra-compiler Show documentation
Core compiler artifact for the ASTRA Language
package graph.impl;
import java.util.LinkedList;
import graph.core.DirectedGraph;
import graph.core.Edge;
import graph.core.Vertex;
public class DirectedAdjacencyListGraph extends AdjacencyListGraph implements DirectedGraph {
@Override
public boolean isSource(Edge edge, Vertex vertex) {
return ((AdjacencyListEdge) edge).start == vertex;
}
@Override
public boolean isTarget(Edge edge, Vertex vertex) {
return ((AdjacencyListEdge) edge).end == vertex;
}
@Override
public Vertex source(Edge edge) {
return ((AdjacencyListEdge) edge).start;
}
@Override
public Vertex target(Edge edge) {
return ((AdjacencyListEdge) edge).end;
}
@Override
public LinkedList> outEdges(Vertex vertex) {
LinkedList> list = new LinkedList>();
for (Edge edge : incidentEdges(vertex)) {
if (isSource(edge, vertex)) {
list.add(edge);
}
}
return list;
}
@Override
public LinkedList> inEdges(Vertex vertex) {
LinkedList> list = new LinkedList>();
for (Edge edge : incidentEdges(vertex)) {
if (isTarget(edge, vertex)) {
list.add(edge);
}
}
return list;
}
}