本文整理汇总了Java中org.jgrapht.Graphs.addGraph方法的典型用法代码示例。如果您正苦于以下问题:Java Graphs.addGraph方法的具体用法?Java Graphs.addGraph怎么用?Java Graphs.addGraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.Graphs
的用法示例。
在下文中一共展示了Graphs.addGraph方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.jgrapht.Graphs; //导入方法依赖的package包/类
@Override
public void run() {
try {
synchronized (this) {
LOGGER.info("Establishing inital connection and getting initial graph");
IfmapGraphImpl tmp = DataReciever.getInitialGraph();
mGraph.setLastUpdated(tmp.getLastUpdated());
Graphs.addGraph(mGraph, tmp);
while (!mIsDone) {
if (DataReciever.isUpdateAvailable(mGraph.getLastUpdated())) {
while (DataReciever.isUpdateAvailable(mGraph.getLastUpdated())) {
DataReciever.nextUpdate(mGraph);
}
}
wait(mInterval);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
LOGGER.info("Loop which updates the Graph has ended.");
}
示例2: getCurrentGraph
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Gets the current graph from the visitmeta dataservice.
*
* @return The graph of the newest timestamp.
*/
public static IfmapGraphImpl getCurrentGraph() {
if (!isInitialized) {
LOGGER.warn("DataReciever was not initialized properly. Call init() first! Trying to initilaize now.");
init();
}
String json = visitmeta.get("current");
JsonArray array = parser.parse(json).getAsJsonArray();
IfmapGraphImpl graph = new IfmapGraphImpl();
for (JsonElement elem : array) {
IfmapGraphImpl graphPart = gson.fromJson(elem, IfmapGraphImpl.class);
graph.setLastUpdated(graphPart.getLastUpdated());
Graphs.addGraph(graph, graphPart);
}
LOGGER.debug("Recieved current graph: " + graph);
return graph;
}
示例3: union
import org.jgrapht.Graphs; //导入方法依赖的package包/类
@Override
public G union(G a, G b) {
Graph<V, E> tmp = new GraphUnion<V, E, G>(a, b);
G result = createNew();
Graphs.addGraph(result, tmp);
return result;
}
示例4: mergeGraphs
import org.jgrapht.Graphs; //导入方法依赖的package包/类
private Graph<Node, Edge> mergeGraphs(final List<Graph<Node, Edge>> graphs) {
final Graph<Node, Edge> mergedGraph = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class));
for (final Graph<Node, Edge> graph : graphs) {
Graphs.addGraph(mergedGraph, graph);
}
return mergedGraph;
}
示例5: computeGraphToBeDeleted
import org.jgrapht.Graphs; //导入方法依赖的package包/类
private Graph<Node, Edge> computeGraphToBeDeleted(final Graph<Node, Edge> graph, final String... nodeTypesToRetain) {
final DirectedGraph<Node, Edge> toDelete = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class));
// copy graph to a destination, which we are going to modify
Graphs.addGraph(toDelete, graph);
// remove the nodes, we have to retain from the graph
Graphs.removeVerticesAndPreserveConnectivity(toDelete, v -> shouldRetainNode(v, nodeTypesToRetain));
return toDelete;
}
示例6: removeSpecialEdges
import org.jgrapht.Graphs; //导入方法依赖的package包/类
private DirectedGraph<AttributeRef, ExtendedEdge> removeSpecialEdges(DirectedGraph<AttributeRef, ExtendedEdge> faginDependencyGraph) {
DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph = new DefaultDirectedGraph<AttributeRef, ExtendedEdge>(ExtendedEdge.class);
if (faginDependencyGraph == null) {
return dependencyGraph;
}
Graphs.addGraph(dependencyGraph, faginDependencyGraph);
for (ExtendedEdge edge : faginDependencyGraph.edgeSet()) {
if (edge.isSpecial() && !edge.isNormal()) {
dependencyGraph.removeEdge(edge);
}
}
return dependencyGraph;
}
示例7: toUnionGraph
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Given a collection of {@link KnowledgeGraphPath}s, creates a
* union {@link DirectedGraph}
*
* @param paths
* @return takes the union of the input paths to create a graph
*/
public static DirectedGraph<String, WeightedLabeledEdge> toUnionGraph(Collection<KnowledgeGraphPath> paths)
{
DirectedGraph<String, WeightedLabeledEdge> union =
new DirectedMultigraph<String, WeightedLabeledEdge>(WeightedLabeledEdge.class);
for (KnowledgeGraphPath path : paths)
{
DirectedGraph<String, WeightedLabeledEdge> graph = path.toGraph();
Graphs.addGraph(union, graph);
}
return union;
}
示例8: testJsonDeserialize
import org.jgrapht.Graphs; //导入方法依赖的package包/类
/**
* Tests the parsing of a JSON String
*/
@Test
public void testJsonDeserialize() {
String json = "[{\"timestamp\":1409833398907,\"links\":[{\"identifiers\":[{\"typename\":\"device\",\"properties\":{\"/device/name\":\"freeradius-pdp\"}},{\"typename\":\"ip-address\",\"properties\":{\"/ip-address[@type]\":\"IPv4\",\"/ip-address[@value]\":\"192.168.0.1\"}}],\"metadata\":{\"typename\":\"device-ip\",\"properties\":{\"/meta:device-ip[@ifmap-publisher-id]\":\"test-4b698afc-1732-42e2-a6df-5063467dc836\",\"/meta:device-ip[@ifmap-cardinality]\":\"singleValue\",\"/meta:device-ip[@ifmap-timestamp]\":\"2014-09-04T14:23:08+02:00\",\"/meta:device-ip[@xmlns:meta]\":\"http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2\"}}},{\"identifiers\":[{\"typename\":\"mac-address\",\"properties\":{\"/mac-address[@value]\":\"aa:bb:cc:dd:ee:ff\"}},{\"typename\":\"ip-address\",\"properties\":{\"/ip-address[@type]\":\"IPv4\",\"/ip-address[@value]\":\"192.168.0.1\"}}],\"metadata\":{\"typename\":\"ip-mac\",\"properties\":{\"/meta:ip-mac[@ifmap-cardinality]\":\"multiValue\",\"/meta:ip-mac[@ifmap-publisher-id]\":\"test-4b698afc-1732-42e2-a6df-5063467dc836\",\"/meta:ip-mac[@xmlns:meta]\":\"http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2\",\"/meta:ip-mac/end-time\":\"2014-09-04T22:22:50+02:00\",\"/meta:ip-mac/dhcp-server\":\"ip-mac-cli\",\"/meta:ip-mac/start-time\":\"2014-09-04T14:22:50+02:00\",\"/meta:ip-mac[@ifmap-timestamp]\":\"2014-09-04T14:22:51+02:00\"}}},{\"identifiers\":[{\"typename\":\"device\",\"properties\":{\"/device/name\":\"bronko\"}},{\"typename\":\"ip-address\",\"properties\":{\"/ip-address[@type]\":\"IPv4\",\"/ip-address[@value]\":\"192.168.0.1\"}}],\"metadata\":{\"typename\":\"device-ip\",\"properties\":{\"/meta:device-ip[@ifmap-publisher-id]\":\"test-4b698afc-1732-42e2-a6df-5063467dc836\",\"/meta:device-ip[@ifmap-cardinality]\":\"singleValue\",\"/meta:device-ip[@ifmap-timestamp]\":\"2014-09-04T14:22:33+02:00\",\"/meta:device-ip[@xmlns:meta]\":\"http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2\"}}}]}]";
IfmapGraphImpl graphFromString = new IfmapGraphImpl();
JsonArray array = parser.parse(json).getAsJsonArray();
for (JsonElement elem : array) {
IfmapGraphImpl graphPart = gson.fromJson(elem, IfmapGraphImpl.class);
graphFromString.setLastUpdated(graphPart.getLastUpdated());
Graphs.addGraph(graphFromString, graphPart);
}
IfmapVertexImpl pdp = new IfmapVertexImpl("device", new HashMap<String, String>(), null);
pdp.addProperty("/device/name", "freeradius-pdp");
IfmapVertexImpl bronko = new IfmapVertexImpl("device", new HashMap<String, String>(), null);
bronko.addProperty("/device/name", "bronko");
IfmapVertexImpl ip = new IfmapVertexImpl("ip-address", new HashMap<String, String>(), null);
ip.addProperty("/ip-address[@type]", "IPv4");
ip.addProperty("/ip-address[@value]", "192.168.0.1");
IfmapVertexImpl mac = new IfmapVertexImpl("mac-address", new HashMap<String, String>(), null);
mac.addProperty("/mac-address[@value]", "aa:bb:cc:dd:ee:ff");
MetadataImpl deviceIpPdp = new MetadataImpl("device-ip", new HashMap<String, String>(), null);
deviceIpPdp.addProperty("/meta:device-ip[@ifmap-publisher-id]", "test-4b698afc-1732-42e2-a6df-5063467dc836");
deviceIpPdp.addProperty("/meta:device-ip[@ifmap-timestamp]", "2014-09-04T14:23:08+02:00");
deviceIpPdp.addProperty("/meta:device-ip[@ifmap-cardinality]", "singleValue");
deviceIpPdp.addProperty("/meta:device-ip[@xmlns:meta]",
"http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2");
MetadataImpl ipMac = new MetadataImpl("ip-mac", new HashMap<String, String>(), null);
ipMac.addProperty("/meta:ip-mac[@ifmap-publisher-id]", "test-4b698afc-1732-42e2-a6df-5063467dc836");
ipMac.addProperty("/meta:ip-mac[@ifmap-timestamp]", "2014-09-04T14:22:51+02:00");
ipMac.addProperty("/meta:ip-mac/start-time", "2014-09-04T14:22:50+02:00");
ipMac.addProperty("/meta:ip-mac/end-time", "2014-09-04T22:22:50+02:00");
ipMac.addProperty("/meta:ip-mac/dhcp-server", "ip-mac-cli");
ipMac.addProperty("/meta:ip-mac[@ifmap-cardinality]", "multiValue");
ipMac.addProperty("/meta:ip-mac[@xmlns:meta]", "http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2");
MetadataImpl deviceIpBronko = new MetadataImpl("device-ip", new HashMap<String, String>(), null);
deviceIpBronko.addProperty("/meta:device-ip[@ifmap-publisher-id]", "test-4b698afc-1732-42e2-a6df-5063467dc836");
deviceIpBronko.addProperty("/meta:device-ip[@ifmap-timestamp]", "2014-09-04T14:22:33+02:00");
deviceIpBronko.addProperty("/meta:device-ip[@ifmap-cardinality]", "singleValue");
deviceIpBronko.addProperty("/meta:device-ip[@xmlns:meta]",
"http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2");
IfmapGraphImpl graph = new IfmapGraphImpl();
graph.setLastUpdated(Long.valueOf("1409833398907"));
graph.addVertex(pdp);
graph.addVertex(ip);
graph.addVertex(mac);
graph.addVertex(bronko);
IfmapEdgeImpl e1 = new IfmapEdgeImpl(pdp, ip, deviceIpPdp);
IfmapEdgeImpl e2 = new IfmapEdgeImpl(ip, mac, ipMac);
IfmapEdgeImpl e3 = new IfmapEdgeImpl(bronko, ip, deviceIpBronko);
graph.addEdge(pdp, ip, e1);
graph.addEdge(ip, mac, e2);
graph.addEdge(bronko, ip, e3);
Iterator<IfmapEdge> boing = graphFromString.edgeSet().iterator();
assertEquals(graph, graphFromString);
}