Stop installing librairies during tests
[parser.git] / verigraph / src / main / java / it / polito / escape / verify / model / Graph.java
1 /*******************************************************************************
2  * Copyright (c) 2017 Politecnico di Torino and others.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Apache License, Version 2.0
6  * which accompanies this distribution, and is available at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *******************************************************************************/
9
10 package it.polito.escape.verify.model;
11
12 import java.util.HashMap;
13 import java.util.HashSet;
14 import java.util.Map;
15 import java.util.Set;
16
17 import javax.xml.bind.annotation.XmlRootElement;
18 import javax.xml.bind.annotation.XmlTransient;
19
20 import com.fasterxml.jackson.annotation.JsonInclude;
21 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
23
24 import io.swagger.annotations.ApiModel;
25 import io.swagger.annotations.ApiModelProperty;
26 import it.polito.escape.verify.deserializer.GraphCustomDeserializer;
27 import it.polito.escape.verify.serializer.CustomMapSerializer;
28
29 @ApiModel(value = "Graph")
30 @XmlRootElement
31 @JsonDeserialize(using = GraphCustomDeserializer.class)
32 @JsonInclude(JsonInclude.Include.NON_EMPTY)
33 public class Graph {
34
35         @ApiModelProperty(required = false, hidden = true)
36         @XmlTransient
37         private long                    id;
38
39         @ApiModelProperty(name = "nodes", notes = "Nodes", dataType = "List[it.polito.escape.verify.model.Node]")
40         private Map<Long, Node> nodes   = new HashMap<Long, Node>();
41
42         @ApiModelProperty(required = false, hidden = true)
43         @XmlTransient
44         private Set<Link>               links   = new HashSet<Link>();
45
46         public Graph() {
47
48         }
49
50         public Graph(long id) {
51                 this.id = id;
52         }
53
54         public long getId() {
55                 return id;
56         }
57
58         public void setId(long id) {
59                 this.id = id;
60         }
61
62         @JsonSerialize(using = CustomMapSerializer.class)
63         public Map<Long, Node> getNodes() {
64                 return nodes;
65         }
66
67         public void setNodes(Map<Long, Node> nodes) {
68                 this.nodes = nodes;
69         }
70
71         @XmlTransient
72         public Set<Link> getLinks() {
73                 return links;
74         }
75
76         public void setLinks(Set<Link> links) {
77                 this.links = links;
78         }
79
80         public void addLink(String url, String rel) {
81                 Link link = new Link();
82                 link.setLink(url);
83                 link.setRel(rel);
84                 links.add(link);
85         }
86
87         public Node searchNodeByName(String name) {
88                 for (Node node : this.nodes.values()) {
89                         if (node.getName().equals(name))
90                                 return node;
91                 }
92                 return null;
93         }
94
95         public int nodesWithName(String name) {
96                 int occurrences = 0;
97                 for (Node node : this.nodes.values()) {
98                         if (node.getName().equals(name))
99                                 occurrences++;
100
101                 }
102                 return occurrences;
103         }
104
105 }