Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1.  
  2. public class Edge implements Comparable<Edge>{
  3.  
  4. private int first_vertex;
  5. private int second_vertex;
  6. private double weight;
  7.  
  8. /**
  9. * Constructor for this class
  10. *
  11. * @param first Serves as name of a vertex of this edge
  12. * @param second Serves as name of other vertex of this edge
  13. * @param weight Weight of this edge
  14. */
  15. public Edge(int first, int second, double weight) {
  16. this.first_vertex = first;
  17. this.second_vertex = second;
  18. this.weight = weight;
  19. }
  20.  
  21. /**
  22. * Method overridden for purposes of this class - used to compare weight of this instance to
  23. * weight of another instance of this class
  24. *
  25. * @param Edge to compare weight against
  26. * @return Integer indicating relationship between edge weights compared
  27. */
  28. @Override
  29. public int compareTo(Edge other) {
  30. if (this.getWeight() < other.getWeight()) {
  31. return -1;
  32. } else if (this.getWeight() > other.getWeight()){
  33. return +1;
  34. } else {
  35. return 0;
  36. }
  37. }
  38.  
  39. /**
  40. * Getter for name of first vertex of the edge
  41. *
  42. * @return Integer name of edge's first (arbitrary) vertex
  43. */
  44. public int getFirstVertex() {
  45. return this.first_vertex;
  46. }
  47.  
  48. /**
  49. * Getter for name of edge's other vertex
  50. *
  51. * @return Integer name of edge's other (arbitrary) vertex
  52. */
  53. public int getSecondVertex() {
  54. return this.second_vertex;
  55. }
  56.  
  57. /**
  58. * Getter for this edge's weight
  59. *
  60. * @return Weight of the edge
  61. */
  62. public double getWeight() {
  63. return this.weight;
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement