0
當我在解決兩點之間的Dijkstra算法時,我必須在運行它時再次創建圖形對象。我想創建一個Spring MVC應用程序,其中該圖形在啓動時僅作爲一個bean加載一次。Spring MVC:Dijkstra算法如何在啓動時創建一個圖形bean
目前這些都是我的課是這樣的:
public class Graph {
private final List<Vertex> vertexes;
public Graph(List<Vertex> vertexes) {
this.vertexes = vertexes;
public List<Vertex> getVertexes() {
return vertexes;
}
}
頂點類:
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);
}
}
邊緣階層:
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;
}
}
在我的主方法,我填充頂點列表包含274個頂點元素。 Graph類然後在其構造函數中使用此列表。我如何創建這個單一的圖形對象作爲一個bean?這是我得到的。
<bean id="graph" class="com.fdm.model.Graph" >
<constructor-arg ref="list"/>
</bean>
<util:list id="list" list-class="java.util.ArrayList" />
但我不確定如何進一步處理。上面的列表不是類型頂點?
定義'Graph'靜態這份名單的範圍是單 ? –