Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8ade384b

Přidáno uživatelem Vít Mazín před téměř 6 roky(ů)

Loader fix

Zobrazit rozdíly:

sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/BaseDOTLoader.java
7 7
import java.util.List;
8 8
import java.util.Set;
9 9

  
10
/**
11
 * Abstract class for DOT loader which takes DOT input and transforms it
12
 * to DTO classes.
13
 */
10 14
public abstract class BaseDOTLoader<V extends VertexDTO, E extends EdgeDTO> {
11 15

  
16
    /**
17
     * Source DOT file
18
     */
12 19
    protected final String dotInput;
13 20

  
21
    /**
22
     *
23
     * @param dotInput - Source DOT file
24
     */
14 25
    public BaseDOTLoader(String dotInput) {
15 26
        this.dotInput = dotInput;
16 27
    }
17 28

  
29
    /**
30
     * Returns list of vertices DTO
31
     * @return List of vertices DTO
32
     */
18 33
    public abstract List<V> getVertices();
19 34

  
35
    /**
36
     * Returns list of edges DTO
37
     * @return List of edges DTO
38
     */
20 39
    public abstract List<E> getEdges();
21 40

  
41
    /**
42
     * Returns list of attribute types
43
     * @return List of attribute types
44
     */
22 45
    public abstract Set<AttributeType> getAttributeTypes();
23 46
}
sources/imiger-dot-converter/src/main/java/cz/zcu/kiv/imiger/plugin/dot/loader/PaypalDOTLoader.java
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());

Také k dispozici: Unified diff