L2ArrayList.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2004-2013 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.ArrayList;
  21. import java.util.Collection;
  22. import com.l2jserver.gameserver.model.interfaces.IL2Procedure;
  23. /**
  24. * A custom version of ArrayList: Extension for iterating without using temporary collection<br>
  25. * Note that this implementation is not synchronized. If multiple threads access a array list concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates
  26. * the list. If no such object exists, the list should be "wrapped" using the {@link L2FastList}. This is best done at creation time, to prevent accidental unsynchronized access.
  27. * @author UnAfraid
  28. * @param <T>
  29. */
  30. public class L2ArrayList<T> extends ArrayList<T>
  31. {
  32. private static final long serialVersionUID = 8354641653178203420L;
  33. public L2ArrayList()
  34. {
  35. super();
  36. }
  37. public L2ArrayList(Collection<? extends T> c)
  38. {
  39. super(c);
  40. }
  41. public L2ArrayList(int initialCapacity)
  42. {
  43. super(initialCapacity);
  44. }
  45. /**
  46. * Public method that iterate entire collection.<br>
  47. * <br>
  48. * @param proc - a class method that must be executed on every element of collection.<br>
  49. * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
  50. * check method (IL2Procedure.execute(T))<br>
  51. */
  52. public boolean executeForEach(IL2Procedure<T> proc)
  53. {
  54. for (T e : this)
  55. {
  56. if (!proc.execute(e))
  57. {
  58. return false;
  59. }
  60. }
  61. return true;
  62. }
  63. }