Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a8d86f83

Přidáno uživatelem Tomáš Šimandl před více než 6 roky(ů)

Removed vertex originalId

Zobrazit rozdíly:

sources/src/main/java/cz/zcu/kiv/offscreen/api/BaseVertex.java
8 8

  
9 9
    /** New generated identification number. */
10 10
    private int id;
11
    /** Identification number which is in input file. */
12
    private int originalId;
13 11
    /** Name of vertex. */
14 12
    private String name;
15 13
    /** Index of vertex archetype. */
......
17 15
    /** Additional info. */
18 16
    private String text;
19 17

  
20
    public BaseVertex(int id, int originalId, String name, int archetypeIndex, String text) {
18
    public BaseVertex(int id, String name, int archetypeIndex, String text) {
21 19
        this.id = id;
22
        this.originalId = originalId;
23 20
        this.name = name;
24 21
        this.archetypeIndex = archetypeIndex;
25 22
        this.text = text;
......
33 30
        this.id = id;
34 31
    }
35 32

  
36
    public int getOriginalId() {
37
        return originalId;
38
    }
39

  
40
    public void setOriginalId(int originalId) {
41
        this.originalId = originalId;
42
    }
43

  
44 33
    public String getName() {
45 34
        return name;
46 35
    }
......
71 60
     */
72 61
    @Override
73 62
    public int hashCode() {
74
        return originalId;
63
        return id;
75 64
    }
76 65

  
77 66
    /**
78 67
     * Two vertices are equals when their {@code originalId} is equals.
79
     * @param edge which will be compared with this instance
68
     * @param vertex which will be compared with this instance
80 69
     * @return true if vertices are equal, false otherwise
81 70
     */
82 71
    @Override
83
    public boolean equals(Object edge) {
84
        if (!(edge instanceof BaseVertex)) return false;
85
        return originalId == ((BaseVertex) edge).originalId;
72
    public boolean equals(Object vertex) {
73
        if (!(vertex instanceof BaseVertex)) return false;
74
        return id == ((BaseVertex) vertex).id;
86 75
    }
87 76
}
sources/src/main/java/cz/zcu/kiv/offscreen/api/GraphExport.java
5 5
import java.util.ArrayList;
6 6
import java.util.List;
7 7
import java.util.Map;
8
import java.util.Set;
8 9

  
9 10
import org.apache.log4j.Logger;
10 11

  
......
14 15
 */
15 16
public class GraphExport {
16 17

  
17
    private List<Vertex> vertices;
18
    private Set<Vertex> vertices;
18 19
    private List<Edge> edges;
19 20
    private List<VertexArchetype> vertexArchetypes;
20 21
    private List<EdgeArchetype> edgeArchetypes;
......
30 31

  
31 32
    public GraphExport(Graph graph) {
32 33
        logger.trace("ENTRY");
33
        this.vertices = new ArrayList<>(graph.getVertices().values());
34
        this.edges = new ArrayList<>(graph.getEdges());
35
        this.vertexArchetypes = new ArrayList<>(graph.getVertexArchetypes());
36
        this.edgeArchetypes = new ArrayList<>(graph.getEdgeArchetypes());
37
        this.attributeTypes = new ArrayList<>(graph.getAttributeTypes());
34
        this.vertices = graph.getVertices();
35
        this.edges = graph.getEdges();
36
        this.vertexArchetypes = graph.getVertexArchetypes();
37
        this.edgeArchetypes = graph.getEdgeArchetypes();
38
        this.attributeTypes = graph.getAttributeTypes();
38 39
        this.possibleEnumValues = graph.getPossibleEnumValues();
39 40
        this.groups = graph.getGraphState().getGroups();
40 41
        this.sideBar = graph.getGraphState().getSideBar();
......
49 50
        return edges;
50 51
    }
51 52

  
52
    public List<Vertex> getVertices() {
53
    public Set<Vertex> getVertices() {
53 54
        logger.trace("ENTRY");
54 55
        logger.trace("EXIT");
55 56
        return vertices;
sources/src/main/java/cz/zcu/kiv/offscreen/api/Group.java
8 8
 */
9 9
public class Group {
10 10

  
11
    /** Generated id of group which is unique only in groups. */
12
    private int groupId;
13
    /** Generated if of group which is unique in groups and vertexes. */
11
    /** Generated id of group. */
14 12
    private int id;
15 13
    /** Name of group */
16 14
    private String name;
......
23 21
    /** Relative position in graph */
24 22
    private Position position;
25 23

  
26
    public Group(int groupId, int id, String name){
27
        this.groupId = groupId;
24
    public Group(int id, String name){
28 25
        this.id = id;
29 26
        this.name = name;
30 27
        this.verticesId = new ArrayList<>();
......
33 30
        this.position = null;
34 31
    }
35 32

  
36
    public Group(int groupId, int id, String name, List<Integer> verticesId, List<Integer> verticesEdgeFromId, List<Integer> verticesEdgeToId) {
37
        this.groupId = groupId;
33
    public Group(int id, String name, List<Integer> verticesId, List<Integer> verticesEdgeFromId, List<Integer> verticesEdgeToId) {
38 34
        this.id = id;
39 35
        this.name = name;
40 36
        this.verticesId = verticesId;
......
43 39
        this.position = null;
44 40
    }
45 41

  
46
    public int getGroupId() {
47
        return groupId;
48
    }
49

  
50
    public void setGroupId(int groupId) {
51
        this.groupId = groupId;
52
    }
53

  
54 42
    public int getId() {
55 43
        return id;
56 44
    }
sources/src/main/java/cz/zcu/kiv/offscreen/api/Vertex.java
1 1
package cz.zcu.kiv.offscreen.api;
2 2

  
3
import cz.zcu.kiv.offscreen.graph.VertexImpl;
4

  
3 5
import java.util.List;
4 6

  
5 7
/**
......
14 16

  
15 17
    /**
16 18
     * Create new vertex.
17
     * @param id new generated identification number.
18
     * @param originalId original identification number from input file
19
     * @param id original identification number from input file
19 20
     * @param name of vertex
20 21
     * @param archetypeIndex index of vertex archetype
21 22
     * @param text additional info
22 23
     * @param attributes List of all attributes. Every attribute is stored in String array in pair as {attribute name, attribute value}.
23 24
     */
24
    public Vertex(int id, int originalId, String name, int archetypeIndex, String text, List<String[]> attributes) {
25
        super(id, originalId, name, archetypeIndex, text);
25
    public Vertex(int id, String name, int archetypeIndex, String text, List<String[]> attributes) {
26
        super(id, name, archetypeIndex, text);
26 27
        this.attributes = attributes;
27 28
        this.position = null;
28 29
    }
29 30

  
31
    /**
32
     * Create new vertex.
33
     * @param vertex instance of VertexImpl with set all parameters
34
     * @param attributes ist of all attributes. Every attribute is stored in String array in pair as {attribute name, attribute value}.
35
     */
36
    public Vertex(VertexImpl vertex, List<String[]> attributes){
37
        this(vertex.getId(), vertex.getName(), vertex.getArchetype(), vertex.getText(), attributes);
38
    }
39

  
30 40
    public List<String[]> getAttributes() {
31 41
        return attributes;
32 42
    }
sources/src/main/java/cz/zcu/kiv/offscreen/graph/Graph.java
4 4
import cz.zcu.kiv.offscreen.api.Vertex;
5 5
import org.apache.log4j.Logger;
6 6

  
7
import java.util.HashMap;
8
import java.util.LinkedList;
9
import java.util.List;
10
import java.util.Map;
7
import java.util.*;
11 8

  
12 9
/**
13 10
 * Class represents graph which is loaded from input JSON file.
14 11
 */
15 12
public class Graph {
16 13

  
17
    private Map<Integer, Vertex> vertices;
14
    private Set<Vertex> vertices;
18 15
    private List<Edge> edges;
19 16
    private List<VertexArchetype> vertexArchetypes;
20 17
    private List<EdgeArchetype> edgeArchetypes;
......
28 25

  
29 26
    public Graph() {
30 27
        logger.trace("ENTRY");
31
        this.vertices = new HashMap<Integer, Vertex>();
32
        this.edges = new LinkedList<Edge>();
28
        this.vertices = new HashSet<>();
29
        this.edges = new LinkedList<>();
33 30
        logger.trace("EXIT");
34 31
    }
35 32

  
......
82 79
        return possibleEnumValues;
83 80
    }
84 81

  
85
    public Map<Integer, Vertex> getVertices() {
82
    public Set<Vertex> getVertices() {
86 83
        logger.trace("ENTRY");
87 84
        logger.trace("EXIT");
88 85
        return vertices;
......
94 91
        logger.trace("EXIT");
95 92
    }
96 93

  
97
    public void addVertex(int id, Vertex vertex) {
94
    public void addVertex(Vertex vertex) {
98 95
        logger.trace("ENTRY");
99
        this.vertices.put(id, vertex);
96
        this.vertices.add(vertex);
100 97
        logger.trace("EXIT");
101 98
    }
102 99

  
sources/src/main/java/cz/zcu/kiv/offscreen/graph/GraphManager.java
38 38
        }
39 39
    }
40 40

  
41
    private int lastVertexOrGroupId = 1;
42

  
43 41
    public List<VertexArchetype> vertexArchetypes = new ArrayList<>();
44 42
    public List<EdgeArchetype> edgeArchetypes = new ArrayList<>();
45 43
    public List<AttributeType> attributeTypes = new ArrayList<>();
......
151 149
     * @param attributes     - Map of attributes associated with the vertex
152 150
     */
153 151
    public void addVertex(int id, String name, String text, int archetypeIndex, Map<Integer, Attribute> attributes) {
154
        VertexImpl vertexToAdd = new VertexImpl(id, id, name, archetypeIndex, text);
152
        VertexImpl vertexToAdd = new VertexImpl(id, name, archetypeIndex, text);
155 153
        if (vertices.containsKey(archetypeIndex)) {
156 154
            vertices.get(archetypeIndex).add(vertexToAdd);
157 155
        } else {
......
447 445
        while (i.hasNext()) {
448 446
            EdgeImpl edge = i.next();
449 447

  
450
            VertexImpl toDummy = new VertexImpl(edge.getTo(), edge.getTo(), null, -1,null);
451
            VertexImpl fromDummy = new VertexImpl(edge.getFrom(), edge.getFrom(), null, -1, null);
448
            VertexImpl toDummy = new VertexImpl(edge.getTo(), null, -1,null);
449
            VertexImpl fromDummy = new VertexImpl(edge.getFrom(), null, -1, null);
452 450

  
453 451
            if (!resultVertices.contains(toDummy) || !resultVertices.contains(fromDummy)){
454 452
                i.remove();
......
519 517
        for (VertexImpl vertexImpl : resultVertices) {
520 518

  
521 519
            List<String[]> attributes = getAttributesAsArray(vertexImpl.getSortedAttributes());
522

  
523
            Vertex vertex = new Vertex(
524
                    lastVertexOrGroupId++,
525
                    vertexImpl.getOriginalId(),
526
                    vertexImpl.getName(),
527
                    vertexImpl.getArchetype(),
528
                    vertexImpl.getText(),
529
                    attributes);
530

  
531
            graph.addVertex(vertexImpl.getId(), vertex);
520
            Vertex vertex = new Vertex(vertexImpl,attributes);
521
            graph.addVertex(vertex);
532 522
        }
533 523
    }
534 524

  
......
610 600
        int index = 0;
611 601
        for(VertexArchetype archetype : graph.getVertexArchetypes()){
612 602
            if(graph.getDefaultGroupArchetypes().contains(archetype.name)){
613
                groups.put(index, new Group(groupId++, lastVertexOrGroupId++, archetype.name));
603
                groups.put(index, new Group(groupId++, archetype.name));
614 604
            }
615 605
            index++;
616 606
        }
617 607

  
618 608
        // find vertices with founded vertex archetypes indices
619
        for (Vertex vertex : graph.getVertices().values()){
609
        for (Vertex vertex : graph.getVertices()){
620 610
            if(groups.keySet().contains(vertex.getArchetype())){
621
                groups.get(vertex.getArchetype()).addVertexId(vertex.getOriginalId());
611
                groups.get(vertex.getArchetype()).addVertexId(vertex.getId());
622 612
            }
623 613
        }
624 614

  
sources/src/main/java/cz/zcu/kiv/offscreen/graph/VertexImpl.java
13 13

  
14 14
    /**
15 15
     * Creates new vertex.
16
     * @param id new generated identification number.
17
     * @param originalId original identification number from input file
16
     * @param id original identification number from input file
18 17
     * @param name of vertex
19 18
     * @param archetypeIndex index of vertex archetype
20 19
     * @param text additional info
21 20
     */
22
    public VertexImpl(int id, int originalId, String name, int archetypeIndex, String text) {
23
        super(id, originalId, name, archetypeIndex, text);
21
    public VertexImpl(int id, String name, int archetypeIndex, String text) {
22
        super(id, name, archetypeIndex, text);
24 23
        this.attributesMap = new HashMap<>();
25 24
    }
26 25

  

Také k dispozici: Unified diff