Dépôt du be graphe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Node.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package org.insa.graph;
  2. import java.util.ArrayList;
  3. public class Node implements Comparable<Node> {
  4. // ID of the node.
  5. private int id;
  6. // Point of this graph.
  7. private Point point;
  8. // Successors.
  9. private ArrayList<Arc> successors;
  10. /**
  11. * Create a new Node corresponding to the given Point with
  12. * an empty list of successors.
  13. *
  14. * @param point
  15. */
  16. public Node(int id, Point point) {
  17. this.id = id;
  18. this.point = point;
  19. this.successors = new ArrayList<Arc>();
  20. }
  21. /**
  22. * Add a successor to this node.
  23. *
  24. * @param arc Arc to the successor.
  25. */
  26. public void addSuccessor(Arc arc) {
  27. successors.add(arc);
  28. }
  29. /**
  30. * @return ID of this node.
  31. */
  32. public int getId() { return id; }
  33. /**
  34. * @return List of successors of this node.
  35. */
  36. public ArrayList<Arc> getSuccessors() { return successors; }
  37. /**
  38. * @return Point of this node.
  39. */
  40. public Point getPoint() { return point; }
  41. @Override
  42. public boolean equals(Object other) {
  43. if (other instanceof Node) {
  44. return getId() == ((Node) other).getId();
  45. }
  46. return false;
  47. }
  48. @Override
  49. public int compareTo(Node other) {
  50. return Integer.compare(getId(), other.getId());
  51. }
  52. }