All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graph.impl.DirectedAdjacencyListGraph Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy