Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hw4;
- import java.util.Objects;
- public class Edge {
- private Node startPoint;
- private Node endPoint;
- private String label;
- public Edge(Node start, Node end, String label) {
- this.startPoint = start;
- this.endPoint = new Node(end.getName(),label);
- this.label = label;
- //checkRep();
- }
- public Node getStartPoint(){
- return new Node(startPoint);
- }
- public Node getEndPoint() {
- return new Node(endPoint);
- }
- public String getLabel() {
- return label;
- }
- public Edge getEdge() {
- Node tempStart = new Node(this.startPoint.getName());
- Node tempEnd = new Node(this.endPoint.getName());
- String tempLabel = this.label;
- return new Edge(tempStart,tempEnd,tempLabel);
- }
- @Override
- public int hashCode() {
- return Objects.hash(startPoint,endPoint,label);
- }
- @Override
- public boolean equals(Object obj) {
- if((obj == null) || (getClass() != obj.getClass())){
- return false;
- }
- Edge tempEdge = (Edge) obj;
- return this.startPoint.equals(tempEdge.startPoint)
- && this.endPoint.equals(tempEdge.endPoint)
- && this.label.equals(tempEdge.label);
- }
- public void checkRep() {
- if(startPoint == null) throw new RuntimeException("Error: Start point of edge is null");
- if(endPoint == null) throw new RuntimeException("Error: End point of edge is null");
- if(label == null) throw new RuntimeException("Error: Labelof edge is null");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement