TreeEdge.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package pathgame.algorithm;
  2. /** Class that stores data for a graph edge
  3. *
  4. */
  5. public class TreeEdge implements Comparable< TreeEdge > {
  6. private int src, dest, weight;
  7. private boolean checked = false;
  8. /** Creates a new TreeEdge with the given parameters
  9. *
  10. * @param src the index of the source vertex of the edge
  11. * @param dest the index of the destination vertex of the edge
  12. * @param weight the weight of the edge
  13. */
  14. public TreeEdge(int src, int dest, int weight) {
  15. this.src = src;
  16. this.dest = dest;
  17. this.weight = weight;
  18. }
  19. /** Returns the index of the source vertex of the edge
  20. *
  21. * @return the index of the source vertex of the edge
  22. */
  23. public int getSrc() {
  24. return src;
  25. }
  26. /** Returns the index of the destination vertex of the edge
  27. *
  28. * @return the index of the destination vertex of the edge
  29. */
  30. public int getDest() {
  31. return dest;
  32. }
  33. /** Returns the index of the other vertex, using the given vertex
  34. *
  35. * @param other the vertex index that shouldn't be returned
  36. * @return the other vertex index
  37. */
  38. public int getOtherVertex(int other) {
  39. if(other == src) {
  40. return dest;
  41. }
  42. else {
  43. return src;
  44. }
  45. }
  46. /** Returns the weight of the edge
  47. *
  48. * @return the weight of the edge
  49. */
  50. public Integer getWeight() {
  51. return weight;
  52. }
  53. /** Returns isChecked, which is true if the TreeEdge has been checked
  54. *
  55. * @return whether this TreeEdge has been checked
  56. */
  57. public boolean isChecked() {
  58. return checked;
  59. }
  60. /** Sets isChecked, which is true if the TreeEdge has been checked
  61. *
  62. * @param checked new status of whether this TreeEdge has been checked
  63. */
  64. public void setChecked(boolean checked) {
  65. this.checked = checked;
  66. }
  67. /** Used for sorting Collections of TreeEdges
  68. *
  69. * @param o the TreeEdge that this one is being compared to
  70. * @return the result of compareTo()
  71. */
  72. @Override
  73. public int compareTo(TreeEdge o) {
  74. return this.getWeight().compareTo(o.getWeight());
  75. }
  76. }