AbstractNode.java 1.8 KB

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