Refactoring

* package refactoring
* new matrix implementation (todo)
* new adj list implemetation (todo)
* fixed tests
This commit is contained in:
2019-06-15 15:15:13 +02:00
parent a8596331e7
commit 0de35fd4a1
35 changed files with 772 additions and 118 deletions

View File

@@ -0,0 +1,41 @@
package berack96.lib.graph.models;
import berack96.lib.graph.Edge;
import berack96.lib.graph.Graph;
/**
* Support class used for saving a Graph in a file.
*
* @author Berack96
*
*/
public class GraphSaveStructure {
public GraphSaveStructure() {}
public GraphSaveStructure(Graph<?, ?> graph, String other) {
this.vertices = new String[graph.numberOfVertices()];
int i = 0;
for(Object o: graph.vertices()) {
this.vertices[i] = Graph.GSON.toJson(o);
i++;
}
this.edges = new EdgeSaveStructure[graph.numberOfEdges()];
i = 0;
for (Edge<?, ?> edge : graph.edges()) {
this.edges[i] = new EdgeSaveStructure(
Graph.GSON.toJson(edge.getSource()),
Graph.GSON.toJson(edge.getDestination()),
Graph.GSON.toJson(edge.getWeight())
);
i++;
}
this.other = other;
}
public String[] vertices;
public EdgeSaveStructure[] edges;
//public MarkSaveStructure[] marks;
public String other;
}