L2FastList.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.List;
  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 Object> extends FastList<T>
  33. {
  34. private static final long serialVersionUID = 8354641653178203420L;
  35. public L2FastList()
  36. {
  37. this(false);
  38. }
  39. public L2FastList(boolean shared)
  40. {
  41. if (shared)
  42. {
  43. shared();
  44. }
  45. }
  46. public L2FastList(List<? extends T> list)
  47. {
  48. this(list, false);
  49. }
  50. public L2FastList(List<? extends T> list, boolean shared)
  51. {
  52. super(list);
  53. if (shared)
  54. {
  55. shared();
  56. }
  57. }
  58. /**
  59. * Public method that iterate entire collection.<br>
  60. * <br>
  61. * @param proc - a class method that must be executed on every element of collection.<br>
  62. * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
  63. * check method (IL2Procedure.execute(T))<br>
  64. */
  65. public boolean forEach(IL2Procedure<T> proc)
  66. {
  67. for (T e : this)
  68. {
  69. if (!proc.execute(e))
  70. {
  71. return false;
  72. }
  73. }
  74. return true;
  75. }
  76. }