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 --- .../polito/escape/verify/service/GraphService.java | 129 --------------------- 1 file changed, 129 deletions(-) delete mode 100644 verigraph/src/main/java/it/polito/escape/verify/service/GraphService.java (limited to 'verigraph/src/main/java/it/polito/escape/verify/service/GraphService.java') diff --git a/verigraph/src/main/java/it/polito/escape/verify/service/GraphService.java b/verigraph/src/main/java/it/polito/escape/verify/service/GraphService.java deleted file mode 100644 index b34eb08..0000000 --- a/verigraph/src/main/java/it/polito/escape/verify/service/GraphService.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * 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.escape.verify.service; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import it.polito.escape.verify.database.DatabaseClass; -import it.polito.escape.verify.exception.DataNotFoundException; -import it.polito.escape.verify.exception.ForbiddenException; -import it.polito.escape.verify.model.Graph; -import it.polito.escape.verify.model.Neighbour; -import it.polito.escape.verify.model.Node; - -public class GraphService { - - private Map graphs = DatabaseClass.getInstance().getGraphs(); - - public GraphService() { - - } - - public List getAllGraphs() { - return new ArrayList(graphs.values()); - } - - public Graph getGraph(long id) { - if (id <= 0) { - throw new ForbiddenException("Illegal graph id: " + id); - } - Graph graph = graphs.get(id); - if (graph == null) { - throw new DataNotFoundException("Graph with id " + id + " not found"); - } - return graph; - } - - public Graph updateGraph(Graph graph) { - if (graph.getId() <= 0) { - throw new ForbiddenException("Illegal graph id: " + graph.getId()); - } - Graph localGraph = graphs.get(graph.getId()); - if (localGraph == null) { - throw new DataNotFoundException("Graph with id " + graph.getId() + " not found"); - } - - validateGraph(graph); - -// int numberOfNodes = 0; -// for (Node node : graph.getNodes().values()) { -// -// node.setId(++numberOfNodes); -// -// int numberOfNodeNeighbours = 0; -// for (Neighbour neighbour : node.getNeighbours().values()) { -// neighbour.setId(++numberOfNodeNeighbours); -// } -// } - - for (Map.Entry nodeEntry : graph.getNodes().entrySet()){ - nodeEntry.getValue().setId(nodeEntry.getKey()); - - for (Map.Entry neighbourEntry : nodeEntry.getValue().getNeighbours().entrySet()){ - neighbourEntry.getValue().setId(neighbourEntry.getKey()); - } - } - - synchronized(this){ - graphs.put(graph.getId(), graph); - DatabaseClass.persistDatabase(); - return graph; - } - } - - public Graph removeGraph(long id) { - if (id <= 0) { - throw new ForbiddenException("Illegal graph id: " + id); - } - synchronized(this){ - return graphs.remove(id); - } - } - - public Graph addGraph(Graph graph) { - validateGraph(graph); - - synchronized (this) { - graph.setId(DatabaseClass.getInstance().getNumberOfGraphs() + 1); - } -// int numberOfNodes = 0; -// for (Node node : graph.getNodes().values()) { -// -// node.setId(++numberOfNodes); -// -// int numberOfNodeNeighbours = 0; -// for (Neighbour neighbour : node.getNeighbours().values()) { -// neighbour.setId(++numberOfNodeNeighbours); -// } -// } - - for (Map.Entry nodeEntry : graph.getNodes().entrySet()){ - nodeEntry.getValue().setId(nodeEntry.getKey()); - - for (Map.Entry neighbourEntry : nodeEntry.getValue().getNeighbours().entrySet()){ - neighbourEntry.getValue().setId(neighbourEntry.getKey()); - } - } - - synchronized(this){ - graphs.put(graph.getId(), graph); - DatabaseClass.persistDatabase(); - return graph; - } - } - - public static void validateGraph(Graph graph) { - for (Node node : graph.getNodes().values()) { - NodeService.validateNode(graph, node); - } - } -} -- cgit 1.2.3-korg