1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
package net.sourceforge.combean.graph.prop.statics; |
23 | |
|
24 | |
import net.sourceforge.combean.interfaces.graph.EdgeIterator; |
25 | |
import net.sourceforge.combean.interfaces.graph.Graph; |
26 | |
import net.sourceforge.combean.interfaces.graph.Node; |
27 | |
import net.sourceforge.combean.interfaces.graph.NodeIterator; |
28 | |
import net.sourceforge.combean.interfaces.graph.containers.FixedPath; |
29 | |
import net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp; |
30 | |
import net.sourceforge.combean.interfaces.graph.prop.OutgoingEdgeNeighborhoodGraphProp; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class GraphStringifier { |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public static String convertToString(FixedPath path) { |
48 | 0 | StringBuffer result = new StringBuffer(); |
49 | 0 | result.append("path {"); |
50 | 0 | NodeIterator itPathNodes = path.getNodeIterator(); |
51 | 0 | EdgeIterator itPathEdges = path.getEdgeIterator(); |
52 | 0 | while (itPathEdges.hasNext()) { |
53 | 0 | result.append("node {"); |
54 | 0 | result.append(itPathNodes.next()); |
55 | 0 | result.append("} edge {"); |
56 | 0 | result.append(itPathEdges.next()); |
57 | 0 | result.append("} "); |
58 | |
} |
59 | 0 | result.append("node {"); |
60 | 0 | result.append(itPathNodes.next()); |
61 | 0 | result.append("}"); |
62 | 0 | result.append("}"); |
63 | |
|
64 | 0 | return result.toString(); |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public static String convertEdgeIterationToString(EdgeIterator itEdges) { |
75 | 0 | StringBuffer result = new StringBuffer(); |
76 | |
|
77 | 0 | result.append("edge iterator contents {"); |
78 | 0 | while (itEdges.hasNext()) { |
79 | 0 | result.append(" edge {"); |
80 | 0 | result.append(itEdges.next()); |
81 | 0 | result.append("}"); |
82 | |
} |
83 | |
|
84 | 0 | return result.toString(); |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public static String convertOutgoingAdjacencyListsToString(Graph g) { |
95 | 0 | OutgoingEdgeNeighborhoodGraphProp outG = (OutgoingEdgeNeighborhoodGraphProp) |
96 | |
GraphPropertyInitializer.requireGraphProperty(g, |
97 | |
OutgoingEdgeNeighborhoodGraphProp.class); |
98 | 0 | GlobalNodesGraphProp globNodes = (GlobalNodesGraphProp) |
99 | |
GraphPropertyInitializer.requireGraphProperty(g, |
100 | |
GlobalNodesGraphProp.class); |
101 | |
|
102 | 0 | StringBuffer result = new StringBuffer(); |
103 | 0 | result.append("graph outgoing edges {"); |
104 | |
|
105 | 0 | NodeIterator itAllNodes = globNodes.getAllNodesIterator(); |
106 | 0 | while (itAllNodes.hasNext()) { |
107 | 0 | Node v = itAllNodes.next(); |
108 | 0 | result.append("node {"); |
109 | 0 | result.append(v); |
110 | 0 | result.append("} outgoing edges {"); |
111 | 0 | EdgeIterator outEdges = outG.getOutgoingEdges(v); |
112 | 0 | result.append(convertEdgeIterationToString(outEdges)); |
113 | 0 | result.append("} "); |
114 | 0 | } |
115 | 0 | result.append("}"); |
116 | |
|
117 | 0 | return result.toString(); |
118 | |
} |
119 | |
} |