L2FastList.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * @param <T>
  28. */
  29. public class L2FastList<T extends Object> extends FastList<T>
  30. {
  31. static final long serialVersionUID = 1L;
  32. /**
  33. * Public inner interface used by ForEach iterations<br>
  34. *
  35. * @author Julian
  36. * @param <T>
  37. */
  38. public interface I2ForEach<T> {
  39. public boolean ForEach(T obj);
  40. }
  41. public L2FastList() {
  42. super();
  43. }
  44. public L2FastList(List<? extends T> list) {
  45. super(list);
  46. }
  47. /**
  48. * Public method that iterate entire collection.<br>
  49. * <br>
  50. * @param func - a class method that must be executed on every element of collection.<br>
  51. * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
  52. * check method (I2ForEach.forEach())<br>
  53. */
  54. public boolean forEach(I2ForEach<T> func) {
  55. for (T e: this)
  56. if (!func.ForEach(e)) return false;
  57. return true;
  58. }
  59. }