42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class Graph {
|
|
List<Edge> graph;
|
|
|
|
public Graph() {
|
|
graph = new ArrayList<Edge>();
|
|
}
|
|
|
|
public List<Edge> getGraph() {
|
|
System.out.println(graph.toString());
|
|
return graph;
|
|
}
|
|
|
|
public void insertEdge(Edge edge) {
|
|
graph.add(edge);
|
|
}
|
|
|
|
public int findRoute(String src, String dst) {
|
|
for(int i = 0; i < graph.size(); i++) {
|
|
String source = graph.get(i).source.getName();
|
|
String destination = graph.get(i).destination.getName();
|
|
if(source.equals(src) && destination.equals(dst)) {
|
|
return graph.get(i).weight;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public void changeRoute(String src, String dst, int value) {
|
|
for(int i = 0; i < graph.size(); i++) {
|
|
String source = graph.get(i).source.getName();
|
|
String destination = graph.get(i).destination.getName();
|
|
if (source.equals(src) && destination.equals(dst)) {
|
|
graph.get(i).weight = value;
|
|
}
|
|
}
|
|
}
|
|
}
|