2
0

L2FastList.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2004-2014 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.util;
  20. import java.util.Collection;
  21. import javolution.util.FastList;
  22. import com.l2jserver.gameserver.model.interfaces.IProcedure;
  23. /**
  24. * A custom version of FastList with extension for iterating without using temporary collection<br>
  25. * It's provide synchronization lock when iterating if needed<br>
  26. * <br>
  27. * @author Julian
  28. * @version 1.0.1 (2008-02-07)<br>
  29. * 1.0.0 - Initial version.<br>
  30. * 1.0.1 - Made forEachP() final.<br>
  31. * @author UnAfraid
  32. * @version 1.0.2 (20012-08-19)<br>
  33. * 1.0.2 - Using IL2Procedure instead of IForEach.
  34. * @param <T>
  35. */
  36. public class L2FastList<T> extends FastList<T>
  37. {
  38. private static final long serialVersionUID = 8354641653178203420L;
  39. public L2FastList()
  40. {
  41. this(false);
  42. }
  43. public L2FastList(int initialCapacity)
  44. {
  45. this(initialCapacity, false);
  46. }
  47. public L2FastList(Collection<? extends T> c)
  48. {
  49. this(c, false);
  50. }
  51. public L2FastList(boolean shared)
  52. {
  53. super();
  54. if (shared)
  55. {
  56. shared();
  57. }
  58. }
  59. public L2FastList(int initialCapacity, boolean shared)
  60. {
  61. super(initialCapacity);
  62. if (shared)
  63. {
  64. shared();
  65. }
  66. }
  67. public L2FastList(Collection<? extends T> c, boolean shared)
  68. {
  69. super(c);
  70. if (shared)
  71. {
  72. shared();
  73. }
  74. }
  75. /**
  76. * Public method that iterate entire collection.<br>
  77. * <br>
  78. * @param proc - a class method that must be executed on every element of collection.<br>
  79. * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
  80. * check method (IL2Procedure.execute(T))<br>
  81. */
  82. public boolean executeForEach(IProcedure<T, Boolean> proc)
  83. {
  84. for (T e : this)
  85. {
  86. if (!proc.execute(e))
  87. {
  88. return false;
  89. }
  90. }
  91. return true;
  92. }
  93. }