aboutsummaryrefslogtreecommitdiff
path: root/com/example/portfolio3/AbstractGraph.java
blob: c2cf433eb523ca93d3758e01c814f2fdf7fb78ed (plain)
  1. package com.example.portfolio3;
  2. // origin: <https://moodle.ruc.dk/course/section.php?id=211877>
  3. import java.util.*;
  4. /// foo
  5. abstract class AbstractGraph implements Graph{
  6. /// foo
  7. AbstractGraph() {}
  8. /// foo
  9. private HashMap<String,Vertex> vertexMap=new HashMap<>();
  10. /// foo
  11. private HashSet<Vertex> vertexSet=new HashSet<>();
  12. /// foo
  13. /// @param s foo
  14. /// @return Vertex
  15. public Vertex vertex(String s){
  16. if(vertexMap.containsKey(s))return vertexMap.get(s);
  17. Vertex v=new Vertex(s);
  18. vertexMap.put(s,v);
  19. vertexSet.add(v);
  20. return v;
  21. }
  22. /// foo
  23. public void insertEdge(String v, String u, int w){
  24. insertEdge(vertex(v),vertex(u),w);
  25. }
  26. /// foo
  27. public Collection<Vertex> vertices() { return vertexSet; }
  28. /// foo
  29. /// @param v1 foo
  30. /// @param v2 foo
  31. /// @param w foo
  32. abstract public void insertEdge(Vertex v1, Vertex v2, int w);
  33. /// foo
  34. abstract public Collection<Edge> edges();
  35. /// foo
  36. abstract public Collection<Edge> outEdge(Vertex v);
  37. /// foo
  38. abstract public Integer getWeight(Vertex v1, Vertex v2);
  39. }