Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Edge implements Comparable<Edge>{
- private int first_vertex;
- private int second_vertex;
- private double weight;
- /**
- * Constructor for this class
- *
- * @param first Serves as name of a vertex of this edge
- * @param second Serves as name of other vertex of this edge
- * @param weight Weight of this edge
- */
- public Edge(int first, int second, double weight) {
- this.first_vertex = first;
- this.second_vertex = second;
- this.weight = weight;
- }
- /**
- * Method overridden for purposes of this class - used to compare weight of this instance to
- * weight of another instance of this class
- *
- * @param Edge to compare weight against
- * @return Integer indicating relationship between edge weights compared
- */
- @Override
- public int compareTo(Edge other) {
- if (this.getWeight() < other.getWeight()) {
- return -1;
- } else if (this.getWeight() > other.getWeight()){
- return +1;
- } else {
- return 0;
- }
- }
- /**
- * Getter for name of first vertex of the edge
- *
- * @return Integer name of edge's first (arbitrary) vertex
- */
- public int getFirstVertex() {
- return this.first_vertex;
- }
- /**
- * Getter for name of edge's other vertex
- *
- * @return Integer name of edge's other (arbitrary) vertex
- */
- public int getSecondVertex() {
- return this.second_vertex;
- }
- /**
- * Getter for this edge's weight
- *
- * @return Weight of the edge
- */
- public double getWeight() {
- return this.weight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement