2
0

Node.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.pathfinding;
  16. /**
  17. *
  18. * @author -Nemesiss-
  19. */
  20. public class Node
  21. {
  22. private final AbstractNodeLoc _loc;
  23. private final int _neighborsIdx;
  24. private Node[] _neighbors;
  25. private Node _parent;
  26. private short _cost;
  27. public Node(AbstractNodeLoc Loc, int Neighbors_idx)
  28. {
  29. _loc = Loc;
  30. _neighborsIdx = Neighbors_idx;
  31. }
  32. public void setParent(Node p)
  33. {
  34. _parent = p;
  35. }
  36. public void setCost(int cost)
  37. {
  38. _cost = (short)cost;
  39. }
  40. public void attachNeighbors()
  41. {
  42. if(_loc == null) _neighbors = null;
  43. else _neighbors = PathFinding.getInstance().readNeighbors(this, _neighborsIdx);
  44. }
  45. public Node[] getNeighbors()
  46. {
  47. return _neighbors;
  48. }
  49. public Node getParent()
  50. {
  51. return _parent;
  52. }
  53. public AbstractNodeLoc getLoc()
  54. {
  55. return _loc;
  56. }
  57. public short getCost()
  58. {
  59. return _cost;
  60. }
  61. /**
  62. * @see java.lang.Object#hashCode()
  63. */
  64. @Override
  65. public int hashCode()
  66. {
  67. final int prime = 31;
  68. int result = 1;
  69. result = prime * result + ((_loc == null) ? 0 : _loc.hashCode());
  70. return result;
  71. }
  72. /**
  73. * @see java.lang.Object#equals(java.lang.Object)
  74. */
  75. @Override
  76. public boolean equals(Object obj)
  77. {
  78. if (this == obj)
  79. return true;
  80. if (obj == null)
  81. return false;
  82. if (!(obj instanceof Node))
  83. return false;
  84. final Node other = (Node) obj;
  85. if (_loc == null)
  86. {
  87. if (other._loc != null)
  88. return false;
  89. }
  90. else if (!_loc.equals(other._loc))
  91. return false;
  92. return true;
  93. }
  94. }