Advertisement
Guest User

edge

a guest
Aug 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package hw4;
  2.  
  3. import java.util.Objects;
  4.  
  5. public class Edge {
  6. private Node startPoint;
  7. private Node endPoint;
  8. private String label;
  9.  
  10.  
  11. public Edge(Node start, Node end, String label) {
  12. this.startPoint = start;
  13. this.endPoint = new Node(end.getName(),label);
  14. this.label = label;
  15. //checkRep();
  16. }
  17.  
  18. public Node getStartPoint(){
  19. return new Node(startPoint);
  20. }
  21.  
  22. public Node getEndPoint() {
  23. return new Node(endPoint);
  24. }
  25.  
  26. public String getLabel() {
  27. return label;
  28. }
  29.  
  30. public Edge getEdge() {
  31. Node tempStart = new Node(this.startPoint.getName());
  32. Node tempEnd = new Node(this.endPoint.getName());
  33. String tempLabel = this.label;
  34.  
  35. return new Edge(tempStart,tempEnd,tempLabel);
  36. }
  37.  
  38. @Override
  39. public int hashCode() {
  40. return Objects.hash(startPoint,endPoint,label);
  41. }
  42.  
  43. @Override
  44. public boolean equals(Object obj) {
  45. if((obj == null) || (getClass() != obj.getClass())){
  46. return false;
  47. }
  48. Edge tempEdge = (Edge) obj;
  49. return this.startPoint.equals(tempEdge.startPoint)
  50. && this.endPoint.equals(tempEdge.endPoint)
  51. && this.label.equals(tempEdge.label);
  52. }
  53.  
  54. public void checkRep() {
  55. if(startPoint == null) throw new RuntimeException("Error: Start point of edge is null");
  56. if(endPoint == null) throw new RuntimeException("Error: End point of edge is null");
  57. if(label == null) throw new RuntimeException("Error: Labelof edge is null");
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement