Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 630e6753

Přidáno uživatelem Martin Matas před téměř 6 roky(ů)

Fixed problem with data, implemented method getRawJson

Zobrazit rozdíly:

sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/BaseGraphFactory.java
22 22

  
23 23

  
24 24
	protected BaseGraphFactory(BaseDOTLoader<V, E> dotLoader) {
25
		vertices = new ArrayList<>();
26
		edges = new ArrayList<>();
27
		attributeTypes = new ArrayList<>();
25 28
		loadData(dotLoader);
26 29
	}
27 30

  
sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/DOT.java
1 1
package cz.zcu.kiv.imiger.plugin.dot;
2 2

  
3
import com.google.gson.Gson;
4
import cz.zcu.kiv.imiger.plugin.dot.dto.EdgeDTO;
5
import cz.zcu.kiv.imiger.plugin.dot.dto.VertexDTO;
6
import cz.zcu.kiv.imiger.plugin.dot.loader.BaseDOTLoader;
7
import cz.zcu.kiv.imiger.plugin.dot.loader.PaypalDOTLoader;
3 8
import cz.zcu.kiv.imiger.spi.IModule;
9
import cz.zcu.kiv.imiger.vo.Graph;
4 10

  
5 11
public class DOT implements IModule {
6 12
    @Override
......
10 16

  
11 17
    @Override
12 18
    public String getRawJson(String stringToConvert) {
13
        return null;
19
        BaseDOTLoader<VertexDTO, EdgeDTO> loader = new PaypalDOTLoader(stringToConvert);
20
        GraphFactory graphFactory = new GraphFactory(loader);
21
        Graph graph = graphFactory.createGraph();
22

  
23
        Gson gson = new Gson();
24
        return gson.toJson(graph, Graph.class);
14 25
    }
15 26
}
sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/GraphFactory.java
21 21

  
22 22
	public GraphFactory(BaseDOTLoader<VertexDTO,EdgeDTO> dotLoader) {
23 23
		super(dotLoader);
24
		vertices = new ArrayList<>();
25
		edges = new ArrayList<>();
26
		attributeTypes = new ArrayList<>();
27 24
		prepareEdgeArchetypes();
28 25
		prepareVertexArchetypes();
29 26
	}
......
38 35
			vertices = new ArrayList<>(loadedVertices);
39 36
		}
40 37

  
41
		if (loadedVertices != null) {
38
		if (loadedEdges != null) {
42 39
			edges = new ArrayList<>(loadedEdges);
43 40
		}
44 41

  
45
		if (loadedVertices != null) {
42
		if (loadedAttributeTypes != null) {
46 43
			attributeTypes = new ArrayList<>(loadedAttributeTypes);
47 44
		}
48 45
	}
......
64 61
		for (VertexDTO v : vertices) {
65 62

  
66 63
			List<String[]> attributes = new ArrayList<>();
67
			attributes.add((String[]) v.getAttributes().values().toArray());
64
			attributes.add(convertListToArray(v.getAttributes().values()));
68 65
			Vertex vertex = new Vertex(v.getId(), v.getName(), DEFAULT_ARCHETYPE_INDEX, "", attributes);
69 66
			graph.getVertices().add(vertex);
70 67
		}
......
74 71
		for (EdgeDTO e : edges) {
75 72

  
76 73
			List<String[]> attributes = new ArrayList<>();
77
			attributes.add((String[]) e.getAttributes().values().toArray());
74
			attributes.add(convertListToArray(e.getAttributes().values()));
78 75
			SubedgeInfo subedgeInfo = new SubedgeInfo(e.getId(), DEFAULT_ARCHETYPE_INDEX, attributes);
79 76

  
80 77
			List<SubedgeInfo> subedgeInfos = new ArrayList<>();
......
85 82
		}
86 83
	}
87 84

  
85
	private String[] convertListToArray(Collection<String> list) {
86
		String[] array = new String[list.size()];
87
		int i = 0;
88

  
89
		for (String str: list) {
90
			array[i++] = str;
91
		}
92

  
93
		return array;
94
	}
95

  
88 96
	private void prepareEdgeArchetypes() {
89 97
		edgeArchetypes= new ArrayList<>();
90 98
		edgeArchetypes.add(new EdgeArchetype(EDGE_ARCHETYPE_NAME, ARCHETYPE_TEXT));

Také k dispozici: Unified diff