L2FastList.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * A custom version of LinkedList with extension for iterating without using temporary collection<br>
  20. * It`s provide synchronization lock when iterating if needed<br>
  21. * <br>
  22. * @author Julian Version 1.0.1 (2008-02-07)<br>
  23. * Changes:<br>
  24. * 1.0.0 - Initial version.<br>
  25. * 1.0.1 - Made forEachP() final.<br>
  26. * @param <T>
  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. * @author Julian
  34. * @param <T>
  35. */
  36. public interface I2ForEach<T>
  37. {
  38. public boolean ForEach(T obj);
  39. }
  40. public L2FastList()
  41. {
  42. super();
  43. }
  44. public L2FastList(List<? extends T> list)
  45. {
  46. super(list);
  47. }
  48. /**
  49. * Public method that iterate entire collection.<br>
  50. * <br>
  51. * @param func - a class method that must be executed on every element of collection.<br>
  52. * @return - returns true if entire collection is iterated, false if it`s been interrupted by<br>
  53. * check method (I2ForEach.forEach())<br>
  54. */
  55. public boolean forEach(I2ForEach<T> func)
  56. {
  57. for (T e : this)
  58. {
  59. if (!func.ForEach(e))
  60. {
  61. return false;
  62. }
  63. }
  64. return true;
  65. }
  66. }