Commit c0ffc4b4 authored by Roland Kluge's avatar Roland Kluge
Browse files

Add Graph#getEdges to allow for multi edges

parent 5099ee44
...@@ -22,6 +22,7 @@ package de.tudarmstadt.maki.simonstrator.api.common.graph; ...@@ -22,6 +22,7 @@ package de.tudarmstadt.maki.simonstrator.api.common.graph;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -327,6 +328,17 @@ public class BasicGraph implements Graph { ...@@ -327,6 +328,17 @@ public class BasicGraph implements Graph {
return null; return null;
} }
@Override
public Collection<IEdge> getEdges(INodeID from, INodeID to) {
final List<IEdge> resultSet = new ArrayList<>();
for (IEdge edge : edges) {
if (edge.toId().equals(to) && edge.fromId().equals(from)) {
resultSet.add(edge);
}
}
return resultSet;
}
@Override @Override
public IEdge getEdge(EdgeID edgeID) { public IEdge getEdge(EdgeID edgeID) {
return this.edgesById.get(edgeID); return this.edgesById.get(edgeID);
......
...@@ -231,7 +231,7 @@ public interface Graph extends Cloneable { ...@@ -231,7 +231,7 @@ public interface Graph extends Cloneable {
public INode getNode(INodeID nodeId); public INode getNode(INodeID nodeId);
/** /**
* Returns the edge (if present) between from and to, null otherwise * Returns some edge (if present) between from and to, null otherwise
* *
* @param from * @param from
* @param to * @param to
...@@ -239,6 +239,15 @@ public interface Graph extends Cloneable { ...@@ -239,6 +239,15 @@ public interface Graph extends Cloneable {
*/ */
public IEdge getEdge(INodeID from, INodeID to); public IEdge getEdge(INodeID from, INodeID to);
/**
* Returns all edges (if present) between from and to, null otherwise
*
* @param from
* @param to
* @return edge or null
*/
Collection<IEdge> getEdges(INodeID from, INodeID to);
/** /**
* Returns the edge with the given ID. * Returns the edge with the given ID.
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment