L2FastList.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /**
  19. *
  20. * A custom version of LinkedList 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 Version 1.0.1 (2008-02-07)<br>
  24. * Changes:<br>
  25. * 1.0.0 - Initial version.<br>
  26. * 1.0.1 - Made forEachP() final.<br>
  27. */
  28. public class L2FastList<T extends Object> extends FastList<T>
  29. {
  30. static final long serialVersionUID = 1L;
  31. /**
  32. * Public inner interface used by ForEach iterations<br>
  33. *
  34. * @author Julian
  35. */
  36. public interface I2ForEach<T> {
  37. public boolean ForEach(T obj);
  38. }
  39. public L2FastList() {
  40. super();
  41. }
  42. public L2FastList(List<? extends T> list) {
  43. super(list);
  44. }
  45. /**
  46. * Public method that iterate entire collection.<br>
  47. * <br>
  48. * @param func - 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 (I2ForEach.forEach())<br>
  51. */
  52. public boolean forEach(I2ForEach<T> func) {
  53. for (T e: this)
  54. if (!func.ForEach(e)) return false;
  55. return true;
  56. }
  57. }