
de.uni.freiburg.iig.telematik.jagal.graph.abstr.EdgeContainer Maven / Gradle / Ivy
package de.uni.freiburg.iig.telematik.jagal.graph.abstr;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import de.uni.freiburg.iig.telematik.jagal.graph.Edge;
/**
* This class maintains incoming and outgoing edges and is used in graph implementations.
*
* @author Thomas Stocker
*
* @param Edge Type
*/
public class EdgeContainer>{
/**
* Incoming edges.
*/
private ArrayList incoming = new ArrayList();
/**
* Outgoing edges.
*/
private ArrayList outgoing = new ArrayList();
/**
* Returns an unmodifiable version of the incoming edges.
* @return All incoming edges.
*/
public List getIncomingEdges(){
return Collections.unmodifiableList(incoming);
}
/**
* Returns an unmodifiable version of the outgoing edges.
* @return All outgoing edges.
*/
public List getOutgoingEdges(){
return new ArrayList(outgoing);
}
/**
* Adds an incoming edge.
* @param e Incoming edge.
*/
public void addIncomingEdge(E e){
incoming.add(e);
}
/**
* Adds an outgoing edge.
* @param e Outgoing edge.
*/
public void addOutgoingEdge(E e){
outgoing.add(e);
}
/**
* Removes an incoming edge.
* @param e Incoming edge to be removed.
*/
public void removeIncomingEdge(E e){
incoming.remove(e);
}
/**
* Removes an outgoing edge.
* @param e Outgoing edge to be removed.
*/
public void removeOutgoingEdge(E e){
outgoing.remove(e);
}
/**
* checks if there are incoming edges.
* @return true
if there are incoming edges;
* false
otherwise.
*/
public boolean hasIncomingEdges(){
return !incoming.isEmpty();
}
/**
* checks if there are outgoing edges.
* @return true
if there are outgoing edges;
* false
otherwise.
*/
public boolean hasOutgoingEdges(){
return !outgoing.isEmpty();
}
/**
* Checks if there are edges at all.
* @return true
if there are edges;
* false
otherwise.
*/
public boolean isEmpty(){
return !hasIncomingEdges() && !hasOutgoingEdges();
}
@Override
public String toString(){
StringBuilder builder = new StringBuilder();
builder.append("Incoming:");
builder.append('\n');
for(E incomingEdge: incoming){
builder.append(incomingEdge);
builder.append('\n');
}
builder.append("Outgoing:");
builder.append('\n');
for(E outgoingEdge: outgoing){
builder.append(outgoingEdge);
builder.append('\n');
}
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy