L2ArrayList.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.ArrayList;
  17. import java.util.Collection;
  18. import com.l2jserver.gameserver.model.IL2Procedure;
  19. /**
  20. * A custom version of ArrayList: Extension for iterating without using temporary collection<br>
  21. * 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
  22. * 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.
  23. * @author UnAfraid
  24. * @param <T>
  25. */
  26. public class L2ArrayList<T> extends ArrayList<T>
  27. {
  28. private static final long serialVersionUID = 8354641653178203420L;
  29. public L2ArrayList()
  30. {
  31. super();
  32. }
  33. public L2ArrayList(Collection<? extends T> c)
  34. {
  35. super(c);
  36. }
  37. public L2ArrayList(int initialCapacity)
  38. {
  39. super(initialCapacity);
  40. }
  41. /**
  42. * Public method that iterate entire collection.<br>
  43. * <br>
  44. * @param proc - a class method that must be executed on every element of collection.<br>
  45. * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
  46. * check method (IL2Procedure.execute(T))<br>
  47. */
  48. public boolean executeForEach(IL2Procedure<T> proc)
  49. {
  50. for (T e : this)
  51. {
  52. if (!proc.execute(e))
  53. {
  54. return false;
  55. }
  56. }
  57. return true;
  58. }
  59. }