L2FastList.java 2.4 KB

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