21 |
21 |
private final List<VertexDTO> vertices;
|
22 |
22 |
private final List<EdgeDTO> edges;
|
23 |
23 |
private final HashSet<AttributeType> attributeTypes;
|
|
24 |
private final HashSet<String> attributeNames;
|
24 |
25 |
private final HashMap<GraphNode, Integer> remappedVertices;
|
25 |
26 |
|
|
27 |
/**
|
|
28 |
* DOT loader which uses Digraph library
|
|
29 |
*
|
|
30 |
* @param dotInput - Source DOT file
|
|
31 |
*/
|
26 |
32 |
public PaypalDOTLoader(String dotInput) {
|
27 |
33 |
super(dotInput);
|
28 |
34 |
parser = null;
|
... | ... | |
36 |
42 |
edges = new ArrayList<>();
|
37 |
43 |
attributeTypes = new HashSet<>();
|
38 |
44 |
remappedVertices = new HashMap<>();
|
39 |
|
processEdges();
|
|
45 |
attributeNames = new HashSet<>();
|
40 |
46 |
processVertices();
|
|
47 |
processEdges();
|
41 |
48 |
}
|
42 |
49 |
|
|
50 |
/**
|
|
51 |
* Returns list of vertices DTO
|
|
52 |
* @return List of vertices DTO
|
|
53 |
*/
|
43 |
54 |
@Override
|
44 |
55 |
public List<VertexDTO> getVertices() {
|
45 |
56 |
return vertices;
|
46 |
57 |
}
|
47 |
58 |
|
|
59 |
/**
|
|
60 |
* Returns list of edges DTO
|
|
61 |
* @return List of edges DTO
|
|
62 |
*/
|
48 |
63 |
@Override
|
49 |
64 |
public List<EdgeDTO> getEdges() {
|
50 |
65 |
return edges;
|
51 |
66 |
}
|
52 |
67 |
|
|
68 |
/**
|
|
69 |
* Returns list of attribute types
|
|
70 |
* @return List of attribute types
|
|
71 |
*/
|
53 |
72 |
@Override
|
54 |
73 |
public Set<AttributeType> getAttributeTypes() {
|
|
74 |
if(attributeTypes.size() == 0) {
|
|
75 |
for(String attr : attributeNames) {
|
|
76 |
attributeTypes.add(new AttributeType(attr, AttributeDataType.STRING, ""));
|
|
77 |
}
|
|
78 |
}
|
55 |
79 |
return attributeTypes;
|
56 |
80 |
}
|
57 |
81 |
|
|
82 |
/**
|
|
83 |
* Method transforms vertices from GraphNode object to vertex DTO and stores attribute type.
|
|
84 |
* It has to be called before processing edges.
|
|
85 |
*/
|
58 |
86 |
private void processVertices() {
|
59 |
87 |
int id = 0;
|
60 |
88 |
|
61 |
89 |
for(GraphNode node : this.parser.getNodes().values()) {
|
62 |
90 |
HashMap<String, String> attrs = new HashMap<>();
|
63 |
|
for(Map.Entry<String, Object> entry : node.getAttributes().entrySet()) {
|
64 |
|
attrs.put(entry.getKey(), entry.getValue().toString());
|
65 |
|
attributeTypes.add(new AttributeType(entry.getKey(), AttributeDataType.STRING, ""));
|
|
91 |
|
|
92 |
if(!node.getAttributes().entrySet().isEmpty()) {
|
|
93 |
for (Map.Entry<String, Object> entry : node.getAttributes().entrySet()) {
|
|
94 |
attrs.put(entry.getKey(), entry.getValue().toString());
|
|
95 |
attributeNames.add(entry.getKey());
|
|
96 |
}
|
66 |
97 |
}
|
67 |
98 |
|
68 |
99 |
VertexDTO vertex = new VertexDTO(node.getId(), id++, attrs);
|
... | ... | |
72 |
103 |
}
|
73 |
104 |
}
|
74 |
105 |
|
|
106 |
/**
|
|
107 |
* Method transforms vertices from GraphNode object to vertex DTO and stores attribute type.
|
|
108 |
* It has to be called after processing vertices.
|
|
109 |
*/
|
75 |
110 |
private void processEdges() {
|
76 |
111 |
int id = 0;
|
77 |
112 |
|
78 |
113 |
for(GraphEdge edge : this.parser.getEdges().values()) {
|
79 |
114 |
HashMap<String, String> attrs = new HashMap<>();
|
80 |
|
for(Map.Entry<String, Object> entry : edge.getAttributes().entrySet()) {
|
81 |
|
attrs.put(entry.getKey(), entry.getValue().toString());
|
82 |
|
attributeTypes.add(new AttributeType(entry.getKey(), AttributeDataType.STRING, ""));
|
|
115 |
|
|
116 |
if(!edge.getAttributes().entrySet().isEmpty()) {
|
|
117 |
for (Map.Entry<String, Object> entry : edge.getAttributes().entrySet()) {
|
|
118 |
attrs.put(entry.getKey(), entry.getValue().toString());
|
|
119 |
attributeNames.add(entry.getKey());
|
|
120 |
}
|
83 |
121 |
}
|
84 |
122 |
|
85 |
123 |
int from = remappedVertices.get(edge.getNode1());
|
Loader fix