Advertisement
Guest User

Graph Edge

a guest
Nov 12th, 2017
1,157
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package dijkstra;
  2.  
  3. public class Edge implements Comparable{
  4.     private int startPoint;
  5.     private int endPoint;
  6.     private float weight;
  7.  
  8.     public Edge(int startPoint, int endPoint, float weight) {
  9.         this.startPoint = startPoint;
  10.         this.endPoint = endPoint;
  11.         this.weight = weight;
  12.     }
  13.  
  14.     public int getStartPoint() {
  15.         return startPoint;
  16.     }
  17.  
  18.     public int getEndPoint() {
  19.         return endPoint;
  20.     }
  21.  
  22.     public float getWeight() {
  23.         return weight;
  24.     }
  25.  
  26.     public boolean equals(Edge other) {
  27.         if (this.startPoint == other.startPoint) {
  28.             if (this.endPoint == other.endPoint) {
  29.                 return true;
  30.             }
  31.         }
  32.         return false;
  33.     }
  34.    
  35.     public int compareTo(Object o) {
  36.         Edge other = (Edge) o;
  37.         return Double.compare(this.weight, other.weight);
  38.     }
  39.  
  40.     public String toString() {
  41.         return startPoint + "-" + endPoint + " (" + weight + ")";
  42.     }
  43.  
  44. }
Advertisement
RAW Paste Data Copied
Advertisement