aboutsummaryrefslogtreecommitdiff
path: root/com/example/portfolio3/EdgeGraph.java
blob: ae9cbe953088e90ba50dfbf75b9535e9693a66d0 (plain)
  1. package com.example.portfolio3;
  2. // origin: <https://moodle.ruc.dk/course/section.php?id=211877>
  3. /// EdgeGraph - One big set of all edges in the graph
  4. class EdgeGraph extends AbstractGraph {
  5. /// foo
  6. EdgeGraph() {}
  7. /// foo
  8. Set<Edge> edges=new HashSet<>();
  9. /// foo
  10. public void insertEdge(Vertex v1,Vertex v2,int w){
  11. edges.add(new Edge(v1,v2,w));
  12. }
  13. /// foo
  14. public Collection<Edge> edges(){return edges;}
  15. /// foo
  16. public Collection<Edge> outEdge(Vertex v){
  17. ArrayList<Edge> outEdge=new ArrayList<>();
  18. for(Edge e:edges)if(e.from()==v)outEdge.add(e);
  19. return outEdge;
  20. }
  21. /// foo
  22. public Integer getWeight(Vertex v1,Vertex v2){
  23. // linear in number of edges in the graph
  24. for(Edge e:edges){
  25. if(e.from()==v1 && e.to()==v2)return e.weight();
  26. }
  27. return null;
  28. }
  29. }