WorldObjectMap.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.util;
  16. import java.util.Iterator;
  17. import java.util.Map;
  18. import javolution.util.FastMap;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. /**
  21. * This class ...
  22. * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
  23. * @param <T>
  24. */
  25. public class WorldObjectMap<T extends L2Object> extends L2ObjectMap<T>
  26. {
  27. Map<Integer, T> _objectMap = new FastMap<Integer, T>().shared();
  28. @Override
  29. public int size()
  30. {
  31. return _objectMap.size();
  32. }
  33. @Override
  34. public boolean isEmpty()
  35. {
  36. return _objectMap.isEmpty();
  37. }
  38. @Override
  39. public void clear()
  40. {
  41. _objectMap.clear();
  42. }
  43. @Override
  44. public void put(T obj)
  45. {
  46. if (obj != null)
  47. {
  48. _objectMap.put(obj.getObjectId(), obj);
  49. }
  50. }
  51. @Override
  52. public void remove(T obj)
  53. {
  54. if (obj != null)
  55. {
  56. _objectMap.remove(obj.getObjectId());
  57. }
  58. }
  59. @Override
  60. public T get(int id)
  61. {
  62. return _objectMap.get(id);
  63. }
  64. @Override
  65. public boolean contains(T obj)
  66. {
  67. if (obj == null)
  68. {
  69. return false;
  70. }
  71. return _objectMap.get(obj.getObjectId()) != null;
  72. }
  73. @Override
  74. public Iterator<T> iterator()
  75. {
  76. return _objectMap.values().iterator();
  77. }
  78. }