2
0

CellNodeMap.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.utils;
  16. import java.util.ArrayList;
  17. import java.util.Map;
  18. import com.l2jserver.gameserver.pathfinding.Node;
  19. import javolution.util.FastMap;
  20. /**
  21. *
  22. * @author Sami
  23. */
  24. public class CellNodeMap
  25. {
  26. private Map<Integer, ArrayList<Node>> _cellIndex;
  27. public CellNodeMap()
  28. {
  29. _cellIndex = new FastMap<Integer, ArrayList<Node>>();
  30. }
  31. public void add(Node n)
  32. {
  33. if (_cellIndex.containsKey(n.getLoc().getY()))
  34. {
  35. _cellIndex.get(n.getLoc().getY()).add(n);
  36. }
  37. else
  38. {
  39. ArrayList<Node> array = new ArrayList<Node>(5);
  40. array.add(n);
  41. _cellIndex.put(n.getLoc().getY(), array);
  42. }
  43. }
  44. public boolean contains(Node n)
  45. {
  46. ArrayList<Node> array = _cellIndex.get(n.getLoc().getY());
  47. if (array == null)
  48. {
  49. return false;
  50. }
  51. for (Node node : array)
  52. if(node.equals(n))
  53. return true;
  54. return false;
  55. }
  56. }