本文整理汇总了Java中org.jgrapht.graph.SimpleDirectedGraph.addEdge方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleDirectedGraph.addEdge方法的具体用法?Java SimpleDirectedGraph.addEdge怎么用?Java SimpleDirectedGraph.addEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.graph.SimpleDirectedGraph
的用法示例。
在下文中一共展示了SimpleDirectedGraph.addEdge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入方法依赖的package包/类
/**
* This method converts from physical ldap entity format, {@link Hier} to logical {@code org.jgrapht.graph.SimpleDirectedGraph}.
*
* @param hier contains parent-child relationship in preparation to storing in ldap {@code ftRels} attribute of {@code ftHier} object class.
* @return {@code org.jgrapht.graph.SimpleDirectedGraph} containing the vertices of {@code String}, and edges, as {@link Relationship}s that correspond to relational data.
*/
private static SimpleDirectedGraph<String, Relationship> toGraph( Hier hier )
{
LOG.debug( "toGraph" );
SimpleDirectedGraph<String, Relationship> graph =
new SimpleDirectedGraph<>( Relationship.class );
List<Relationship> edges = hier.getRelationships();
if ( edges != null && edges.size() > 0 )
{
for ( Relationship edge : edges )
{
String child = edge.getChild();
String parent = edge.getParent();
try
{
graph.addVertex( child );
graph.addVertex( parent );
graph.addEdge( child, parent, edge );
}
catch (java.lang.IllegalArgumentException e)
{
String error = "toGraph child: " + child + " parent: " + parent + " caught IllegalArgumentException=" + e;
LOG.error( error );
}
LOG.debug( "toGraph child={}, parent={}", child, parent );
}
}
return graph;
}
示例2: sort
import org.jgrapht.graph.SimpleDirectedGraph; //导入方法依赖的package包/类
public List<String> sort(List<Class<?>> classes) throws OrderSortCycleException {
List<String> result = new ArrayList<>();
SimpleDirectedGraph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class);
for (OrderConstraint orderConstraint : getConstraints(classes)) {
graph.addVertex(orderConstraint.getFirst());
graph.addVertex(orderConstraint.getSecond());
graph.addEdge(orderConstraint.getFirst(), orderConstraint.getSecond());
}
CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(graph);
if(!cycleDetector.detectCycles()) {
for (TopologicalOrderIterator<String, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph); iterator.hasNext();) {
result.add(iterator.next());
}
} else {
String cycles = Joiner.on(", ").join(cycleDetector.findCycles());
throw new OrderSortCycleException("The given order constraints contain (at least one) cycle. Cycles can only "
+ "be caused by static references because we have single inherintance only in Java (involved classes: '" + cycles + "').");
}
return result;
}
示例3: addEdge
import org.jgrapht.graph.SimpleDirectedGraph; //导入方法依赖的package包/类
/**
* This method is synchronized and adds an edge and its associated vertices to simple directed graph stored in static memory of this process.
*
* @param graph synchronized parameter contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}.
* @param relation contains parent-child relationship targeted for addition.
* @return {@code org.jgrapht.graph.SimpleDirectedGraph} containing the vertices of {@code String}, and edges, as {@link Relationship}s that correspond to relational data.
*/
private static void addEdge( SimpleDirectedGraph<String, Relationship> graph, Relationship relation )
{
LOG.debug( "addEdge" );
synchronized ( graph )
{
graph.addVertex( relation.getChild().toUpperCase() );
graph.addVertex( relation.getParent().toUpperCase() );
graph.addEdge( relation.getChild().toUpperCase(), relation.getParent().toUpperCase(), relation );
}
}
示例4: toGraphNotUsed
import org.jgrapht.graph.SimpleDirectedGraph; //导入方法依赖的package包/类
/**
* @param hier
* @return
* @throws org.apache.directory.fortress.core.SecurityException
*
*/
public static SimpleDirectedGraph<String, Relationship> toGraphNotUsed(Hier hier)
{
LOG.info("toGraphX");
SimpleDirectedGraph<String, Relationship> graph =
new SimpleDirectedGraph<>(Relationship.class);
//List<String> roles = hier.getRoles();
//if (roles != null)
//{
// for (String role : roles)
// {
// graph.addVertex(role);
// }
//}
List<Relationship> edges = hier.getRelationships();
if (edges != null && edges.size() > 0)
{
for (Relationship edge : edges)
{
String child = edge.getChild();
String parent = edge.getParent();
graph.addVertex(child);
graph.addVertex(parent);
graph.addEdge(child, parent, edge);
if (LOG.isDebugEnabled())
LOG.debug("toGraphX child=" + child + " parent=" + parent);
}
}
return graph;
}
示例5: buildModuleDependencyGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入方法依赖的package包/类
/**
* Build a graph containing all module dependencies
*/
private SimpleDirectedGraph<ModuleModel, Edge> buildModuleDependencyGraph() {
SimpleDirectedGraph<ModuleModel, Edge> g = buildExportGraph();
// add import dependencies
for (ModuleModel module : modules.values()) {
for (ModuleModel imported : module.importedModules) {
g.addEdge(module, imported);
}
}
return g;
}