At the moment whenever I am solving Dijkstra's algorithm between two points, I have to create the graph object again when I run it. I want to create a spring MVC application where that graph is loaded just once on startup as a bean.
At the moment these are what my classes look like:
public class Graph {
private final List<Vertex> vertexes;
public Graph(List<Vertex> vertexes) {
this.vertexes = vertexes;
public List<Vertex> getVertexes() {
return vertexes;
}
}
Vertex Class:
public class Vertex implements Comparable<Vertex> {
final private Integer id;
final private String name;
public List<Edge> adjacencies;
public double minDistance = Double.POSITIVE_INFINITY;
public Vertex previous;
public Vertex(Integer id, String name) {
this.id = id;
this.name = name;
adjacencies = new LinkedList<Edge>();
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
@Override
public String toString() {
return id+name;
}
public int compareTo(Vertex other) {
return Double.compare(minDistance, other.minDistance);
}
}
Edge Class:
public class Edge {
private final String id;
private final Vertex destination;
private final double weight;
public Edge(String id, Vertex destination, double weight) {
this.id = id;
this.destination = destination;
this.weight = weight;
}
public String getId() {
return id;
}
public Vertex getDestination() {
return destination;
}
public double getWeight() {
return weight;
}
}
In my main method, I populate the Vertexes list with 274 Vertex elements. The Graph class then takes this list in its constructor. How can I create this single graph object as a bean? This is a far as I got.
<bean id="graph" class="com.fdm.model.Graph" >
<constructor-arg ref="list"/>
</bean>
<util:list id="list" list-class="java.util.ArrayList" />
But I am unsure how to proceed further. The list above is not of type vertex?