From a42de79292d9541db7865b54e93be2d0b6e6a094 Mon Sep 17 00:00:00 2001 From: "serena.spinoso" Date: Thu, 7 Sep 2017 10:22:39 +0200 Subject: update verigraph JIRA: PARSER-154 code optimizations about graph manipulation and formula generation. Change-Id: Idebef19b128281aa2bc40d1aeab6e208c7ddd93d Signed-off-by: serena.spinoso --- verigraph/src/it/polito/verigraph/model/Graph.java | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 verigraph/src/it/polito/verigraph/model/Graph.java (limited to 'verigraph/src/it/polito/verigraph/model/Graph.java') diff --git a/verigraph/src/it/polito/verigraph/model/Graph.java b/verigraph/src/it/polito/verigraph/model/Graph.java new file mode 100644 index 0000000..22b4907 --- /dev/null +++ b/verigraph/src/it/polito/verigraph/model/Graph.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2017 Politecnico di Torino and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Apache License, Version 2.0 + * which accompanies this distribution, and is available at + * http://www.apache.org/licenses/LICENSE-2.0 + *******************************************************************************/ +package it.polito.verigraph.model; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import it.polito.verigraph.deserializer.GraphCustomDeserializer; +import it.polito.verigraph.serializer.CustomMapSerializer; + +@ApiModel(value = "Graph") +@XmlRootElement +@JsonDeserialize(using = GraphCustomDeserializer.class) +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class Graph { + + @ApiModelProperty(required = false, hidden = true) + @XmlTransient + private long id; + + @ApiModelProperty(name = "nodes", notes = "Nodes", dataType = "List[it.polito.verigraph.model.Node]") + private Mapnodes= new HashMap(); + + @ApiModelProperty(required = false, hidden = true) + @XmlTransient + private Setlinks= new HashSet(); + + public Graph() { + + } + + public Graph(long id) { + this.id = id; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @JsonSerialize(using = CustomMapSerializer.class) + public Map getNodes() { + return nodes; + } + + public void setNodes(Map nodes) { + this.nodes = nodes; + } + + @XmlTransient + public Set getLinks() { + return links; + } + + public void setLinks(Set links) { + this.links = links; + } + + public void addLink(String url, String rel) { + Link link = new Link(); + link.setLink(url); + link.setRel(rel); + links.add(link); + } + + public Node searchNodeByName(String name) { + for (Node node : this.nodes.values()) { + if (node.getName().equals(name)) + return node; + } + return null; + } + + public int nodesWithName(String name) { + int occurrences = 0; + for (Node node : this.nodes.values()) { + if (node.getName().equals(name)) + occurrences++; + + } + return occurrences; + } + +} \ No newline at end of file -- cgit 1.2.3-korg